void Metrics::run(STATE) { timer_->set(interval_); while(!thread_exit_) { if(timer_->wait_for_tick() < 0) { logger::error("metrics: error waiting for timer, exiting thread"); break; } if(thread_exit_) break; metrics_collection_.init(); ThreadList* threads = state->shared().threads(); for(ThreadList::iterator i = threads->begin(); i != threads->end(); ++i) { if(VM* vm = (*i)->as_vm()) { metrics_collection_.add(vm->metrics()); } } #ifdef ENABLE_LLVM if(LLVMState* llvm_state = state->shared().llvm_state) { metrics_collection_.add(llvm_state->metrics()); } #endif { utilities::thread::Mutex::LockGuard guard(metrics_lock_); metrics_collection_.add(metrics_history_); } update_ruby_values(state); if(emitter_) emitter_->send_metrics(); } timer_->clear(); }
void Metrics::process_metrics(STATE) { GCTokenImpl gct; RBX_DTRACE_CONST char* thread_name = const_cast<RBX_DTRACE_CONST char*>("rbx.metrics"); vm_->set_name(thread_name); RUBINIUS_THREAD_START(const_cast<RBX_DTRACE_CONST char*>(thread_name), state->vm()->thread_id(), 1); state->vm()->thread->hard_unlock(state, gct, 0); state->gc_dependent(gct, 0); timer_->set(interval_); while(!thread_exit_) { { GCIndependent guard(state, 0); if(timer_->wait_for_tick() < 0) { logger::error("metrics: error waiting for timer, exiting thread"); break; } } if(thread_exit_) break; { utilities::thread::Mutex::LockGuard guard(metrics_lock_); metrics_collection_.init(); ThreadList* threads = state->shared().threads(); for(ThreadList::iterator i = threads->begin(); i != threads->end(); ++i) { if(VM* vm = (*i)->as_vm()) { if(MetricsData* data = vm->metrics()) { metrics_collection_.add(data); } } } #ifdef ENABLE_LLVM if(state->shared().llvm_state) { if(VM* vm = state->shared().llvm_state->vm()) { metrics_collection_.add(vm->metrics()); } } #endif metrics_collection_.add(&metrics_history_); update_ruby_values(state); } { GCIndependent guard(state, 0); if(emitter_) emitter_->send_metrics(); } } timer_->clear(); RUBINIUS_THREAD_STOP(const_cast<RBX_DTRACE_CONST char*>(thread_name), state->vm()->thread_id(), 1); }