8000 Add a DTrace probe for string capacity resizes · github/ruby@871841c · GitHub
[go: up one dir, main page]

Skip to content

Commit 871841c

Browse files
committed
Add a DTrace probe for string capacity resizes
1 parent d95b13e commit 871841c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

probes.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ provider ruby {
151151
*/
152152
probe string__create(long length, const char *filename, int lineno);
153153

154+
/*
155+
ruby:::string-capa-resize(from_capa, to_capa, filename, lineno);
156+
157+
This probe is fired when String capacity is changed
158+
159+
* `from_capa` the current capacity of the string (long)
160+
* `to_capa` the new capacity of the string (long)
161+
* `filename` the name of the file where the string is allocated (string)
162+
* `lineno` the line number in the file where the string is allocated (int)
163+
*/
164+
probe string__capa__resize(long from_capa, long to_capa, const char *filename, int lineno);
165+
154166
/*
155167
ruby:::symbol-create(str, filename, lineno);
156168

string.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ VALUE rb_cSymbol;
132132
RESIZE_CAPA_TERM(str,capacity,termlen);\
133133
} while (0)
134134
#define RESIZE_CAPA_TERM(str,capacity,termlen) do {\
135+
if (UNLIKELY(RUBY_DTRACE_STRING_CAPA_RESIZE_ENABLED())) {\
136+
int dtrace_line; \
137+
const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \
138+
long prev_capa;\
139+
if (STR_EMBED_P(str)) {\
140+
prev_capa = RSTRING_EMBED_LEN_MAX + 1 - termlen;\
141+
} else {\
142+
prev_capa = RSTRING(str)->as.heap.aux.capa;\
143+
}\
144+
if (!dtrace_file) dtrace_file = ""; \
145+
RUBY_DTRACE_STRING_CAPA_RESIZE(prev_capa, capacity, dtrace_file, dtrace_line);\
146+
}\
135147
if (STR_EMBED_P(str)) {\
136148
if (!STR_EMBEDDABLE_P(capacity, termlen)) {\
137149
char *const tmp = ALLOC_N(char, (size_t)(capacity) + (termlen));\

0 commit comments

Comments
 (0)
0