Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 09e3275

Browse files
committedAug 28, 2015
Improved logging of Thread creation, fork, exec, spawn, backtick.
1 parent 8542e0a commit 09e3275

File tree

6 files changed

+60
-20
lines changed

6 files changed

+60
-20
lines changed
 

Diff for: ‎vm/builtin/system.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,12 @@ namespace rubinius {
467467
sigaction(i, &action, NULL);
468468
}
469469

470-
utilities::logger::write("spawn: %s", exe.command());
470+
CallFrame* call_frame = calling_environment->get(3);
471+
472+
utilities::logger::write("spawn: %s, %s, %s:%d", exe.command(),
473+
state->vm()->name().c_str(),
474+
call_frame->file(state)->cpp_str(state).c_str(),
475+
call_frame->line(state));
471476

472477
if(exe.argc()) {
473478
(void)::execvp(exe.command(), exe.argv());
@@ -586,7 +591,12 @@ namespace rubinius {
586591
sigaction(i, &action, NULL);
587592
}
588593

589-
utilities::logger::write("backtick: %s", exe.command());
594+
CallFrame* call_frame = calling_environment->get(1);
595+
596+
utilities::logger::write("backtick: %s, %s, %s:%d", exe.command(),
597+
state->vm()->name().c_str(),
598+
call_frame->file(state)->cpp_str(state).c_str(),
599+
call_frame->line(state));
590600

591601
exec_sh_fallback(state, exe.command(), exe.command_size());
592602

@@ -696,7 +706,12 @@ namespace rubinius {
696706
old_handlers[i] = (void*)old_action.sa_handler;
697707
}
698708

699-
utilities::logger::write("exec: %s", exe.command());
709+
CallFrame* call_frame = calling_environment->get(3);
710+
711+
utilities::logger::write("exec: %s, %s, %s:%d", exe.command(),
712+
state->vm()->name().c_str(),
713+
call_frame->file(state)->cpp_str(state).c_str(),
714+
call_frame->line(state));
700715

701716
if(exe.argc()) {
702717
(void)::execvp(exe.command(), exe.argv());
@@ -821,7 +836,13 @@ namespace rubinius {
821836

822837
if(pid > 0) {
823838
state->shared().internal_threads()->after_fork_parent(state);
824-
utilities::logger::write("fork: child: %d", pid);
839+
840+
CallFrame* call_frame = calling_environment->get(2);
841+
842+
utilities::logger::write("fork: child: %d, %s, %s:%d", pid,
843+
state->vm()->name().c_str(),
844+
call_frame->file(state)->cpp_str(state).c_str(),
845+
call_frame->line(state));
825846
}
826847
}
827848

Diff for: ‎vm/builtin/thread.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,17 @@ namespace rubinius {
104104
return state->vm()->thread.get()->send(state, NULL, state->symbol("__run__"));
105105
}
106106

107-
Thread* Thread::allocate(STATE, Object* self) {
108-
return Thread::create(state, self, send_run);
107+
Thread* Thread::allocate(STATE, Object* self, CallFrame* calling_environment) {
108+
Thread* thread = Thread::create(state, self, send_run);
109+
110+
CallFrame* call_frame = calling_environment->get(1);
111+
112+
utilities::logger::write("create thread: %s, %s:%d",
113+
thread->vm()->name().c_str(),
114+
call_frame->file(state)->cpp_str(state).c_str(),
115+
call_frame->line(state));
116+
117+
return thread;
109118
}
110119

111120
Thread* Thread::current(STATE) {
@@ -323,18 +332,17 @@ namespace rubinius {
323332
RUBINIUS_THREAD_START(
324333
const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 0);
325334

326-
if(cDebugThreading) {
327-
utilities::logger::debug("Thread: start thread: id: %d, pthread: %d",
328-
vm->thread_id(), (unsigned int)thread_debug_self());
329-
}
335+
vm->thread->pid(state, Fixnum::from(gettid()));
336+
337+
utilities::logger::write("start thread: %s, %d, %#x",
338+
vm->name().c_str(), vm->thread->pid()->to_native(),
339+
(unsigned int)thread_debug_self());
330340

331341
int stack_address = 0;
332342
vm->set_root_stack(reinterpret_cast<uintptr_t>(&stack_address), THREAD_STACK_SIZE);
333343

334344
NativeMethod::init_thread(state);
335345

336-
vm->thread->pid(state, Fixnum::from(gettid()));
337-
338346
// Lock the thread object and unlock it at __run__ in the ruby land.
339347
vm->thread->alive(state, cTrue);
340348
vm->thread->init_lock_.unlock();
@@ -369,18 +377,16 @@ namespace rubinius {
369377

370378
NativeMethod::cleanup_thread(state);
371379

372-
if(cDebugThreading) {
373-
utilities::logger::debug("Thread: exit thread: id: %d", vm->thread_id());
374-
}
380+
utilities::logger::write("exit thread: %s", vm->name().c_str());
375381

376382
vm->become_unmanaged();
377383

378384
if(vm->main_thread_p() || (!ret && vm->thread_state()->raise_reason() == cExit)) {
379385
state->shared().signals()->system_exit(vm->thread_state()->raise_value());
380-
} else {
381-
vm->set_zombie(state);
382386
}
383387

388+
vm->set_zombie(state);
389+
384390
RUBINIUS_THREAD_STOP(
385391
const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 0);
386392

Diff for: ‎vm/builtin/thread.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace rubinius {
118118
* @see kernel/bootstrap/thread.rb
119119
*/
120120
// Rubinius.primitive :thread_allocate
121-
static Thread* allocate(STATE, Object* self);
121+
static Thread* allocate(STATE, Object* self, CallFrame* calling_environment);
122122

123123
/**
124124
* Returns the Thread object for the state.

Diff for: ‎vm/call_frame.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ namespace rubinius {
6161
Object* stk[0];
6262

6363
// ACCESS
64+
CallFrame* get(int frame) {
65+
CallFrame* call_frame = this;
66+
67+
for(int i = 0; i < frame; i++) {
68+
if(CallFrame* cf = call_frame->previous) {
69+
call_frame = cf;
70+
} else {
71+
break;
72+
}
73+
}
74+
75+
return call_frame;
76+
}
6477

6578
int ip() const {
6679
return ip_;

Diff for: ‎vm/environment.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace rubinius {
105105

106106
check_io_descriptors();
107107

108-
root_vm = shared->thread_nexus()->new_vm(shared, "rbx.ruby.main");
108+
root_vm = shared->thread_nexus()->new_vm(shared, "ruby.main");
109109
root_vm->set_main_thread();
110110
shared->set_root_vm(root_vm);
111111

Diff for: ‎vm/gc/managed.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace rubinius {
2323
name_ = std::string(name);
2424
} else {
2525
std::ostringstream thread_name;
26-
thread_name << "rbx.ruby." << id_;
26+
thread_name << "ruby." << id_;
2727
name_ = thread_name.str();
2828
}
2929
}

0 commit comments

Comments
 (0)
Please sign in to comment.