diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-08 01:54:24 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-08 01:54:24 +0000 |
commit | 1bbe67f5f6b3c291da604cd61fedc507072ad168 (patch) | |
tree | 865cdf649ce505c51caaa829002b44f2f6627b1f /ext | |
parent | f0e1d723164d99bf733fbb607ef78a440bd40c9f (diff) | |
download | ruby-1bbe67f5f6b3c291da604cd61fedc507072ad168.tar.gz |
memory_status.c: Win32 API
* ext/-test-/memory_status/memory_status.c (read_status): use
Win32 GetProcessMemoryInfo API.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/-test-/memory_status/extconf.rb | 4 | ||||
-rw-r--r-- | ext/-test-/memory_status/memory_status.c | 13 |
2 files changed, 17 insertions, 0 deletions
diff --git a/ext/-test-/memory_status/extconf.rb b/ext/-test-/memory_status/extconf.rb index 8bfbfe6321..1c1096d8f4 100644 --- a/ext/-test-/memory_status/extconf.rb +++ b/ext/-test-/memory_status/extconf.rb @@ -1,6 +1,10 @@ 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 diff --git a/ext/-test-/memory_status/memory_status.c b/ext/-test-/memory_status/memory_status.c index 813a8349c4..80e2648992 100644 --- a/ext/-test-/memory_status/memory_status.c +++ b/ext/-test-/memory_status/memory_status.c @@ -4,6 +4,8 @@ # 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) 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) 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); |