Class: RubyRunNative__
Class Method Summary collapse
-
.get_all_top_stacks ⇒ Object
This c routine implements RubyRunNative__.get_all_top_stacks (static method).
Class Method Details
.get_all_top_stacks ⇒ Object
This c routine implements RubyRunNative__.get_all_top_stacks (static method). For each thread in the space, it calls call_stack to simulate a Ruby caller invocation.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'ext/rubyrunnative__.c', line 108
VALUE c_getAllThreadTopStacks(VALUE self)
{
VALUE all_top_stack_trace;
VALUE currThreadID;
rb_thread_t thrObj, currThreadObj;
/*
We start with the current thread, whatever it is (likely main),
and use the macro to locate its structure (rb_thread_current only
returns the thread ID)
*/
currThreadID = rb_thread_current();
Data_Get_Struct(currThreadID, struct rb_thread, currThreadObj);
/*
Final result is a hash where the key is the thread ID and value
an array of stack trace entries.
*/
all_top_stack_trace = rb_hash_new();
/*
Starts the loop without the dump thread itself.
Thread structs are double linked list in Ruby. We can start from any one
and chain through the rest of them.
*/
thrObj = currThreadObj;
for ( ;thrObj ;thrObj = thrObj->next) {
/* printf("Ruby thread id = %x\n", thrObj->thread); */
if(thrObj != NULL) {
rb_hash_aset(all_top_stack_trace, thrObj->thread, getTopThreadStack(thrObj));
}
// If we reached the start point, break.
// Note: Threads are double linked objects
if (thrObj->next == currThreadObj) break;
}
return all_top_stack_trace;
}
|