void apm_driver_mysql_process_stats(TSRMLS_D) { APM_DEBUG("[MySQL driver] ======apm_driver_mysql_process_stats \n"); char *sql = NULL; MYSQL *connection; apm_driver_mysql_insert_request(TSRMLS_C); MYSQL_INSTANCE_INIT sql = emalloc(170); sprintf( sql, "INSERT INTO stats (request_id, duration, user_cpu, sys_cpu, mem_peak_usage) VALUES (@request_id, %f, %f, %f, %ld)", USEC_TO_SEC(APM_G(duration)), USEC_TO_SEC(APM_G(user_cpu)), USEC_TO_SEC(APM_G(sys_cpu)), APM_G(mem_peak_usage) ); APM_DEBUG("[MySQL driver] Sending: %s\n", sql); if (mysql_query(connection, sql) != 0) APM_DEBUG("[MySQL driver] Error: %s\n", mysql_error(APM_G(mysql_event_db))); efree(sql); }
void ScriptDebuggerLocal::profiling_end() { int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&pinfo[ofs], pinfo.size() - ofs); } SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; sort.sort(pinfo.ptr(), ofs); uint64_t total_us = 0; for (int i = 0; i < ofs; i++) { total_us += pinfo[i].self_time; } float total_time = total_us / 1000000.0; for (int i = 0; i < ofs; i++) { print_line(itos(i) + ":" + pinfo[i].signature); float tt = USEC_TO_SEC(pinfo[i].total_time); float st = USEC_TO_SEC(pinfo[i].self_time); print_line("\ttotal_ms: " + rtos(tt) + "\tself_ms: " + rtos(st) + "total%: " + itos(tt * 100 / total_time) + "\tself%: " + itos(st * 100 / total_time) + "\tcalls: " + itos(pinfo[i].call_count)); } for (int i = 0; i < ScriptServer::get_language_count(); i++) { ScriptServer::get_language(i)->profiling_stop(); } profiling = false; }
static double _get_elapsed_secs(struct timeval *t1, struct timeval *t2) { if( !t1 || !t2 ) return -1.0f; return (((double)t2->tv_sec) + USEC_TO_SEC(t2->tv_usec)) - (((double)t1->tv_sec) + USEC_TO_SEC(t1->tv_usec)); }
void PhysicsServerSW::flush_queries() { #ifndef _3D_DISABLED if (!active) return; doing_sync = true; flushing_queries = true; uint64_t time_beg = OS::get_singleton()->get_ticks_usec(); for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) { SpaceSW *space = (SpaceSW *)E->get(); space->call_queries(); } flushing_queries = false; if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) { uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX]; static const char *time_name[SpaceSW::ELAPSED_TIME_MAX] = { "integrate_forces", "generate_islands", "setup_constraints", "solve_constraints", "integrate_velocities" }; for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) { total_time[i] = 0; } for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) { for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) { total_time[i] += E->get()->get_elapsed_time(SpaceSW::ElapsedTime(i)); } } Array values; values.resize(SpaceSW::ELAPSED_TIME_MAX * 2); for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) { values[i * 2 + 0] = time_name[i]; values[i * 2 + 1] = USEC_TO_SEC(total_time[i]); } values.push_back("flush_queries"); values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec() - time_beg)); ScriptDebugger::get_singleton()->add_profiling_frame_data("physics", values); } #endif };
// Similar to cv_wait(), except that it returns -1 without the condition // being signaled after the timeout time has been reached. // // timeout A time, in absolute ticks since boot, when cv_timedwait() // should return. clock_t cv_timedwait(kcondvar_t * cv, kmutex_t * m, clock_t timeout) { struct timespec abstime; // All the callers of cv_timedwait calculate the timeout by adding // ticks to ddi_get_lbolt(), which is in usec. abstime.tv_sec = USEC_TO_SEC(timeout); abstime.tv_nsec = USEC_TO_NSEC(timeout - SEC_TO_USEC(abstime.tv_sec)); int error = pthread_cond_timedwait(&cv->cond, &m->mutex, &abstime); switch (error) { case 0: // Update the mutex holder since we now own the lock. m->holder = pthread_to_kthread(pthread_self()); // Return >0 on signalled wakeup. return 1; case ETIMEDOUT: // Update the mutex holder since we now own the lock. m->holder = pthread_to_kthread(pthread_self()); // Return -1 on timeout. return -1; default: // And this only happens on a programmer error. panic("pthread_cond_timedwait() failed: %s (%d)", strerror(error), error); } }
void ScriptDebuggerLocal::idle_poll() { if (!profiling) return; uint64_t diff = OS::get_singleton()->get_ticks_usec() - idle_accum; if (diff < 1000000) //show every one second return; idle_accum = OS::get_singleton()->get_ticks_usec(); int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&pinfo[ofs], pinfo.size() - ofs); } SortArray<ScriptLanguage::ProfilingInfo, _ScriptDebuggerLocalProfileInfoSort> sort; sort.sort(pinfo.ptr(), ofs); //falta el frame time uint64_t script_time_us = 0; for (int i = 0; i < ofs; i++) { script_time_us += pinfo[i].self_time; } float script_time = USEC_TO_SEC(script_time_us); float total_time = frame_time; //print script total print_line("FRAME: total: " + rtos(frame_time) + " script: " + rtos(script_time) + "/" + itos(script_time * 100 / total_time) + " %"); for (int i = 0; i < ofs; i++) { print_line(itos(i) + ":" + pinfo[i].signature); float tt = USEC_TO_SEC(pinfo[i].total_time); float st = USEC_TO_SEC(pinfo[i].self_time); print_line("\ttotal: " + rtos(tt) + "/" + itos(tt * 100 / total_time) + " % \tself: " + rtos(st) + "/" + itos(st * 100 / total_time) + " % tcalls: " + itos(pinfo[i].call_count)); } }
void ScriptDebuggerRemote::_send_profiling_data(bool p_for_frame) { int ofs = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { if (p_for_frame) ofs += ScriptServer::get_language(i)->profiling_get_frame_data(&profile_info[ofs], profile_info.size() - ofs); else ofs += ScriptServer::get_language(i)->profiling_get_accumulated_data(&profile_info[ofs], profile_info.size() - ofs); } for (int i = 0; i < ofs; i++) { profile_info_ptrs[i] = &profile_info[i]; } SortArray<ScriptLanguage::ProfilingInfo *, ProfileInfoSort> sa; sa.sort(profile_info_ptrs.ptr(), ofs); int to_send = MIN(ofs, max_frame_functions); //check signatures first uint64_t total_script_time = 0; for (int i = 0; i < to_send; i++) { if (!profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) { int idx = profiler_function_signature_map.size(); packet_peer_stream->put_var("profile_sig"); packet_peer_stream->put_var(2); packet_peer_stream->put_var(profile_info_ptrs[i]->signature); packet_peer_stream->put_var(idx); profiler_function_signature_map[profile_info_ptrs[i]->signature] = idx; } total_script_time += profile_info_ptrs[i]->self_time; } //send frames then if (p_for_frame) { packet_peer_stream->put_var("profile_frame"); packet_peer_stream->put_var(8 + profile_frame_data.size() * 2 + to_send * 4); } else { packet_peer_stream->put_var("profile_total"); packet_peer_stream->put_var(8 + to_send * 4); } packet_peer_stream->put_var(Engine::get_singleton()->get_frames_drawn()); //total frame time packet_peer_stream->put_var(frame_time); //total frame time packet_peer_stream->put_var(idle_time); //idle frame time packet_peer_stream->put_var(fixed_time); //fixed frame time packet_peer_stream->put_var(fixed_frame_time); //fixed frame time packet_peer_stream->put_var(USEC_TO_SEC(total_script_time)); //total script execution time if (p_for_frame) { packet_peer_stream->put_var(profile_frame_data.size()); //how many profile framedatas to send packet_peer_stream->put_var(to_send); //how many script functions to send for (int i = 0; i < profile_frame_data.size(); i++) { packet_peer_stream->put_var(profile_frame_data[i].name); packet_peer_stream->put_var(profile_frame_data[i].data); } } else { packet_peer_stream->put_var(0); //how many script functions to send packet_peer_stream->put_var(to_send); //how many script functions to send } for (int i = 0; i < to_send; i++) { int sig_id = -1; if (profiler_function_signature_map.has(profile_info_ptrs[i]->signature)) { sig_id = profiler_function_signature_map[profile_info_ptrs[i]->signature]; } packet_peer_stream->put_var(sig_id); packet_peer_stream->put_var(profile_info_ptrs[i]->call_count); packet_peer_stream->put_var(profile_info_ptrs[i]->total_time / 1000000.0); packet_peer_stream->put_var(profile_info_ptrs[i]->self_time / 1000000.0); } if (p_for_frame) { profile_frame_data.clear(); } }