ruby-changes:67048
From: Nobuyoshi <ko1@a...>
Date: Thu, 5 Aug 2021 17:14:49 +0900 (JST)
Subject: [ruby-changes:67048] ae275f67ce (master): Show WorkingSetSize as RSS on Windows
https://git.ruby-lang.org/ruby.git/commit/?id=ae275f67ce From ae275f67cea586933d9983c066c2771f83c76943 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 5 Aug 2021 14:16:09 +0900 Subject: Show WorkingSetSize as RSS on Windows --- ext/-test-/memory_status/memory_status.c | 19 +++++++++++++++---- tool/lib/memory_status.rb | 5 +++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ext/-test-/memory_status/memory_status.c b/ext/-test-/memory_status/memory_status.c index 5775fa5..afacbee 100644 --- a/ext/-test-/memory_status/memory_status.c +++ b/ext/-test-/memory_status/memory_status.c @@ -10,11 +10,15 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L10 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L44 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_status/memory_status.c#L69 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); diff --git a/tool/lib/memory_status.rb b/tool/lib/memory_status.rb index ad002b2..4415443 100644 --- a/tool/lib/memory_status.rb +++ b/tool/lib/memory_status.rb @@ -56,11 +56,12 @@ module Memory https://github.com/ruby/ruby/blob/trunk/tool/lib/memory_status.rb#L56 end end - keys << :peak << :size + keys.push(:size, :rss, :peak) def self.read_status if info = Win32.memory_info - yield :peak, info.PeakPagefileUsage yield :size, info.PagefileUsage + yield :rss, info.WorkingSetSize + yield :peak, info.PeakWorkingSetSize end end when (require_relative 'find_executable' -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/