summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-08-05 14:16:09 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-08-05 17:14:38 +0900
commitae275f67cea586933d9983c066c2771f83c76943 (patch)
tree0d6fa5ee75b164d2bfea4172b020d69721f16832 /ext
parent228b3e43be5e01e204751be2035fee3576a7ab74 (diff)
Show WorkingSetSize as RSS on Windows
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4709
Diffstat (limited to 'ext')
-rw-r--r--ext/-test-/memory_status/memory_status.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/ext/-test-/memory_status/memory_status.c b/ext/-test-/memory_status/memory_status.c
index 5775fa56f3..afacbee785 100644
--- a/ext/-test-/memory_status/memory_status.c
+++ b/ext/-test-/memory_status/memory_status.c
@@ -10,11 +10,15 @@
static VALUE cMemoryStatus;
+#undef HAVE_RSS
+#undef HAVE_PEAK
+
static VALUE
read_status(VALUE self)
{
VALUE size = INT2FIX(0);
#if defined __APPLE__
+# define HAVE_RSS 1
VALUE rss;
kern_return_t error;
# if defined MACH_TASK_BASIC_INFO
@@ -40,14 +44,20 @@ read_status(VALUE self)
rss = ULL2NUM(taskinfo.resident_size);
rb_struct_aset(self, INT2FIX(1), rss);
#elif defined _WIN32
- VALUE peak;
+# define HAVE_RSS 1
+# define HAVE_PEAK 1
+ VALUE rss, peak;
PROCESS_MEMORY_COUNTERS c;
c.cb = sizeof(c);
if (!GetProcessMemoryInfo(GetCurrentProcess(), &c, c.cb))
return Qnil;
size = SIZET2NUM(c.PagefileUsage);
+ rss = SIZET2NUM(c.WorkingSetSize);
peak = SIZET2NUM(c.PeakWorkingSetSize);
- rb_struct_aset(self, INT2FIX(1), peak);
+ rb_struct_aset(self, INT2FIX(2), peak);
+#endif
+#ifdef HAVE_RSS
+ rb_struct_aset(self, INT2FIX(1), rss);
#endif
rb_struct_aset(self, INT2FIX(0), size);
return self;
@@ -59,9 +69,10 @@ Init_memory_status(void)
VALUE mMemory = rb_define_module("Memory");
cMemoryStatus =
rb_struct_define_under(mMemory, "Status", "size",
-#if defined __APPLE__
+#ifdef HAVE_RSS
"rss",
-#elif defined _WIN32
+#endif
+#ifdef HAVE_PEAK
"peak",
#endif
(char *)NULL);