| 1 |
#include "ruby/ruby.h" |
| 2 |
#include "ruby/debug.h" |
| 3 |
|
| 4 |
#define MAX_BUF_SIZE 0x100 |
| 5 |
|
| 6 |
static VALUE |
| 7 |
profile_frames(VALUE self, VALUE start_v, VALUE num_v) |
| 8 |
{ |
| 9 |
int i, collected_size; |
| 10 |
int start = NUM2INT(start_v); |
| 11 |
int buff_size = NUM2INT(num_v); |
| 12 |
VALUE buff[MAX_BUF_SIZE]; |
| 13 |
int lines[MAX_BUF_SIZE]; |
| 14 |
VALUE result = rb_ary_new(); |
| 15 |
|
| 16 |
if (buff_size > MAX_BUF_SIZE) rb_raise(rb_eRuntimeError, "too long buff_size"); |
| 17 |
|
| 18 |
collected_size = rb_profile_frames(start, buff_size, buff, lines); |
| 19 |
|
| 20 |
for (i=0; i<collected_size; i++) { |
| 21 |
VALUE ary = rb_ary_new(); |
| 22 |
rb_ary_push(ary, rb_profile_frame_path(buff[i])); |
| 23 |
rb_ary_push(ary, rb_profile_frame_absolute_path(buff[i])); |
| 24 |
rb_ary_push(ary, rb_profile_frame_label(buff[i])); |
| 25 |
rb_ary_push(ary, rb_profile_frame_base_label(buff[i])); |
| 26 |
rb_ary_push(ary, rb_profile_frame_full_label(buff[i])); |
| 27 |
rb_ary_push(ary, rb_profile_frame_first_lineno(buff[i])); |
| 28 |
rb_ary_push(ary, rb_profile_frame_classpath(buff[i])); |
| 29 |
rb_ary_push(ary, rb_profile_frame_singleton_method_p(buff[i])); |
| 30 |
rb_ary_push(ary, rb_profile_frame_method_name(buff[i])); |
| 31 |
rb_ary_push(ary, rb_profile_frame_qualified_method_name(buff[i])); |
| 32 |
rb_ary_push(ary, INT2NUM(lines[i])); |
| 33 |
|
| 34 |
rb_ary_push(result, ary); |
| 35 |
} |
| 36 |
|
| 37 |
return result; |
| 38 |
} |
| 39 |
|
| 40 |
static VALUE |
| 41 |
profile_thread_frames(VALUE self, VALUE thread, VALUE start_v, VALUE num_v) |
| 42 |
{ |
| 43 |
int i, collected_size; |
| 44 |
int start = NUM2INT(start_v); |
| 45 |
int buff_size = NUM2INT(num_v); |
| 46 |
VALUE buff[MAX_BUF_SIZE]; |
| 47 |
int lines[MAX_BUF_SIZE]; |
| 48 |
VALUE result = rb_ary_new(); |
| 49 |
|
| 50 |
if (buff_size > MAX_BUF_SIZE) rb_raise(rb_eRuntimeError, "too long buff_size"); |
| 51 |
|
| 52 |
collected_size = rb_profile_thread_frames(thread, start, buff_size, buff, lines); |
| 53 |
for (i=0; i<collected_size; i++) { |
| 54 |
rb_ary_push(result, rb_profile_frame_full_label(buff[i])); |
| 55 |
} |
| 56 |
|
| 57 |
return result; |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
Init_profile_frames(VALUE klass) |
| 62 |
{ |
| 63 |
rb_define_module_function(klass, "profile_frames", profile_frames, 2); |
| 64 |
rb_define_module_function(klass, "profile_thread_frames", profile_thread_frames, 3); |
| 65 |
} |