diff --git a/probes.d b/probes.d index 57a3d762bd16c9..1e3609ee00095b 100644 --- a/probes.d +++ b/probes.d @@ -151,6 +151,18 @@ provider ruby { */ probe string__create(long length, const char *filename, int lineno); + /* + ruby:::string-capa-resize(from_capa, to_capa, filename, lineno); + + This probe is fired when String capacity is changed + + * `from_capa` the current capacity of the string (long) + * `to_capa` the new capacity of the string (long) + * `filename` the name of the file where the string is allocated (string) + * `lineno` the line number in the file where the string is allocated (int) + */ + probe string__capa__resize(long from_capa, long to_capa, const char *filename, int lineno); + /* ruby:::symbol-create(str, filename, lineno); diff --git a/string.c b/string.c index fefcd05e640eef..7159c058920fc3 100644 --- a/string.c +++ b/string.c @@ -132,6 +132,18 @@ VALUE rb_cSymbol; RESIZE_CAPA_TERM(str,capacity,termlen);\ } while (0) #define RESIZE_CAPA_TERM(str,capacity,termlen) do {\ + if (UNLIKELY(RUBY_DTRACE_STRING_CAPA_RESIZE_ENABLED())) {\ + int dtrace_line; \ + const char *dtrace_file = rb_source_location_cstr(&dtrace_line); \ + long prev_capa;\ + if (STR_EMBED_P(str)) {\ + prev_capa = RSTRING_EMBED_LEN_MAX + 1 - termlen;\ + } else {\ + prev_capa = RSTRING(str)->as.heap.aux.capa;\ + }\ + if (!dtrace_file) dtrace_file = ""; \ + RUBY_DTRACE_STRING_CAPA_RESIZE(prev_capa, capacity, dtrace_file, dtrace_line);\ + }\ if (STR_EMBED_P(str)) {\ if (!STR_EMBEDDABLE_P(capacity, termlen)) {\ char *const tmp = ALLOC_N(char, (size_t)(capacity) + (termlen));\