* 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
This commit is contained in:
nobu 2016-10-08 01:54:24 +00:00
Родитель f0e1d72316
Коммит 1bbe67f5f6
3 изменённых файлов: 21 добавлений и 1 удалений

Просмотреть файл

@ -1,4 +1,7 @@
Sat Oct 8 10:34:25 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sat Oct 8 10:54:22 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/-test-/memory_status/memory_status.c (read_status): use
Win32 GetProcessMemoryInfo API.
* ext/-test-/memory_status/memory_status.c: get memory sizes by
mach task_info system call.

Просмотреть файл

@ -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

Просмотреть файл

@ -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);