Skip to content

Add a DTrace probe for string capacity resizes #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions probes.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));\
Expand Down