diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-04-25 03:50:00 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-04-25 03:50:00 +0000 |
commit | abcbd7ea38f64f942a934ba065aabf9da81a21bc (patch) | |
tree | 8bf33e560f4c99904d36a1f0681bf5c2ebd34dae /ext/probeprofiler/probeprofiler.c | |
parent | 354844be45efe799031b1a9799e8c6d52cc6b16d (diff) |
* 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
Diffstat (limited to 'ext/probeprofiler/probeprofiler.c')
-rw-r--r-- | ext/probeprofiler/probeprofiler.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ext/probeprofiler/probeprofiler.c b/ext/probeprofiler/probeprofiler.c new file mode 100644 index 0000000000..9d67160bc4 --- /dev/null +++ b/ext/probeprofiler/probeprofiler.c @@ -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);
+}
+
|