jemalloc_ctl 0.1.1 → 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 +23 -22
- data/lib/jemalloc_ctl.rb +13 -0
- 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,55 +44,55 @@ 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
|
}
|
|
56
58
|
|
|
57
|
-
static VALUE
|
|
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
|
-
bool val =
|
|
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
|
}
|
|
70
72
|
|
|
71
|
-
static VALUE
|
|
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
|
-
bool
|
|
77
|
-
int err = my_mallctl("
|
|
78
|
+
bool enabled = RTEST(onoff);
|
|
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
|
-
return
|
|
84
|
+
return Qtrue;
|
|
83
85
|
}
|
|
84
86
|
|
|
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
|
}
|
|
@@ -118,11 +120,8 @@ static void write_stats_cb(void *opaque, const char *buf)
|
|
|
118
120
|
|
|
119
121
|
static VALUE rb_jemalloc_ctl_print_stats(VALUE self, VALUE filename)
|
|
120
122
|
{
|
|
121
|
-
if (my_mallctl == NULL)
|
|
122
|
-
rb_raise(rb_eRuntimeError, "jemalloc is not available");
|
|
123
|
-
|
|
124
123
|
if (my_malloc_stats_print == NULL)
|
|
125
|
-
rb_raise(
|
|
124
|
+
rb_raise(rb_eJemallocCtlError, "malloc_stats_print is not available");
|
|
126
125
|
|
|
127
126
|
const char *path = StringValueCStr(filename);
|
|
128
127
|
FILE *f = fopen(path, "w");
|
|
@@ -176,11 +175,13 @@ void Init_jemalloc_ctl(void)
|
|
|
176
175
|
#endif
|
|
177
176
|
|
|
178
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);
|
|
179
180
|
rb_define_singleton_method(rb_mJemallocCtl, "enabled?", rb_jemalloc_ctl_enabled_p, 0);
|
|
180
181
|
rb_define_singleton_method(rb_mJemallocCtl, "version", rb_jemalloc_ctl_version, 0);
|
|
181
|
-
rb_define_singleton_method(rb_mJemallocCtl, "enable_background_thread", rb_jemalloc_ctl_enable_background_thread, 0);
|
|
182
|
-
rb_define_singleton_method(rb_mJemallocCtl, "disable_background_thread", rb_jemalloc_ctl_disable_background_thread, 0);
|
|
183
182
|
rb_define_singleton_method(rb_mJemallocCtl, "print_stats", rb_jemalloc_ctl_print_stats, 1);
|
|
183
|
+
rb_define_singleton_method(rb_mJemallocCtl, "toggle_background_thread", rb_jemalloc_ctl_toggle_background_thread, 1);
|
|
184
184
|
rb_define_singleton_method(rb_mJemallocCtl, "purge_arenas", rb_jemalloc_ctl_purge_arenas, 0);
|
|
185
185
|
rb_define_singleton_method(rb_mJemallocCtl, "flush_current_thread_tcache", rb_jemalloc_ctl_flush_current_thread_tcache, 0);
|
|
186
|
+
rb_define_singleton_method(rb_mJemallocCtl, "toggle_current_thread_tcache", rb_jemalloc_ctl_toggle_current_thread_tcache, 1);
|
|
186
187
|
}
|
data/lib/jemalloc_ctl.rb
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
require "jemalloc_ctl/jemalloc_ctl"
|
|
2
2
|
module JemallocCtl
|
|
3
|
+
def self.disable_background_thread
|
|
4
|
+
toggle_background_thread(false)
|
|
5
|
+
end
|
|
6
|
+
def self.enable_background_thread
|
|
7
|
+
toggle_background_thread(true)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.disable_current_thread_tcache
|
|
11
|
+
toggle_current_thread_tcache(false)
|
|
12
|
+
end
|
|
13
|
+
def self.enable_current_thread_tcache
|
|
14
|
+
toggle_current_thread_tcache(true)
|
|
15
|
+
end
|
|
3
16
|
end
|