mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
RUBY_DTRACE_CREATE_HOOK
* internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at object creation. * vm.c (rb_source_location, rb_source_loc): retrieve source path and line number at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1be5cb6371
commit
645116ff25
8 changed files with 48 additions and 45 deletions
9
array.c
9
array.c
|
@ -453,10 +453,7 @@ ary_alloc(VALUE klass)
|
|||
static VALUE
|
||||
empty_ary_alloc(VALUE klass)
|
||||
{
|
||||
if (RUBY_DTRACE_ARRAY_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_ARRAY_CREATE(0, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
|
||||
RUBY_DTRACE_CREATE_HOOK(ARRAY, 0);
|
||||
return ary_alloc(klass);
|
||||
}
|
||||
|
||||
|
@ -472,9 +469,7 @@ ary_new(VALUE klass, long capa)
|
|||
rb_raise(rb_eArgError, "array size too big");
|
||||
}
|
||||
|
||||
if (RUBY_DTRACE_ARRAY_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_ARRAY_CREATE(capa, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(ARRAY, capa);
|
||||
|
||||
ary = ary_alloc(klass);
|
||||
if (capa > RARRAY_EMBED_LEN_MAX) {
|
||||
|
|
4
hash.c
4
hash.c
|
@ -381,9 +381,7 @@ hash_alloc(VALUE klass)
|
|||
static VALUE
|
||||
empty_hash_alloc(VALUE klass)
|
||||
{
|
||||
if (RUBY_DTRACE_HASH_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_HASH_CREATE(0, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(HASH, 0);
|
||||
|
||||
return hash_alloc(klass);
|
||||
}
|
||||
|
|
|
@ -526,9 +526,7 @@ newhash
|
|||
{
|
||||
rb_num_t i;
|
||||
|
||||
if(RUBY_DTRACE_HASH_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_HASH_CREATE(num, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(HASH, num);
|
||||
|
||||
val = rb_hash_new();
|
||||
|
||||
|
@ -796,7 +794,7 @@ trace
|
|||
RUBY_DTRACE_CMETHOD_ENTRY_ENABLED() ||
|
||||
RUBY_DTRACE_CMETHOD_RETURN_ENABLED()) {
|
||||
|
||||
switch(flag) {
|
||||
switch (flag) {
|
||||
case RUBY_EVENT_CALL:
|
||||
RUBY_DTRACE_METHOD_ENTRY_HOOK(th, 0, 0);
|
||||
break;
|
||||
|
|
12
internal.h
12
internal.h
|
@ -1183,6 +1183,8 @@ void rb_vm_inc_const_missing_count(void);
|
|||
void rb_thread_mark(void *th);
|
||||
const void **rb_vm_get_insns_address_table(void);
|
||||
VALUE rb_sourcefilename(void);
|
||||
VALUE rb_source_location(int *pline);
|
||||
const char *rb_source_loc(int *pline);
|
||||
void rb_vm_pop_cfunc_frame(void);
|
||||
int rb_vm_add_root_module(ID id, VALUE module);
|
||||
void rb_vm_check_redefinition_by_prepend(VALUE klass);
|
||||
|
@ -1326,6 +1328,16 @@ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
|
|||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#define RUBY_DTRACE_CREATE_HOOK(name, arg) \
|
||||
do { \
|
||||
if (UNLIKELY(RUBY_DTRACE_##name##_CREATE_ENABLED())) { \
|
||||
int dtrace_line; \
|
||||
const char *dtrace_file = rb_source_loc(&dtrace_line); \
|
||||
if (!dtrace_file) dtrace_file = ""; \
|
||||
RUBY_DTRACE_##name##_CREATE(arg, dtrace_file, dtrace_line); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
|
|
9
object.c
9
object.c
|
@ -1810,14 +1810,7 @@ rb_obj_alloc(VALUE klass)
|
|||
klass);
|
||||
}
|
||||
|
||||
#if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED
|
||||
if (RUBY_DTRACE_OBJECT_CREATE_ENABLED()) {
|
||||
const char * file = rb_sourcefile();
|
||||
RUBY_DTRACE_OBJECT_CREATE(rb_class2name(klass),
|
||||
file ? file : "",
|
||||
rb_sourceline());
|
||||
}
|
||||
#endif
|
||||
RUBY_DTRACE_CREATE_HOOK(OBJECT, rb_class2name(klass));
|
||||
|
||||
obj = (*allocator)(klass);
|
||||
|
||||
|
|
17
string.c
17
string.c
|
@ -624,9 +624,7 @@ str_alloc(VALUE klass)
|
|||
static inline VALUE
|
||||
empty_str_alloc(VALUE klass)
|
||||
{
|
||||
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_STRING_CREATE(0, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(STRING, 0);
|
||||
return str_alloc(klass);
|
||||
}
|
||||
|
||||
|
@ -639,9 +637,7 @@ str_new0(VALUE klass, const char *ptr, long len, int termlen)
|
|||
rb_raise(rb_eArgError, "negative string size (or size too big)");
|
||||
}
|
||||
|
||||
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_STRING_CREATE(len, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(STRING, len);
|
||||
|
||||
str = str_alloc(klass);
|
||||
if (len > RSTRING_EMBED_LEN_MAX) {
|
||||
|
@ -746,9 +742,7 @@ str_new_static(VALUE klass, const char *ptr, long len, int encindex)
|
|||
str = str_new(klass, ptr, len);
|
||||
}
|
||||
else {
|
||||
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_STRING_CREATE(len, rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(STRING, len);
|
||||
str = str_alloc(klass);
|
||||
RSTRING(str)->as.heap.len = len;
|
||||
RSTRING(str)->as.heap.ptr = (char *)ptr;
|
||||
|
@ -1314,10 +1308,7 @@ rb_str_dup(VALUE str)
|
|||
VALUE
|
||||
rb_str_resurrect(VALUE str)
|
||||
{
|
||||
if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
|
||||
rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(STRING, RSTRING_LEN(str));
|
||||
return str_duplicate(rb_cString, str);
|
||||
}
|
||||
|
||||
|
|
8
symbol.c
8
symbol.c
|
@ -465,9 +465,7 @@ register_static_symid_str(ID id, VALUE str)
|
|||
OBJ_FREEZE(str);
|
||||
str = rb_fstring(str);
|
||||
|
||||
if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(str), rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(str));
|
||||
|
||||
register_sym(str, sym);
|
||||
set_id_entry(num, str, sym);
|
||||
|
@ -534,9 +532,7 @@ dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc, const
|
|||
register_sym(str, dsym);
|
||||
rb_hash_aset(global_symbols.dsymbol_fstr_hash, str, Qtrue);
|
||||
|
||||
if (RUBY_DTRACE_SYMBOL_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_SYMBOL_CREATE(RSTRING_PTR(RSYMBOL(dsym)->fstr), rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
RUBY_DTRACE_CREATE_HOOK(SYMBOL, RSTRING_PTR(RSYMBOL(dsym)->fstr));
|
||||
|
||||
return dsym;
|
||||
}
|
||||
|
|
28
vm.c
28
vm.c
|
@ -1111,6 +1111,29 @@ rb_sourceline(void)
|
|||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_source_location(int *pline)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(th, th->cfp);
|
||||
|
||||
if (cfp) {
|
||||
if (pline) *pline = rb_vm_get_sourceline(cfp);
|
||||
return cfp->iseq->body->location.path;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
rb_source_loc(int *pline)
|
||||
{
|
||||
VALUE path = rb_source_location(pline);
|
||||
if (!path) return 0;
|
||||
return RSTRING_PTR(path);
|
||||
}
|
||||
|
||||
rb_cref_t *
|
||||
rb_vm_cref(void)
|
||||
{
|
||||
|
@ -2428,10 +2451,7 @@ core_hash_from_ary(VALUE ary)
|
|||
{
|
||||
VALUE hash = rb_hash_new();
|
||||
|
||||
if (RUBY_DTRACE_HASH_CREATE_ENABLED()) {
|
||||
RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline());
|
||||
}
|
||||
|
||||
RUBY_DTRACE_CREATE_HOOK(HASH, RARRAY_LEN(ary));
|
||||
return core_hash_merge_ary(hash, ary);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue