summaryrefslogtreecommitdiff
path: root/ext/-test-/memory_status/memory_status.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/-test-/memory_status/memory_status.c')
-rw-r--r--ext/-test-/memory_status/memory_status.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/ext/-test-/memory_status/memory_status.c b/ext/-test-/memory_status/memory_status.c
index 5775fa56f3..f124c97ca1 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
@@ -30,7 +34,7 @@ read_status(VALUE self)
taskinfo.virtual_size = 0;
taskinfo.resident_size = 0;
error = task_info(mach_task_self(), flavor,
- (task_info_t)&taskinfo, &out_count);
+ (task_info_t)&taskinfo, &out_count);
if (error != KERN_SUCCESS) return Qnil;
#ifndef ULL2NUM
/* "long long" does not exist here, use size_t instead. */
@@ -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;
+ 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;
@@ -58,12 +68,13 @@ Init_memory_status(void)
{
VALUE mMemory = rb_define_module("Memory");
cMemoryStatus =
- rb_struct_define_under(mMemory, "Status", "size",
-#if defined __APPLE__
- "rss",
-#elif defined _WIN32
- "peak",
+ rb_struct_define_under(mMemory, "Status", "size",
+#ifdef HAVE_RSS
+ "rss",
+#endif
+#ifdef HAVE_PEAK
+ "peak",
#endif
- (char *)NULL);
+ (char *)NULL);
rb_define_method(cMemoryStatus, "_update", read_status, 0);
}