ruby-changes:44304
From: nobu <ko1@a...>
Date: Sat, 8 Oct 2016 10:54:29 +0900 (JST)
Subject: [ruby-changes:44304] nobu:r56377 (trunk): memory_status.c: Win32 API
nobu 2016-10-08 10:54:24 +0900 (Sat, 08 Oct 2016) New Revision: 56377 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56377 Log: memory_status.c: Win32 API * ext/-test-/memory_status/memory_status.c (read_status): use Win32 GetProcessMemoryInfo API. Modified files: trunk/ChangeLog trunk/ext/-test-/memory_status/extconf.rb trunk/ext/-test-/memory_status/memory_status.c Index: ext/-test-/memory_status/extconf.rb =================================================================== --- ext/-test-/memory_status/extconf.rb (revision 56376) +++ ext/-test-/memory_status/extconf.rb (revision 56377) @@ -1,6 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/extconf.rb#L1 case RUBY_PLATFORM when /darwin/ ok = true +when /mswin/, /mingw/ + func = "GetProcessMemoryInfo(0, 0, 0)" + hdr = "psapi.h" + ok = have_func(func, hdr) || have_library("psapi", func, hdr) end if ok Index: ext/-test-/memory_status/memory_status.c =================================================================== --- ext/-test-/memory_status/memory_status.c (revision 56376) +++ ext/-test-/memory_status/memory_status.c (revision 56377) @@ -4,6 +4,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L4 # include <mach/message.h> # include <mach/kern_return.h> # include <mach/task_info.h> +#elif defined _WIN32 +# include <psapi.h> #endif static VALUE cMemoryStatus; @@ -26,6 +28,15 @@ read_status(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L28 size = ULL2NUM(taskinfo.virtual_size); rss = ULL2NUM(taskinfo.resident_size); rb_struct_aset(self, INT2FIX(1), rss); +#elif defined _WIN32 + VALUE peak; + PROCESS_MEMORY_COUNTERS c; + c.cb = sizeof(c); + if (!GetProcessMemoryInfo(GetCurrentProcess(), &c, c.cb)) + return Qnil; + size = SIZET2NUM(c.PagefileUsage); + peak = SIZET2NUM(c.PeakWorkingSetSize); + rb_struct_aset(self, INT2FIX(1), peak); #endif rb_struct_aset(self, INT2FIX(0), size); return self; @@ -39,6 +50,8 @@ Init_memory_status(void) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L50 rb_struct_define_under(mMemory, "Status", "size", #if defined __APPLE__ "rss", +#elif defined _WIN32 + "peak", #endif (char *)NULL); rb_define_method(cMemoryStatus, "_update", read_status, 0); Index: ChangeLog =================================================================== --- ChangeLog (revision 56376) +++ ChangeLog (revision 56377) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Sat Oct 8 10:34:25 2016 Nobuyoshi Nakada <nobu@r...> +Sat Oct 8 10:54:22 2016 Nobuyoshi Nakada <nobu@r...> + + * ext/-test-/memory_status/memory_status.c (read_status): use + Win32 GetProcessMemoryInfo API. * ext/-test-/memory_status/memory_status.c: get memory sizes by mach task_info system call. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/