From 680f0b5ba4eb4ba4f542ebc8d1204da61b71eb92 Mon Sep 17 00:00:00 2001 From: ko1 Date: Mon, 27 May 2013 00:21:02 +0000 Subject: * include/ruby/ruby.h, gc.c, vm_trace.c: add internal events. * RUBY_INTERNAL_EVENT_NEWOBJ: object created. * RUBY_INTERNAL_EVENT_FREE: object freeed. * RUBY_INTERNAL_EVENT_GC_START: GC started. And rename `RUBY_EVENT_SWITCH' to `RUBY_INTERNAL_EVENT_SWITCH'. Internal events can not invoke any Ruby program because the tracing timing may be critical (under huge restriction). These events can be hooked only by C-extensions. We recommend to use rb_potponed_job_register() API to call Ruby program safely. This change is mostly written by Aman Gupta (tmm1). https://bugs.ruby-lang.org/issues/8107#note-12 [Feature #8107] * include/ruby/debug.h, vm_trace.c: added two new APIs. * rb_tracearg_event_flag() returns rb_event_flag_t of this event. * rb_tracearg_object() returns created/freeed object. * ext/-test-/tracepoint/extconf.rb, ext/-test-/tracepoint/tracepoint.c, test/-ext-/tracepoint/test_tracepoint.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/tracepoint/test_tracepoint.rb | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/-ext-/tracepoint/test_tracepoint.rb (limited to 'test') diff --git a/test/-ext-/tracepoint/test_tracepoint.rb b/test/-ext-/tracepoint/test_tracepoint.rb new file mode 100644 index 0000000000..058809471f --- /dev/null +++ b/test/-ext-/tracepoint/test_tracepoint.rb @@ -0,0 +1,40 @@ +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_objspace_events + result = Bug.tracepoint_track_objspace_events{ + 99 + 'abc' + v="foobar" + Object.new + nil + } + + newobj_count, free_count, gc_start_count, *newobjs = *result + assert_equal 2, newobj_count + assert_equal 2, newobjs.size + assert_equal 'foobar', newobjs[0] + assert_equal Object, newobjs[1].class + + stat1 = {} + stat2 = {} + GC.stat(stat1) + result = Bug.tracepoint_track_objspace_events{ + 1_000_000.times{''} + } + GC.stat(stat2) + + newobj_count, free_count, gc_start_count, *newobjs = *result + + assert_operator stat2[:total_allocated_object] - stat1[:total_allocated_object], :>=, newobj_count + assert_operator stat2[:total_freed_object] - stat1[:total_freed_object], :>=, free_count + assert_operator stat2[:count] - stat1[:count], :==, gc_start_count + end +end -- cgit v1.2.3