jemalloc_ctl 0.1.2 → 0.1.3
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/ext/jemalloc_ctl/jemalloc_ctl.c +15 -11
- 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: 0ee6bbbd66f548328f75198782d1981fb0b2b06772b6d19cb81496157e3efcf4
|
|
4
|
+
data.tar.gz: fab1affaa3c8c1d94c4b681d1eebb35262acbbfef6faa37ba6dc302a9223bef8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c64a56894264596d6679879cac23f9ace7b17dbcfb6e0f7bd60198e0f5dd8326baa651757d2f465aea80803b735161e2886563805add92d0e1be0c81ae5af52c
|
|
7
|
+
data.tar.gz: ba4c2cb7e37d667485cb58c431ba3479ea5a8394928278279d9271b8479e2a60f3fce6aca477635158fbf59a1276f28c637a93e52ea767a248b28d2577da60cc
|
|
@@ -33,6 +33,8 @@ static malloc_stats_print_fn my_malloc_stats_print = NULL;
|
|
|
33
33
|
#endif
|
|
34
34
|
|
|
35
35
|
static VALUE rb_mJemallocCtl;
|
|
36
|
+
static VALUE rb_eJemallocCtlError;
|
|
37
|
+
static VALUE rb_eJemallocCtlJemallocNotFound;
|
|
36
38
|
|
|
37
39
|
static VALUE rb_jemalloc_ctl_enabled_p(VALUE self)
|
|
38
40
|
{
|
|
@@ -42,14 +44,14 @@ static VALUE rb_jemalloc_ctl_enabled_p(VALUE self)
|
|
|
42
44
|
static VALUE rb_jemalloc_ctl_version(VALUE self)
|
|
43
45
|
{
|
|
44
46
|
if (my_mallctl == NULL)
|
|
45
|
-
rb_raise(
|
|
47
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
46
48
|
|
|
47
49
|
const char *version;
|
|
48
50
|
size_t sz = sizeof(version);
|
|
49
51
|
int err = my_mallctl("version", &version, &sz, NULL, 0);
|
|
50
52
|
|
|
51
53
|
if (err != 0)
|
|
52
|
-
rb_raise(
|
|
54
|
+
rb_raise(rb_eJemallocCtlError, "mallctl(\"version\") failed with error %d", err);
|
|
53
55
|
|
|
54
56
|
return rb_str_new_cstr(version);
|
|
55
57
|
}
|
|
@@ -57,13 +59,13 @@ static VALUE rb_jemalloc_ctl_version(VALUE self)
|
|
|
57
59
|
static VALUE rb_jemalloc_ctl_toggle_background_thread(VALUE self, VALUE onoff)
|
|
58
60
|
{
|
|
59
61
|
if (my_mallctl == NULL)
|
|
60
|
-
rb_raise(
|
|
62
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
61
63
|
|
|
62
64
|
bool val = RTEST(onoff);
|
|
63
65
|
int err = my_mallctl("background_thread", NULL, NULL, &val, sizeof(bool));
|
|
64
66
|
|
|
65
67
|
if (err != 0)
|
|
66
|
-
rb_raise(
|
|
68
|
+
rb_raise(rb_eJemallocCtlError, "mallctl(\"background_thread\") failed with error %d", err);
|
|
67
69
|
|
|
68
70
|
return Qtrue;
|
|
69
71
|
}
|
|
@@ -71,13 +73,13 @@ static VALUE rb_jemalloc_ctl_toggle_background_thread(VALUE self, VALUE onoff)
|
|
|
71
73
|
static VALUE rb_jemalloc_ctl_toggle_current_thread_tcache(VALUE self, VALUE onoff)
|
|
72
74
|
{
|
|
73
75
|
if (my_mallctl == NULL)
|
|
74
|
-
rb_raise(
|
|
76
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
75
77
|
|
|
76
78
|
bool enabled = RTEST(onoff);
|
|
77
79
|
int err = my_mallctl("thread.tcache.enabled", NULL, NULL, &enabled, sizeof(enabled));
|
|
78
80
|
|
|
79
81
|
if (err != 0)
|
|
80
|
-
rb_raise(
|
|
82
|
+
rb_raise(rb_eJemallocCtlError, "mallctl(\"thread.tcache.enabled\") failed with error %d", err);
|
|
81
83
|
|
|
82
84
|
return Qtrue;
|
|
83
85
|
}
|
|
@@ -85,12 +87,12 @@ static VALUE rb_jemalloc_ctl_toggle_current_thread_tcache(VALUE self, VALUE onof
|
|
|
85
87
|
static VALUE rb_jemalloc_ctl_flush_current_thread_tcache(VALUE self)
|
|
86
88
|
{
|
|
87
89
|
if (my_mallctl == NULL)
|
|
88
|
-
rb_raise(
|
|
90
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
89
91
|
|
|
90
92
|
int err = my_mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
|
|
91
93
|
|
|
92
94
|
if (err != 0)
|
|
93
|
-
rb_raise(
|
|
95
|
+
rb_raise(rb_eJemallocCtlError, "mallctl(\"thread.tcache.flush\") failed with error %d", err);
|
|
94
96
|
|
|
95
97
|
return Qtrue;
|
|
96
98
|
}
|
|
@@ -98,7 +100,7 @@ static VALUE rb_jemalloc_ctl_flush_current_thread_tcache(VALUE self)
|
|
|
98
100
|
static VALUE rb_jemalloc_ctl_purge_arenas(VALUE self)
|
|
99
101
|
{
|
|
100
102
|
if (my_mallctl == NULL)
|
|
101
|
-
rb_raise(
|
|
103
|
+
rb_raise(rb_eJemallocCtlJemallocNotFound, "jemalloc is not available");
|
|
102
104
|
|
|
103
105
|
char ctl[32];
|
|
104
106
|
snprintf(ctl, sizeof(ctl), "arena.%d.purge", MALLCTL_ARENAS_ALL);
|
|
@@ -106,7 +108,7 @@ static VALUE rb_jemalloc_ctl_purge_arenas(VALUE self)
|
|
|
106
108
|
int err = my_mallctl(ctl, NULL, NULL, NULL, 0);
|
|
107
109
|
|
|
108
110
|
if (err != 0)
|
|
109
|
-
rb_raise(
|
|
111
|
+
rb_raise(rb_eJemallocCtlError, "mallctl(\"%s\") failed with error %d", ctl, err);
|
|
110
112
|
|
|
111
113
|
return Qtrue;
|
|
112
114
|
}
|
|
@@ -119,7 +121,7 @@ static void write_stats_cb(void *opaque, const char *buf)
|
|
|
119
121
|
static VALUE rb_jemalloc_ctl_print_stats(VALUE self, VALUE filename)
|
|
120
122
|
{
|
|
121
123
|
if (my_malloc_stats_print == NULL)
|
|
122
|
-
rb_raise(
|
|
124
|
+
rb_raise(rb_eJemallocCtlError, "malloc_stats_print is not available");
|
|
123
125
|
|
|
124
126
|
const char *path = StringValueCStr(filename);
|
|
125
127
|
FILE *f = fopen(path, "w");
|
|
@@ -173,6 +175,8 @@ void Init_jemalloc_ctl(void)
|
|
|
173
175
|
#endif
|
|
174
176
|
|
|
175
177
|
rb_mJemallocCtl = rb_define_module("JemallocCtl");
|
|
178
|
+
rb_eJemallocCtlError = rb_define_class_under(rb_mJemallocCtl, "Error", rb_eStandardError);
|
|
179
|
+
rb_eJemallocCtlJemallocNotFound = rb_define_class_under(rb_mJemallocCtl, "JemallocNotFound", rb_eJemallocCtlError);
|
|
176
180
|
rb_define_singleton_method(rb_mJemallocCtl, "enabled?", rb_jemalloc_ctl_enabled_p, 0);
|
|
177
181
|
rb_define_singleton_method(rb_mJemallocCtl, "version", rb_jemalloc_ctl_version, 0);
|
|
178
182
|
rb_define_singleton_method(rb_mJemallocCtl, "print_stats", rb_jemalloc_ctl_print_stats, 1);
|