diff --git a/server/php-engine.cpp b/server/php-engine.cpp index 5f5a33e561..56cf220209 100644 --- a/server/php-engine.cpp +++ b/server/php-engine.cpp @@ -2368,7 +2368,7 @@ int run_main(int argc, char **argv, php_mode mode) { max_special_connections = 1; set_on_active_special_connections_update_callback([] (bool on_accept) { if (on_accept) { - PhpScript::last_conn_start_processing_time = get_utime_monotonic(); + PhpScript::script_time_stats.conn_accept_time = get_utime_monotonic(); } vk::singleton::get().update_active_connections(active_special_connections, max_special_connections); }); diff --git a/server/php-runner.cpp b/server/php-runner.cpp index 7cec6d89c9..85549ab896 100644 --- a/server/php-runner.cpp +++ b/server/php-runner.cpp @@ -177,11 +177,11 @@ void PhpScript::init(script_t *script, php_query_data *data_to_set) noexcept { error_message = "??? error"; - script_time = 0; - net_time = 0; - cur_timestamp = dl_time(); + script_time_stats.script_time = 0; + script_time_stats.net_time = 0; queries_cnt = 0; long_queries_cnt = 0; + cur_timestamp = dl_time(); query_stats_id++; memset(&query_stats, 0, sizeof(query_stats)); @@ -267,7 +267,7 @@ void PhpScript::update_net_time() noexcept { kprintf("Awakening net event: %s\n", event->get_description()); } } - net_time += net_add; + script_time_stats.net_time += net_add; last_net_time_delta = net_add; cur_timestamp = new_cur_timestamp; @@ -275,7 +275,7 @@ void PhpScript::update_net_time() noexcept { void PhpScript::update_script_time() noexcept { double new_cur_timestamp = dl_time(); - script_time += new_cur_timestamp - cur_timestamp; + script_time_stats.script_time += new_cur_timestamp - cur_timestamp; cur_timestamp = new_cur_timestamp; } @@ -307,7 +307,9 @@ void PhpScript::finish() noexcept { const auto &script_mem_stats = dl::get_script_memory_stats(); state = run_state_t::uncleared; update_net_time(); - vk::singleton::get().add_request_stats(script_time, net_time, last_script_start_time - last_worker_init_time, last_script_start_time - last_conn_start_processing_time, + double script_init_time_sec = script_time_stats.script_start_time - script_time_stats.worker_init_time; + double connection_process_time_sec = script_time_stats.script_start_time - script_time_stats.conn_accept_time; + vk::singleton::get().add_request_stats(script_time_stats.script_time, script_time_stats.net_time, script_init_time_sec, connection_process_time_sec, queries_cnt, long_queries_cnt, script_mem_stats.max_memory_used, script_mem_stats.max_real_memory_used, vk::singleton::get().total_allocated, error_type); if (save_state == run_state_t::error) { @@ -339,7 +341,7 @@ void PhpScript::finish() noexcept { } } kprintf("[worked = %.3lf, net = %.3lf, script = %.3lf, queries_cnt = %5d, long_queries_cnt = %5d, heap_memory_used = %9d, peak_script_memory = %9d, total_script_memory = %9d] %s\n", - script_time + net_time, net_time, script_time, queries_cnt, long_queries_cnt, + script_time_stats.script_time + script_time_stats.net_time, script_time_stats.net_time, script_time_stats.script_time, queries_cnt, long_queries_cnt, (int)dl::get_heap_memory_used(), (int)script_mem_stats.max_real_memory_used, (int)script_mem_stats.real_memory_used, buf); @@ -428,7 +430,7 @@ void PhpScript::run() noexcept { check_net_context_errors(); CurException = Optional{}; - PhpScript::last_script_start_time = get_utime_monotonic(); + PhpScript::script_time_stats.script_start_time = get_utime_monotonic(); run_main->run(); if (CurException.is_null()) { set_script_result(nullptr); @@ -465,7 +467,7 @@ void PhpScript::reset_script_timeout() noexcept { } double PhpScript::get_net_time() const noexcept { - return net_time; + return script_time_stats.net_time; } long long PhpScript::memory_get_total_usage() const noexcept { @@ -475,7 +477,7 @@ long long PhpScript::memory_get_total_usage() const noexcept { double PhpScript::get_script_time() noexcept { assert_state(run_state_t::running); update_script_time(); - return script_time; + return script_time_stats.script_time; } int PhpScript::get_net_queries_count() const noexcept { @@ -487,9 +489,7 @@ ucontext_t_portable PhpScript::exit_context; volatile bool PhpScript::in_script_context = false; volatile bool PhpScript::time_limit_exceeded = false; volatile bool PhpScript::memory_limit_exceeded = false; -double PhpScript::last_conn_start_processing_time = 0; -double PhpScript::last_worker_init_time = 0; -double PhpScript::last_script_start_time = 0; +PhpScript::script_time_stats_t PhpScript::script_time_stats; static __inline__ void *get_sp() { return __builtin_frame_address(0); diff --git a/server/php-runner.h b/server/php-runner.h index 66341b5548..72d3d28c98 100644 --- a/server/php-runner.h +++ b/server/php-runner.h @@ -82,11 +82,19 @@ class PhpScriptStack : vk::not_copyable { * It stores state of the script: current execution point, pointers to allocated script memory, stack for script context, etc. */ class PhpScript { - double cur_timestamp{0}, net_time{0}, script_time{0}; + double cur_timestamp{0}; double last_net_time_delta{0}; int queries_cnt{0}; int long_queries_cnt{0}; + struct script_time_stats_t { + double net_time{0}; + double script_time{0}; + double conn_accept_time{0}; + double worker_init_time{0}; + double script_start_time{0}; + }; + private: int swapcontext_helper(ucontext_t_portable *oucp, const ucontext_t_portable *ucp); @@ -98,10 +106,7 @@ class PhpScript { volatile static bool in_script_context; volatile static bool time_limit_exceeded; volatile static bool memory_limit_exceeded; - - static double last_conn_start_processing_time; - static double last_worker_init_time; - static double last_script_start_time; + static script_time_stats_t script_time_stats; run_state_t state{run_state_t::empty}; const char *error_message{nullptr}; diff --git a/server/php-worker.cpp b/server/php-worker.cpp index ca99b27fc4..e199819d55 100644 --- a/server/php-worker.cpp +++ b/server/php-worker.cpp @@ -460,7 +460,7 @@ PhpWorker::PhpWorker(php_worker_mode_t mode_, connection *c, http_query_data *ht , mode(mode_) , req_id(req_id_) { - PhpScript::last_worker_init_time = init_time; + PhpScript::script_time_stats.worker_init_time = init_time; assert(c != nullptr); if (conn->target) { target_fd = static_cast(conn->target - Targets);