mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Show WorkingSetSize as RSS on Windows
This commit is contained in:
parent
228b3e43be
commit
ae275f67ce
Notes:
git
2021-08-05 17:14:59 +09:00
2 changed files with 18 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -56,11 +56,12 @@ module Memory
|
|||
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'
|
||||
|
|
Loading…
Add table
Reference in a new issue