mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
tracepoint.c: wrap data in a struct
* ext/-test-/tracepoint/tracepoint.c (struct tracepoint_track): wrap tracepoint tracking data in a struct to be placed on the stack. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3f3bec4911
commit
f856c1237b
1 changed files with 27 additions and 28 deletions
|
@ -1,38 +1,45 @@
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
#include "ruby/debug.h"
|
#include "ruby/debug.h"
|
||||||
|
|
||||||
static size_t newobj_count;
|
struct tracepoint_track {
|
||||||
static size_t free_count;
|
size_t newobj_count;
|
||||||
static size_t gc_start_count;
|
size_t free_count;
|
||||||
static size_t gc_end_count;
|
size_t gc_start_count;
|
||||||
static size_t objects_count;
|
size_t gc_end_count;
|
||||||
static VALUE objects[10];
|
size_t objects_count;
|
||||||
|
VALUE objects[10];
|
||||||
|
};
|
||||||
|
|
||||||
void
|
#define objects_max (sizeof(((struct tracepoint_track *)NULL)->objects)/sizeof(VALUE))
|
||||||
|
|
||||||
|
static void
|
||||||
tracepoint_track_objspace_events_i(VALUE tpval, void *data)
|
tracepoint_track_objspace_events_i(VALUE tpval, void *data)
|
||||||
{
|
{
|
||||||
rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval);
|
rb_trace_arg_t *tparg = rb_tracearg_from_tracepoint(tpval);
|
||||||
|
struct tracepoint_track *track = data;
|
||||||
|
|
||||||
switch (rb_tracearg_event_flag(tparg)) {
|
switch (rb_tracearg_event_flag(tparg)) {
|
||||||
case RUBY_INTERNAL_EVENT_NEWOBJ:
|
case RUBY_INTERNAL_EVENT_NEWOBJ:
|
||||||
{
|
{
|
||||||
VALUE obj = rb_tracearg_object(tparg);
|
VALUE obj = rb_tracearg_object(tparg);
|
||||||
if (objects_count < sizeof(objects)/sizeof(VALUE)) objects[objects_count++] = obj;
|
if (track->objects_count < objects_max)
|
||||||
newobj_count++;
|
track->objects[track->objects_count++] = obj;
|
||||||
|
track->newobj_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RUBY_INTERNAL_EVENT_FREEOBJ:
|
case RUBY_INTERNAL_EVENT_FREEOBJ:
|
||||||
{
|
{
|
||||||
free_count++;
|
track->free_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RUBY_INTERNAL_EVENT_GC_START:
|
case RUBY_INTERNAL_EVENT_GC_START:
|
||||||
{
|
{
|
||||||
gc_start_count++;
|
track->gc_start_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RUBY_INTERNAL_EVENT_GC_END:
|
case RUBY_INTERNAL_EVENT_GC_END:
|
||||||
{
|
{
|
||||||
gc_end_count++;
|
track->gc_end_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -40,28 +47,24 @@ tracepoint_track_objspace_events_i(VALUE tpval, void *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
static VALUE
|
||||||
tracepoint_track_objspace_events(VALUE self)
|
tracepoint_track_objspace_events(VALUE self)
|
||||||
{
|
{
|
||||||
|
struct tracepoint_track track = {0, 0, 0, 0, 0, {}};
|
||||||
VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ |
|
VALUE tpval = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ | RUBY_INTERNAL_EVENT_FREEOBJ |
|
||||||
RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END,
|
RUBY_INTERNAL_EVENT_GC_START | RUBY_INTERNAL_EVENT_GC_END,
|
||||||
tracepoint_track_objspace_events_i, 0);
|
tracepoint_track_objspace_events_i, &track);
|
||||||
VALUE result = rb_ary_new();
|
VALUE result = rb_ary_new();
|
||||||
size_t i;
|
|
||||||
|
|
||||||
newobj_count = free_count = gc_start_count = objects_count = 0;
|
|
||||||
|
|
||||||
rb_tracepoint_enable(tpval);
|
rb_tracepoint_enable(tpval);
|
||||||
rb_yield(Qundef);
|
rb_yield(Qundef);
|
||||||
rb_tracepoint_disable(tpval);
|
rb_tracepoint_disable(tpval);
|
||||||
|
|
||||||
rb_ary_push(result, SIZET2NUM(newobj_count));
|
rb_ary_push(result, SIZET2NUM(track.newobj_count));
|
||||||
rb_ary_push(result, SIZET2NUM(free_count));
|
rb_ary_push(result, SIZET2NUM(track.free_count));
|
||||||
rb_ary_push(result, SIZET2NUM(gc_start_count));
|
rb_ary_push(result, SIZET2NUM(track.gc_start_count));
|
||||||
rb_ary_push(result, SIZET2NUM(gc_end_count));
|
rb_ary_push(result, SIZET2NUM(track.gc_end_count));
|
||||||
for (i=0; i<objects_count; i++) {
|
rb_ary_cat(result, track.objects, track.objects_count);
|
||||||
rb_ary_push(result, objects[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -69,10 +72,6 @@ tracepoint_track_objspace_events(VALUE self)
|
||||||
void
|
void
|
||||||
Init_tracepoint(void)
|
Init_tracepoint(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
VALUE mBug = rb_define_module("Bug");
|
VALUE mBug = rb_define_module("Bug");
|
||||||
rb_define_module_function(mBug, "tracepoint_track_objspace_events", tracepoint_track_objspace_events, 0);
|
rb_define_module_function(mBug, "tracepoint_track_objspace_events", tracepoint_track_objspace_events, 0);
|
||||||
for (i=0; i<sizeof(objects)/sizeof(VALUE); i++) {
|
|
||||||
rb_global_variable(objects+i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue