mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* yarvcore.h: remove rb_control_frame_t#callee_id.
* vm_macro.def: ditto. * eval_intern.h (exec_event_hooks): fix to check event flags * eval_intern.h (EXEC_EVENT_HOOK): fix to re-check event flags. * ext/probeprofiler : added. this profiler is sampling based profiler. * vm.c: add rb_thread_current_status() API for probeprofiler. * thread.c (rb_thread_execute_interrupts): add comments. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
354844be45
commit
abcbd7ea38
10 changed files with 199 additions and 35 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
||||||
|
Wed Apr 25 12:42:40 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* yarvcore.h: remove rb_control_frame_t#callee_id.
|
||||||
|
|
||||||
|
* vm_macro.def: ditto.
|
||||||
|
|
||||||
|
* eval_intern.h (exec_event_hooks): fix to check event flags
|
||||||
|
|
||||||
|
* eval_intern.h (EXEC_EVENT_HOOK): fix to re-check event flags.
|
||||||
|
|
||||||
|
* ext/probeprofiler : added. this profiler is sampling based
|
||||||
|
profiler.
|
||||||
|
|
||||||
|
* vm.c: add rb_thread_current_status() API for probeprofiler.
|
||||||
|
|
||||||
|
* thread.c (rb_thread_execute_interrupts): add comments.
|
||||||
|
|
||||||
Wed Apr 25 10:36:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Apr 25 10:36:03 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval_intern.h (PUSH_TAG): no argument now.
|
* eval_intern.h (PUSH_TAG): no argument now.
|
||||||
|
|
|
@ -234,7 +234,9 @@ static void inline
|
||||||
exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
|
exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
|
||||||
{
|
{
|
||||||
while (hook) {
|
while (hook) {
|
||||||
(*hook->func)(flag, hook->data, self, id, klass);
|
if (flag & hook->flag) {
|
||||||
|
(*hook->func)(flag, hook->data, self, id, klass);
|
||||||
|
}
|
||||||
hook = hook->next;
|
hook = hook->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,13 +244,15 @@ exec_event_hooks(rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id,
|
||||||
#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
|
#define EXEC_EVENT_HOOK(th, flag, self, id, klass) do { \
|
||||||
rb_event_flag_t wait_event__ = th->event_flags; \
|
rb_event_flag_t wait_event__ = th->event_flags; \
|
||||||
if (UNLIKELY(wait_event__)) { \
|
if (UNLIKELY(wait_event__)) { \
|
||||||
VALUE self__ = (self), klass__ = (klass); \
|
if (wait_event__ & (flag | RUBY_EVENT_VM)) { \
|
||||||
ID id__ = (id); \
|
VALUE self__ = (self), klass__ = (klass); \
|
||||||
if (wait_event__ & flag) { \
|
ID id__ = (id); \
|
||||||
exec_event_hooks(th->event_hooks, flag, self__, id__, klass__); \
|
if (wait_event__ & flag) { \
|
||||||
} \
|
exec_event_hooks(th->event_hooks, flag, self__, id__, klass__); \
|
||||||
if (wait_event__ & RUBY_EVENT_VM) { \
|
} \
|
||||||
exec_event_hooks(th->vm->event_hooks, flag, self__, id__, klass__); \
|
if (wait_event__ & RUBY_EVENT_VM) { \
|
||||||
|
exec_event_hooks(th->vm->event_hooks, flag, self__, id__, klass__); \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
2
ext/probeprofiler/extconf.rb
Normal file
2
ext/probeprofiler/extconf.rb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
require 'mkmf'
|
||||||
|
create_makefile("probeprofiler")
|
7
ext/probeprofiler/lib/probeprofile.rb
Normal file
7
ext/probeprofiler/lib/probeprofile.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'probeprofiler'
|
||||||
|
END{
|
||||||
|
ProbeProfiler.stop_profile
|
||||||
|
ProbeProfiler.print_profile
|
||||||
|
}
|
||||||
|
|
||||||
|
ProbeProfiler.start_profile
|
14
ext/probeprofiler/lib/probeprofiler.rb
Normal file
14
ext/probeprofiler/lib/probeprofiler.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
|
||||||
|
require 'probeprofiler.so'
|
||||||
|
|
||||||
|
def ProbeProfiler.print_profile
|
||||||
|
data = ProbeProfiler.profile_data
|
||||||
|
total = 0.0
|
||||||
|
printf("%-60s %-8s %-7s\n", "ProbeProfile Result: Method signature", "count", "ratio")
|
||||||
|
data.map{|k, n| total += n; [n, k]}.sort.reverse.each{|n, sig|
|
||||||
|
#
|
||||||
|
printf("%-60s %8d %7.2f%%\n", sig, n, 100 * n / total)
|
||||||
|
}
|
||||||
|
printf("%60s %8d\n", "total:", total)
|
||||||
|
end
|
||||||
|
|
63
ext/probeprofiler/probeprofiler.c
Normal file
63
ext/probeprofiler/probeprofiler.c
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include <ruby.h>
|
||||||
|
#include <yarvcore.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
hash_inc(VALUE data, VALUE key)
|
||||||
|
{
|
||||||
|
VALUE num = INT2FIX(0);
|
||||||
|
|
||||||
|
if (num = rb_hash_aref(data, key)) {
|
||||||
|
num = INT2FIX(FIX2INT(num) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_hash_aset(data, key, num);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
pprof_hook(rb_event_flag_t flag, VALUE data,
|
||||||
|
VALUE dmyid, VALUE dmyklass)
|
||||||
|
{
|
||||||
|
rb_thread_t *th = GET_THREAD();
|
||||||
|
VALUE sig = rb_thread_current_sig(th);
|
||||||
|
hash_inc(data, sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pprof_data(VALUE mod)
|
||||||
|
{
|
||||||
|
rb_const_get_at(mod, rb_intern("#pprof_data"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pprof_start(VALUE self)
|
||||||
|
{
|
||||||
|
VALUE data = pprof_data(self);
|
||||||
|
rb_add_event_hook(pprof_hook, RUBY_EVENT_SWITCH, data);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
pprof_stop(VALUE self)
|
||||||
|
{
|
||||||
|
rb_remove_event_hook(pprof_hook);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
hash_to_ary_i(VALUE key, VALUE value, VALUE ary)
|
||||||
|
{
|
||||||
|
rb_ary_push(ary, rb_ary_new3(2, value, key));
|
||||||
|
return ST_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Init_probeprofiler(void)
|
||||||
|
{
|
||||||
|
VALUE mPProf;
|
||||||
|
|
||||||
|
mPProf = rb_define_module("ProbeProfiler");
|
||||||
|
rb_const_set(mPProf, rb_intern("#pprof_data"), rb_hash_new());
|
||||||
|
rb_define_module_function(mPProf, "start_profile", pprof_start, 0);
|
||||||
|
rb_define_module_function(mPProf, "stop_profile", pprof_stop, 0);
|
||||||
|
rb_define_module_function(mPProf, "profile_data", pprof_data, 0);
|
||||||
|
}
|
||||||
|
|
17
thread.c
17
thread.c
|
@ -717,6 +717,7 @@ rb_thread_execute_interrupts(rb_thread_t *th)
|
||||||
/* thread pass */
|
/* thread pass */
|
||||||
rb_thread_schedule();
|
rb_thread_schedule();
|
||||||
}
|
}
|
||||||
|
EXEC_EVENT_HOOK(th, RUBY_EVENT_SWITCH, th->cfp->self, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1836,14 +1837,28 @@ static void
|
||||||
timer_thread_function(void)
|
timer_thread_function(void)
|
||||||
{
|
{
|
||||||
rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */
|
rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */
|
||||||
|
|
||||||
|
/* for time slice */
|
||||||
vm->running_thread->interrupt_flag = 1;
|
vm->running_thread->interrupt_flag = 1;
|
||||||
|
|
||||||
|
/* check signal */
|
||||||
if (vm->bufferd_signal_size && vm->main_thread->exec_signal == 0) {
|
if (vm->bufferd_signal_size && vm->main_thread->exec_signal == 0) {
|
||||||
vm->main_thread->exec_signal = rb_get_next_signal(vm);
|
vm->main_thread->exec_signal = rb_get_next_signal(vm);
|
||||||
thread_debug("bufferd_signal_size: %d, sig: %d\n",
|
thread_debug("bufferd_signal_size: %d, sig: %d\n",
|
||||||
vm->bufferd_signal_size, vm->main_thread->exec_signal);
|
vm->bufferd_signal_size, vm->main_thread->exec_signal);
|
||||||
rb_thread_interrupt(vm->main_thread);
|
rb_thread_interrupt(vm->main_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* prove profiler */
|
||||||
|
if (vm->prove_profile.enable) {
|
||||||
|
rb_thread_t *th = vm->running_thread;
|
||||||
|
|
||||||
|
if (vm->during_gc) {
|
||||||
|
/* GC prove profiling */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
53
vm.c
53
vm.c
|
@ -106,7 +106,7 @@ push_frame(rb_thread_t *th, rb_iseq_t *iseq, VALUE magic,
|
||||||
cfp->dfp = dfp;
|
cfp->dfp = dfp;
|
||||||
cfp->proc = 0;
|
cfp->proc = 0;
|
||||||
cfp->method_id = 0;
|
cfp->method_id = 0;
|
||||||
cfp->callee_id = 0;
|
cfp->method_klass = 0;
|
||||||
|
|
||||||
#define COLLECT_PROFILE 0
|
#define COLLECT_PROFILE 0
|
||||||
#if COLLECT_PROFILE
|
#if COLLECT_PROFILE
|
||||||
|
@ -541,7 +541,6 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv,
|
||||||
push_frame(th, 0, FRAME_MAGIC_CFUNC,
|
push_frame(th, 0, FRAME_MAGIC_CFUNC,
|
||||||
recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
|
recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
|
||||||
|
|
||||||
cfp->callee_id = oid;
|
|
||||||
cfp->method_id = id;
|
cfp->method_id = id;
|
||||||
cfp->method_klass = klass;
|
cfp->method_klass = klass;
|
||||||
|
|
||||||
|
@ -983,11 +982,10 @@ th_backtrace_each(rb_thread_t *th,
|
||||||
rb_ary_push(ary, str);
|
rb_ary_push(ary, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (cfp->callee_id) {
|
else if (cfp->method_id) {
|
||||||
str = rb_sprintf("%s:%d:in `%s'",
|
str = rb_sprintf("%s:%d:in `%s'",
|
||||||
file, line_no,
|
file, line_no,
|
||||||
/* TODO: method_id? callee_id? */
|
rb_id2name(cfp->method_id));
|
||||||
rb_id2name(cfp->callee_id));
|
|
||||||
rb_ary_push(ary, str);
|
rb_ary_push(ary, str);
|
||||||
}
|
}
|
||||||
cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp);
|
cfp = RUBY_VM_NEXT_CONTROL_FRAME(cfp);
|
||||||
|
@ -1807,3 +1805,48 @@ rb_thread_eval(rb_thread_t *th, VALUE iseqval)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_thread_method_id_and_klass(rb_thread_t *th, ID *idp, VALUE *klassp)
|
||||||
|
{
|
||||||
|
rb_control_frame_t *cfp = th->cfp;
|
||||||
|
|
||||||
|
if (cfp->iseq) {
|
||||||
|
if (cfp->pc != 0) {
|
||||||
|
rb_iseq_t *iseq = cfp->iseq->local_iseq;
|
||||||
|
if (idp) *idp = rb_intern(RSTRING_PTR(iseq->name));
|
||||||
|
if (klassp) *klassp = iseq->klass;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (idp) *idp = cfp->method_id;
|
||||||
|
if (klassp) *klassp = cfp->method_klass;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
*idp = *klassp = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_thread_current_status(rb_thread_t *th)
|
||||||
|
{
|
||||||
|
rb_control_frame_t *cfp = th->cfp;
|
||||||
|
VALUE str = Qnil;
|
||||||
|
|
||||||
|
if (cfp->iseq != 0) {
|
||||||
|
if (cfp->pc != 0) {
|
||||||
|
rb_iseq_t *iseq = cfp->iseq;
|
||||||
|
int line_no = th_get_sourceline(cfp);
|
||||||
|
char *file = RSTRING_PTR(iseq->filename);
|
||||||
|
str = rb_sprintf("%s:%d:in `%s'",
|
||||||
|
file, line_no, RSTRING_PTR(iseq->name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (cfp->method_id) {
|
||||||
|
str = rb_sprintf("`%s#%s' (cfunc)",
|
||||||
|
RSTRING_PTR(rb_class_name(cfp->method_klass)),
|
||||||
|
rb_id2name(cfp->method_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
|
@ -61,7 +61,6 @@ MACRO macro_eval_invoke_cfunc(num, id, recv, klass, mn, blockptr)
|
||||||
rb_control_frame_t *cfp =
|
rb_control_frame_t *cfp =
|
||||||
push_frame(th, 0, FRAME_MAGIC_CFUNC,
|
push_frame(th, 0, FRAME_MAGIC_CFUNC,
|
||||||
recv, (VALUE) blockptr, 0, GET_SP(), 0, 1);
|
recv, (VALUE) blockptr, 0, GET_SP(), 0, 1);
|
||||||
cfp->callee_id = id; /* TODO */
|
|
||||||
cfp->method_id = id;
|
cfp->method_id = id;
|
||||||
cfp->method_klass = klass;
|
cfp->method_klass = klass;
|
||||||
|
|
||||||
|
|
40
yarvcore.h
40
yarvcore.h
|
@ -253,20 +253,20 @@ struct rb_iseq_struct {
|
||||||
void *jit_compiled;
|
void *jit_compiled;
|
||||||
void *iseq_orig;
|
void *iseq_orig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* argument information
|
* argument information
|
||||||
*
|
*
|
||||||
* def m(a1, a2, ..., aM, b1=(...), b2=(...), ..., bN=(...), *c, &d)
|
* def m(a1, a2, ..., aM, b1=(...), b2=(...), ..., bN=(...), *c, &d)
|
||||||
* =>
|
* =>
|
||||||
*
|
*
|
||||||
* argc = M
|
* argc = M
|
||||||
* arg_rest = M+N + 1 // if no rest arguments, rest is 0
|
* arg_rest = M+N + 1 // if no rest arguments, rest is 0
|
||||||
* arg_opts = N
|
* arg_opts = N
|
||||||
* arg_opts_tbl = [ (N entries) ]
|
* arg_opts_tbl = [ (N entries) ]
|
||||||
* arg_block = M+N + 1 (rest) + 1 (block)
|
* arg_block = M+N + 1 (rest) + 1 (block)
|
||||||
* check:
|
* check:
|
||||||
* M <= num
|
* M <= num
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
int arg_simple;
|
int arg_simple;
|
||||||
|
@ -316,6 +316,7 @@ typedef struct rb_iseq_struct rb_iseq_t;
|
||||||
#define RUBY_EVENT_RAISE 0x80
|
#define RUBY_EVENT_RAISE 0x80
|
||||||
#define RUBY_EVENT_ALL 0xff
|
#define RUBY_EVENT_ALL 0xff
|
||||||
#define RUBY_EVENT_VM 0x100
|
#define RUBY_EVENT_VM 0x100
|
||||||
|
#define RUBY_EVENT_SWITCH 0x200
|
||||||
|
|
||||||
typedef unsigned int rb_event_flag_t;
|
typedef unsigned int rb_event_flag_t;
|
||||||
typedef void (*rb_event_hook_func_t)(rb_event_flag_t, VALUE data, VALUE, ID, VALUE klass);
|
typedef void (*rb_event_hook_func_t)(rb_event_flag_t, VALUE data, VALUE, ID, VALUE klass);
|
||||||
|
@ -371,12 +372,10 @@ typedef struct {
|
||||||
VALUE *dfp; /* cfp[7] / block[2] */
|
VALUE *dfp; /* cfp[7] / block[2] */
|
||||||
rb_iseq_t *block_iseq; /* cfp[8] / block[3] */
|
rb_iseq_t *block_iseq; /* cfp[8] / block[3] */
|
||||||
VALUE proc; /* cfp[9] / block[4] */
|
VALUE proc; /* cfp[9] / block[4] */
|
||||||
ID callee_id; /* cfp[10] */
|
ID method_id; /* cfp[10] saved in special case */
|
||||||
ID method_id; /* cfp[11] saved in special case */
|
VALUE method_klass; /* cfp[11] saved in special case */
|
||||||
VALUE method_klass; /* cfp[12] saved in special case */
|
VALUE prof_time_self; /* cfp[12] */
|
||||||
VALUE prof_time_self; /* cfp[13] */
|
VALUE prof_time_chld; /* cfp[13] */
|
||||||
VALUE prof_time_chld; /* cfp[14] */
|
|
||||||
VALUE dummy; /* cfp[15] */
|
|
||||||
} rb_control_frame_t;
|
} rb_control_frame_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -629,6 +628,7 @@ void yarv_bug(void);
|
||||||
VALUE rb_thread_eval(rb_thread_t *th, VALUE iseqval);
|
VALUE rb_thread_eval(rb_thread_t *th, VALUE iseqval);
|
||||||
void rb_enable_interrupt(void);
|
void rb_enable_interrupt(void);
|
||||||
void rb_disable_interrupt(void);
|
void rb_disable_interrupt(void);
|
||||||
|
int rb_thread_method_id_and_klass(rb_thread_t *th, ID *idp, VALUE *klassp);
|
||||||
|
|
||||||
VALUE th_eval_body(rb_thread_t *th);
|
VALUE th_eval_body(rb_thread_t *th);
|
||||||
VALUE th_set_eval_stack(rb_thread_t *, VALUE iseq);
|
VALUE th_set_eval_stack(rb_thread_t *, VALUE iseq);
|
||||||
|
|
Loading…
Reference in a new issue