-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add simple object events to tracepoint api (c-api only)
- Loading branch information
Showing
7 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
create_makefile("-test-/tracepoint") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "ruby.h" | ||
#include "ruby/debug.h" | ||
|
||
static size_t count; | ||
static VALUE objects[10]; | ||
|
||
void | ||
newobj_callback(VALUE tpval, void *data) | ||
{ | ||
rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval); | ||
VALUE obj = rb_tracearg_object(tparg); | ||
|
||
if (count < sizeof(objects)) | ||
objects[count++] = obj; | ||
} | ||
|
||
VALUE | ||
tracepoint_track_newobj(VALUE self) | ||
{ | ||
VALUE tpval = rb_tracepoint_new(0, RUBY_EVENT_OBJ_NEW, newobj_callback, 0); | ||
|
||
count = 0; | ||
memset(objects, (VALUE)Qnil, sizeof(objects)); | ||
|
||
rb_tracepoint_enable(tpval); | ||
rb_yield(Qundef); | ||
rb_tracepoint_disable(tpval); | ||
|
||
return rb_ary_new4(count, objects); | ||
} | ||
|
||
void | ||
Init_tracepoint(void) | ||
{ | ||
VALUE mBug = rb_define_module("Bug"); | ||
rb_define_module_function(mBug, "tracepoint_track_newobj", tracepoint_track_newobj, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'test/unit' | ||
require '-test-/tracepoint' | ||
|
||
class TestTracepointObj < Test::Unit::TestCase | ||
def test_not_available_from_ruby | ||
assert_raises ArgumentError do | ||
TracePoint.trace(:obj_new){} | ||
end | ||
end | ||
|
||
def test_tracks_newly_created_objects | ||
newobjs = Bug.tracepoint_track_newobj{ | ||
99 | ||
'abc' | ||
v="foobar" | ||
Object.new | ||
nil | ||
} | ||
|
||
assert_equal 2, newobjs.size | ||
assert_equal 'foobar', newobjs[0] | ||
assert_equal Object, newobjs[1].class | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters