ruby-changes:44303
From: nobu <ko1@a...>
Date: Sat, 8 Oct 2016 10:34:35 +0900 (JST)
Subject: [ruby-changes:44303] nobu:r56376 (trunk): memory_status.c: system call
nobu 2016-10-08 10:34:27 +0900 (Sat, 08 Oct 2016) New Revision: 56376 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56376 Log: memory_status.c: system call * ext/-test-/memory_status/memory_status.c: get memory sizes by mach task_info system call. Added directories: trunk/ext/-test-/memory_status/ Added files: trunk/ext/-test-/memory_status/extconf.rb trunk/ext/-test-/memory_status/memory_status.c Modified files: trunk/ChangeLog trunk/test/lib/memory_status.rb Index: test/lib/memory_status.rb =================================================================== --- test/lib/memory_status.rb (revision 56375) +++ test/lib/memory_status.rb (revision 56376) @@ -1,4 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/test/lib/memory_status.rb#L1 # frozen_string_literal: false +begin + require '-test-/memory_status.so' +rescue LoadError +end + module Memory keys = [] @@ -81,7 +86,7 @@ module Memory https://github.com/ruby/ruby/blob/trunk/test/lib/memory_status.rb#L86 if !keys.empty? Status = Struct.new(*keys) end -end +end unless defined?(Memory::Status) if defined?(Memory::Status) class Memory::Status @@ -89,7 +94,7 @@ if defined?(Memory::Status) https://github.com/ruby/ruby/blob/trunk/test/lib/memory_status.rb#L94 Memory.read_status do |key, val| self[key] = val end - end + end unless method_defined?(:_update) Header = members.map {|k| k.to_s.upcase.rjust(6)}.join('') Format = "%6d" Index: ChangeLog =================================================================== --- ChangeLog (revision 56375) +++ ChangeLog (revision 56376) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Oct 8 10:34:25 2016 Nobuyoshi Nakada <nobu@r...> + + * ext/-test-/memory_status/memory_status.c: get memory sizes by + mach task_info system call. + Sat Oct 8 09:06:55 2016 Aurelien Jacobs <aurel@g...> * lib/logger.rb (Logger::Period#next_rotate_time): fix monthly log Index: ext/-test-/memory_status/memory_status.c =================================================================== --- ext/-test-/memory_status/memory_status.c (revision 0) +++ ext/-test-/memory_status/memory_status.c (revision 56376) @@ -0,0 +1,45 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L1 +#include "ruby.h" +#ifdef __APPLE__ +# include <mach/mach.h> +# include <mach/message.h> +# include <mach/kern_return.h> +# include <mach/task_info.h> +#endif + +static VALUE cMemoryStatus; + +static VALUE +read_status(VALUE self) +{ + VALUE size = INT2FIX(0); +#if defined __APPLE__ + VALUE rss; + kern_return_t error; + mach_msg_type_number_t out_count; + mach_task_basic_info_data_t taskinfo; + + taskinfo.virtual_size = 0; + out_count = MACH_TASK_BASIC_INFO_COUNT; + error = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, + (task_info_t)&taskinfo, &out_count); + if (error != KERN_SUCCESS) return Qnil; + size = ULL2NUM(taskinfo.virtual_size); + rss = ULL2NUM(taskinfo.resident_size); + rb_struct_aset(self, INT2FIX(1), rss); +#endif + rb_struct_aset(self, INT2FIX(0), size); + return self; +} + +void +Init_memory_status(void) +{ + VALUE mMemory = rb_define_module("Memory"); + cMemoryStatus = + rb_struct_define_under(mMemory, "Status", "size", +#if defined __APPLE__ + "rss", +#endif + (char *)NULL); + rb_define_method(cMemoryStatus, "_update", read_status, 0); +} Property changes on: ext/-test-/memory_status/memory_status.c ___________________________________________________________________ Added: svn:eol-style + LF Index: ext/-test-/memory_status/extconf.rb =================================================================== --- ext/-test-/memory_status/extconf.rb (revision 0) +++ ext/-test-/memory_status/extconf.rb (revision 56376) @@ -0,0 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/extconf.rb#L1 +case RUBY_PLATFORM +when /darwin/ + ok = true +end + +if ok + create_makefile("-test-/memory_status") +end Property changes on: ext/-test-/memory_status/extconf.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/