public

  • Download Gist
add_object_id_to_xx_create_probes.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
diff --git a/array.c b/array.c
index 2454b99..57673b7 100644
--- a/array.c
+++ b/array.c
@@ -379,11 +379,12 @@ ary_alloc(VALUE klass)
static VALUE
empty_ary_alloc(VALUE klass)
{
+ VALUE ary = ary_alloc(klass);
if(RUBY_DTRACE_ARRAY_CREATE_ENABLED()) {
- RUBY_DTRACE_ARRAY_CREATE(0, rb_sourcefile(), rb_sourceline());
+ RUBY_DTRACE_ARRAY_CREATE(NUM2LONG(rb_obj_id(ary)), 0, rb_sourcefile(), rb_sourceline());
}
- return ary_alloc(klass);
+ return ary;
}
static VALUE
@@ -398,10 +399,6 @@ 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());
- }
-
ary = ary_alloc(klass);
if (capa > RARRAY_EMBED_LEN_MAX) {
FL_UNSET_EMBED(ary);
@@ -409,6 +406,9 @@ ary_new(VALUE klass, long capa)
ARY_SET_CAPA(ary, capa);
ARY_SET_HEAP_LEN(ary, 0);
}
+ if(RUBY_DTRACE_ARRAY_CREATE_ENABLED()) {
+ RUBY_DTRACE_ARRAY_CREATE(NUM2LONG(rb_obj_id(ary)), capa, rb_sourcefile(), rb_sourceline());
+ }
return ary;
}
diff --git a/hash.c b/hash.c
index a9047be..40b099d 100644
--- a/hash.c
+++ b/hash.c
@@ -219,11 +219,12 @@ hash_alloc(VALUE klass)
static VALUE
empty_hash_alloc(VALUE klass)
{
+ VALUE hash = hash_alloc(klass);
if(RUBY_DTRACE_HASH_CREATE_ENABLED()) {
- RUBY_DTRACE_HASH_CREATE(0, rb_sourcefile(), rb_sourceline());
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(hash)), 0, rb_sourcefile(), rb_sourceline());
}
- return hash_alloc(klass);
+ return hash;
}
VALUE
diff --git a/insns.def b/insns.def
index c491896..6d3b045 100644
--- a/insns.def
+++ b/insns.def
@@ -525,12 +525,12 @@ newhash
{
rb_num_t i;
+ val = rb_hash_new();
+
if(RUBY_DTRACE_HASH_CREATE_ENABLED()) {
- RUBY_DTRACE_HASH_CREATE(num, rb_sourcefile(), rb_sourceline());
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(val)), num, rb_sourcefile(), rb_sourceline());
}
- val = rb_hash_new();
-
for (i = num; i > 0; i -= 2) {
const VALUE v = TOPN(i - 2);
const VALUE k = TOPN(i - 1);
diff --git a/object.c b/object.c
index 712d76a..b089864 100644
--- a/object.c
+++ b/object.c
@@ -1686,17 +1686,18 @@ rb_obj_alloc(VALUE klass)
klass);
}
+ obj = (*allocator)(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),
+ RUBY_DTRACE_OBJECT_CREATE(NUM2LONG(rb_obj_id(obj)),
+ rb_class2name(klass),
file ? file : "",
rb_sourceline());
}
#endif
- obj = (*allocator)(klass);
-
if (rb_obj_class(obj) != rb_class_real(klass)) {
rb_raise(rb_eTypeError, "wrong instance allocation");
}
diff --git a/probes.d b/probes.d
index 591b2f4..9e7f601 100644
--- a/probes.d
+++ b/probes.d
@@ -18,10 +18,10 @@ provider ruby {
probe raise(const char *, const char *, int);
- probe object__create(const char *, const char *, int);
- probe array__create(long, const char *, int);
- probe hash__create(long, const char *, int);
- probe string__create(long, const char *, int);
+ probe object__create(long, const char *, const char *, int);
+ probe array__create(long, long, const char *, int);
+ probe hash__create(long, long, const char *, int);
+ probe string__create(long, long, const char *, int);
probe parse__begin(const char *, int);
probe parse__end(const char *, int);
diff --git a/string.c b/string.c
index f2ee280..1ac612e 100644
--- a/string.c
+++ b/string.c
@@ -385,10 +385,11 @@ str_alloc(VALUE klass)
static inline VALUE
empty_str_alloc(VALUE klass)
{
+ VALUE str = str_alloc(klass);
if(RUBY_DTRACE_STRING_CREATE_ENABLED()) {
- RUBY_DTRACE_STRING_CREATE(0, rb_sourcefile(), rb_sourceline());
+ RUBY_DTRACE_STRING_CREATE(NUM2LONG(rb_obj_id(str)), 0, rb_sourcefile(), rb_sourceline());
}
- return str_alloc(klass);
+ return str;
}
static VALUE
@@ -400,10 +401,6 @@ str_new(VALUE klass, const char *ptr, long len)
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());
- }
-
str = str_alloc(klass);
if (len > RSTRING_EMBED_LEN_MAX) {
RSTRING(str)->as.heap.aux.capa = len;
@@ -418,6 +415,11 @@ str_new(VALUE klass, const char *ptr, long len)
}
STR_SET_LEN(str, len);
RSTRING_PTR(str)[len] = '\0';
+
+ if(RUBY_DTRACE_STRING_CREATE_ENABLED()) {
+ RUBY_DTRACE_STRING_CREATE(NUM2LONG(rb_obj_id(str)), len, rb_sourcefile(), rb_sourceline());
+ }
+
return str;
}
@@ -932,11 +934,13 @@ rb_str_dup(VALUE str)
VALUE
rb_str_resurrect(VALUE str)
{
+ VALUE new_str = str_alloc(rb_cString);
+
if(RUBY_DTRACE_STRING_CREATE_ENABLED()) {
RUBY_DTRACE_STRING_CREATE(
- RSTRING_LEN(str), rb_sourcefile(), rb_sourceline());
+ NUM2LONG(rb_obj_id(new_str)), RSTRING_LEN(str), rb_sourcefile(), rb_sourceline());
}
- return str_replace(str_alloc(rb_cString), str);
+ return str_replace(new_str, str);
}
/*
diff --git a/test/dtrace/test_array_create.rb b/test/dtrace/test_array_create.rb
index affcd47..993fc45 100644
--- a/test/dtrace/test_array_create.rb
+++ b/test/dtrace/test_array_create.rb
@@ -4,17 +4,18 @@ module DTrace
class TestArrayCreate < TestCase
def test_lit
trap_probe(probe, '[]') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '0'
}
assert_equal([rbfile], saw.map { |line| line[1] })
assert_equal(['1'], saw.map { |line| line[2] })
+ saw.each {|line| assert_not_equal(0, line[3].to_i) }
}
end
def test_many_lit
trap_probe(probe, '[1,2,3,4]') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '4' && line == '1'
}
assert_operator saw.length, :>, 0
@@ -27,7 +28,7 @@ module DTrace
ruby$target:::#{type}-create
/arg1/
{
- printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2);
+ printf("%d %d %s %d\\n", arg0, arg1, copyinstr(arg2), arg3);
}
eoprobe
end
diff --git a/test/dtrace/test_hash_create.rb b/test/dtrace/test_hash_create.rb
index 91dd6ce..75480d3 100644
--- a/test/dtrace/test_hash_create.rb
+++ b/test/dtrace/test_hash_create.rb
@@ -4,7 +4,7 @@ module DTrace
class TestHashCreate < TestCase
def test_hash_new
trap_probe(probe, 'Hash.new') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '0'
}
assert_operator saw.length, :>, 0
@@ -13,7 +13,7 @@ module DTrace
def test_hash_lit
trap_probe(probe, '{}') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '0'
}
assert_operator saw.length, :>, 0
@@ -22,7 +22,7 @@ module DTrace
def test_hash_lit_elements
trap_probe(probe, '{ :foo => :bar }') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '2'
}
assert_operator saw.length, :>, 0
@@ -31,7 +31,7 @@ module DTrace
def test_hash_lit_elements_string
trap_probe(probe, '{ :foo => :bar, :bar => "baz" }') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |num, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, num, file, line|
file == rbfile && num == '4'
}
assert_operator saw.length, :>, 0
@@ -44,7 +44,7 @@ module DTrace
ruby$target:::hash-create
/arg1/
{
- printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2);
+ printf("%d %d %s %d\\n", arg0, arg1, copyinstr(arg2), arg3);
}
eoprobe
end
diff --git a/test/dtrace/test_object_create_start.rb b/test/dtrace/test_object_create_start.rb
index ae4fb74..6dd84b7 100644
--- a/test/dtrace/test_object_create_start.rb
+++ b/test/dtrace/test_object_create_start.rb
@@ -4,7 +4,7 @@ module DTrace
class TestObjectCreateStart < TestCase
def test_object_create_start
trap_probe(probe, '10.times { Object.new }') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |_, file, _|
+ saw = saw.map(&:split).find_all { |_, _, file, _|
file == rbfile
}
assert_equal 10, saw.length
@@ -13,12 +13,13 @@ module DTrace
def test_object_create_start_name
trap_probe(probe, 'Hash.new') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |klass, file, line|
+ saw = saw.map(&:split).find_all { |obj_id, klass, file, line|
file == rbfile
}
- assert_equal(%w{ Hash }, saw.map(&:first))
- assert_equal([rbfile], saw.map { |line| line[1] })
- assert_equal(['1'], saw.map { |line| line[2] })
+ saw.each {|line| assert_not_equal(0, line[0].to_i) }
+ assert_equal(%w{ Hash }, saw.map{|s| s[1]})
+ assert_equal([rbfile], saw.map { |line| line[2] })
+ assert_equal(['1'], saw.map { |line| line[3] })
}
end
@@ -27,7 +28,7 @@ module DTrace
<<-eoprobe
ruby$target:::object-create
{
- printf("%s %s %d\\n", copyinstr(arg0), copyinstr(arg1), arg2);
+ printf("%s %s %d %d\\n", arg0, copyinstr(arg1), copyinstr(arg2), arg3);
}
eoprobe
end
diff --git a/test/dtrace/test_string.rb b/test/dtrace/test_string.rb
index 05e8033..e392a15 100644
--- a/test/dtrace/test_string.rb
+++ b/test/dtrace/test_string.rb
@@ -4,12 +4,13 @@ module DTrace
class TestStringProbes < TestCase
def test_object_create_start_string_lit
trap_probe(probe, '"omglolwutbbq"') { |_,rbfile,saw|
- saw = saw.map(&:split).find_all { |klass, file, line, len|
+ saw = saw.map(&:split).find_all { |obj_id, klass, file, line, len|
file == rbfile && len == '12' && line == '1'
}
- assert_equal(%w{ String }, saw.map(&:first))
- assert_equal([rbfile], saw.map { |line| line[1] })
- assert_equal(['1'], saw.map { |line| line[2] })
+ saw.each {|line| assert_not_equal(0, line[0].to_i) }
+ assert_equal(%w{ String }, saw.map{|line| line[1] })
+ assert_equal([rbfile], saw.map { |line| line[2] })
+ assert_equal(['1'], saw.map { |line| line[3] })
}
end
@@ -19,7 +20,7 @@ module DTrace
ruby$target:::string-create
/arg1/
{
- printf("String %s %d %d\\n", copyinstr(arg1), arg2, arg0);
+ printf("String %d %s %d %d\\n", arg0, copyinstr(arg2), arg3, arg1);
}
eoprobe
end
diff --git a/vm.c b/vm.c
index f14d391..10f9ab9 100644
--- a/vm.c
+++ b/vm.c
@@ -1986,15 +1986,15 @@ m_core_hash_from_ary(VALUE self, VALUE ary)
VALUE hash = rb_hash_new();
int i;
- if(RUBY_DTRACE_HASH_CREATE_ENABLED()) {
- RUBY_DTRACE_HASH_CREATE(RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline());
- }
-
assert(RARRAY_LEN(ary) % 2 == 0);
for (i=0; i<RARRAY_LEN(ary); i+=2) {
rb_hash_aset(hash, RARRAY_PTR(ary)[i], RARRAY_PTR(ary)[i+1]);
}
+ if(RUBY_DTRACE_HASH_CREATE_ENABLED()) {
+ RUBY_DTRACE_HASH_CREATE(NUM2LONG(rb_obj_id(hash)), RARRAY_LEN(ary), rb_sourcefile(), rb_sourceline());
+ }
+
return hash;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.