summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-08 01:54:24 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-08 01:54:24 (GMT)
commit1bbe67f5f6b3c291da604cd61fedc507072ad168 (patch)
tree865cdf649ce505c51caaa829002b44f2f6627b1f /ext/-test-
parentf0e1d723164d99bf733fbb607ef78a440bd40c9f (diff)
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/-test-')
-rw-r--r--ext/-test-/memory_status/extconf.rb4
-rw-r--r--ext/-test-/memory_status/memory_status.c13
2 files changed, 17 insertions, 0 deletions
diff --git a/ext/-test-/memory_status/extconf.rb b/ext/-test-/memory_status/extconf.rb
index 8bfbfe6..1c1096d 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 813a834..80e2648 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);