leak_profiler 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -5
- data/ext/leak_profiler/leak_profiler.c +31 -17
- data/lib/leak_profiler/memory_usage.rb +1 -1
- data/sig/leak_profiler.rbs +1 -1
- data/test/test_memory_usage.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0cec55b42b6d790d84c3b54c009da7623040f8aa5c0d3a871eb8d44546d82aa
|
4
|
+
data.tar.gz: 0f576971b8e6b1734f51ab4a1bdbb8e00d2822a1eedb1e24f53dc7342c25caff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1636ecd9234f7ba4216c2dbc22892c7aafef11cf26efda7c198dccde3c45cc5273eb2f23974d9524c6d2435f44533c2b20b60f0c70473bc69ebf0101729eddda
|
7
|
+
data.tar.gz: b05038cb49f6e21a1a44a3dcc8525c3ee6fdb24a8aa4ae0c04b0544f8a4121218dbe80932281970d61260adc05e38042b2272c4502da4d516e71f0569f589748
|
data/README.md
CHANGED
@@ -86,11 +86,6 @@ elapsed [sec],memory usage (rss) [MB]
|
|
86
86
|
* `interval` (default `1`): The interval in seconds for report.
|
87
87
|
* `filename` (defalut `nil`): Specify the filename if you want to use custom filename.
|
88
88
|
|
89
|
-
> [!WARNING]
|
90
|
-
> This uses this uses `ps` command for measurement.
|
91
|
-
> So, this is not supported Windows platform.
|
92
|
-
|
93
|
-
|
94
89
|
### `LeakProfiler#report_memsize`
|
95
90
|
This method outputs `ObjectSpace.memsize_of_all` values with CSV format, like:
|
96
91
|
|
@@ -1,38 +1,52 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <unistd.h>
|
3
4
|
|
4
5
|
// get the maximum resident set size (RSS) of the current process
|
5
6
|
// return the value in kilobytes
|
6
7
|
#if defined(_WIN32)
|
7
8
|
#include <psapi.h>
|
8
9
|
|
9
|
-
static VALUE
|
10
|
+
static VALUE leak_profiler_rss(VALUE self)
|
10
11
|
{
|
11
|
-
|
12
|
+
PROCESS_MEMORY_COUNTERS pmc;
|
12
13
|
if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
13
14
|
rb_sys_fail("GetProcessMemoryInfo");
|
14
15
|
}
|
15
16
|
return LONG2NUM(pmc.PeakWorkingSetSize / 1024);
|
16
17
|
}
|
17
18
|
|
18
|
-
#
|
19
|
-
#include <sys/resource.h>
|
19
|
+
#elif defined(__APPLE__)
|
20
20
|
|
21
|
-
|
22
|
-
{
|
23
|
-
struct rusage usage;
|
24
|
-
long max_rss;
|
21
|
+
#include <mach/mach.h>
|
25
22
|
|
26
|
-
|
27
|
-
|
23
|
+
static VALUE leak_profiler_rss(VALUE self)
|
24
|
+
{
|
25
|
+
struct mach_task_basic_info info;
|
26
|
+
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
|
27
|
+
kern_return_t kr = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count);
|
28
|
+
if (kr != KERN_SUCCESS) {
|
29
|
+
rb_sys_fail("task_info");
|
28
30
|
}
|
29
|
-
|
31
|
+
return LONG2NUM(info.resident_size / 1024);
|
32
|
+
}
|
30
33
|
|
31
|
-
#
|
32
|
-
max_rss = max_rss / 1024;
|
33
|
-
#endif
|
34
|
+
#else // linux
|
34
35
|
|
35
|
-
|
36
|
+
static VALUE leak_profiler_rss(VALUE self)
|
37
|
+
{
|
38
|
+
long rss = 0;
|
39
|
+
|
40
|
+
FILE *file = fopen("/proc/self/statm", "r");
|
41
|
+
if (!file) {
|
42
|
+
rb_sys_fail("/proc/self/statm");
|
43
|
+
}
|
44
|
+
if (fscanf(file, "%*s%ld", &rss) != 1) {
|
45
|
+
fclose(file);
|
46
|
+
rb_sys_fail("fscanf");
|
47
|
+
}
|
48
|
+
fclose(file);
|
49
|
+
return LONG2NUM(rss * sysconf(_SC_PAGESIZE) / 1024);
|
36
50
|
}
|
37
51
|
|
38
52
|
#endif
|
@@ -43,5 +57,5 @@ void Init_leak_profiler_ext(void)
|
|
43
57
|
VALUE cMemoryUsage = rb_define_class_under(cLeakProfiler, "MemoryUsage", rb_cObject);
|
44
58
|
|
45
59
|
|
46
|
-
rb_define_singleton_method(cMemoryUsage, "
|
60
|
+
rb_define_singleton_method(cMemoryUsage, "rss", leak_profiler_rss, 0);
|
47
61
|
}
|
data/sig/leak_profiler.rbs
CHANGED
data/test/test_memory_usage.rb
CHANGED