Skip to content
This repository

Fix for Ruby 2.0.0 #56

Merged
merged 2 commits into from about 1 year ago

2 participants

Christian Neukirchen Aman Gupta
Christian Neukirchen

First try on fixing #55; this has not been tested yet very much, but the arithmetic example works.

Needs review from someone more versed in Ruby internals.

Aman Gupta
Owner
tmm1 commented April 08, 2013

Thanks.

Aman Gupta tmm1 merged commit 73e7b26 into from April 08, 2013
Aman Gupta tmm1 closed this April 08, 2013
Christian Neukirchen

I noticed a lockup related to a memory-heavy Ruby program, but I don't know how to debug it yet.

Aman Gupta
Owner
tmm1 commented April 09, 2013

Unfortunately perftools.rb's design makes it pretty unstable. The profiling signals sometimes come when the VM is inconsistent.

Ruby 2.0 actually makes call stack profiling a lot easier. You can even do it all in ruby with caller_locations. See http://samsaffron.com/archive/2013/03/19/flame-graphs-in-ruby-miniprofiler

You might also be interested in https://github.com/tmm1/rblineprof which is much better tested and more stable on 1.9 and 2.0.

Christian Neukirchen

Concretely, the program hangs with:

rt_sigreturn()                          = 56
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f34ffa599d0) = ? ERESTARTNOINTR (To be restarted)
--- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL} ---
rt_sigreturn()                          = 56
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f34ffa599d0) = ? ERESTARTNOINTR (To be restarted)
--- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL} ---
rt_sigreturn()                          = 56
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f34ffa599d0) = ? ERESTARTNOINTR (To be restarted)
--- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL} ---
rt_sigreturn()                          = 56
#0  0x00007f34ff125c85 in fork () from /usr/lib/libc.so.6
#1  0x00007f34ff4ebe5c in ?? () from /usr/lib/libruby.so.2.0
#2  0x00007f34ff4f080e in ?? () from /usr/lib/libruby.so.2.0
#3  0x00007f34ff4f0f88 in rb_fork_async_signal_safe ()
   from /usr/lib/libruby.so.2.0
#4  0x00007f34ff4a99f8 in ?? () from /usr/lib/libruby.so.2.0

I am mainly interested in the pprof call graphs however...

Christian Neukirchen chneukirchen deleted the branch April 09, 2013
Aman Gupta
Owner
tmm1 commented April 09, 2013

Ah, yes. You're hitting #20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 18 additions and 4 deletions. Show diff stats Hide diff stats

  1. 22  ext/perftools.c
22  ext/perftools.c
@@ -23,6 +23,10 @@ static VALUE Iallocate;
23 23
 static VALUE I__send__;
24 24
 static VALUE Isend;
25 25
 
  26
+#ifndef ID_ALLOCATOR
  27
+#define ID_ALLOCATOR Iallocate
  28
+#endif
  29
+
26 30
 #define SAVE_FRAME() \
27 31
   if (method && method != I__send__ && method != Isend) { \
28 32
     if (self && FL_TEST(klass, FL_SINGLETON) && (BUILTIN_TYPE(self) == T_CLASS || BUILTIN_TYPE(self) == T_MODULE)) \
@@ -125,15 +129,25 @@ static VALUE Isend;
125 129
   #include <vm_core.h>
126 130
   #include <iseq.h>
127 131
 
128  
-// Fix compile error in ruby 1.9.3
  132
+// Fix compile error in ruby 1.9.3 and 2.0.0
129 133
 #ifdef RTYPEDDATA_DATA
130  
-#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
  134
+  #if GET_THREAD
  135
+    #define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
  136
+    #define GET_THREAD2 GET_THREAD
  137
+  #else
  138
+    rb_thread_t *ruby_current_thread;
  139
+    rb_thread_t *GET_THREAD2(void)
  140
+    {
  141
+      ruby_current_thread = ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()));
  142
+      return GET_THREAD();
  143
+    }
  144
+  #endif 
131 145
 #endif
132 146
 
133 147
   int
134 148
   rb_stack_trace(void** result, int max_depth)
135 149
   {
136  
-    rb_thread_t *th = GET_THREAD();
  150
+    rb_thread_t *th = GET_THREAD2();
137 151
     rb_control_frame_t *cfp = th->cfp;
138 152
     rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
139 153
 
@@ -190,7 +204,7 @@ static VALUE Isend;
190 204
   void
191 205
   rb_dump_stack()
192 206
   {
193  
-    rb_thread_t *th = GET_THREAD();
  207
+    rb_thread_t *th = GET_THREAD2();
194 208
     rb_control_frame_t *cfp = th->cfp;
195 209
     rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
196 210
     ID func;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.