diff --git a/server/php-runner.cpp b/server/php-runner.cpp index a6d82ede40..915ad59949 100644 --- a/server/php-runner.cpp +++ b/server/php-runner.cpp @@ -183,6 +183,7 @@ void PhpScript::init(script_t *script, php_query_data_t *data_to_set) noexcept { script_time = 0; net_time = 0; + script_max_running_interval = 0; script_init_rusage = get_rusage_info(); queries_cnt = 0; @@ -281,7 +282,9 @@ 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; + double delta = new_cur_timestamp - cur_timestamp; + script_time += delta; + script_max_running_interval = std::fmax(script_max_running_interval, delta); cur_timestamp = new_cur_timestamp; } @@ -320,7 +323,7 @@ void PhpScript::finish() noexcept { } process_rusage_t script_rusage = get_script_rusage(); - vk::singleton::get().add_request_stats(script_time, net_time, script_init_time_sec, connection_process_time_sec, + vk::singleton::get().add_request_stats(script_time, net_time, script_max_running_interval, script_init_time_sec, connection_process_time_sec, queries_cnt, long_queries_cnt, script_mem_stats, vk::singleton::get().total_allocated, script_rusage, error_type); if (save_state == run_state_t::error) { assert (error_message != nullptr); diff --git a/server/php-runner.h b/server/php-runner.h index 38135c9e4a..ce4394a4f9 100644 --- a/server/php-runner.h +++ b/server/php-runner.h @@ -88,6 +88,7 @@ class PhpScript { double net_time{0}; double script_time{0}; double last_net_time_delta{0}; + double script_max_running_interval{0}; int queries_cnt{0}; int long_queries_cnt{0}; diff --git a/server/server-stats.cpp b/server/server-stats.cpp index e45cece4e5..10e5d5d0ac 100644 --- a/server/server-stats.cpp +++ b/server/server-stats.cpp @@ -638,11 +638,12 @@ void ServerStats::after_fork(pid_t worker_pid, uint64_t active_connections, uint last_update_aggr_stats = std::chrono::steady_clock::now(); } -void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, double script_init_time_sec, double connection_process_time_sec, +void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, double script_max_running_interval_sec, double script_init_time_sec, double connection_process_time_sec, int64_t script_queries, int64_t long_script_queries, const memory_resource::MemoryStats &script_memory_stats, int64_t curl_total_allocated, process_rusage_t script_rusage, script_error_t error) noexcept { auto &stats = worker_type_ == WorkerType::job_worker ? shared_stats_->job_workers : shared_stats_->general_workers; const auto script_time = std::chrono::duration_cast(std::chrono::duration(script_time_sec)); const auto net_time = std::chrono::duration_cast(std::chrono::duration(net_time_sec)); + const auto script_max_running_interval = std::chrono::duration_cast(std::chrono::duration(script_max_running_interval_sec)); const auto script_init_time = std::chrono::duration_cast(std::chrono::duration(script_init_time_sec)); const auto http_connection_process_time = std::chrono::duration_cast(std::chrono::duration(connection_process_time_sec)); const auto script_user_time = std::chrono::duration_cast(std::chrono::duration(script_rusage.user_time)); @@ -656,7 +657,7 @@ void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, stats.add_request_stats(queries_stat, error, script_memory_stats, curl_total_allocated); shared_stats_->workers.add_worker_stats(queries_stat, worker_process_id_); - StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), error, script_memory_stats, script_queries, long_script_queries, + StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), script_max_running_interval.count(), error, script_memory_stats, script_queries, long_script_queries, script_user_time.count(), script_system_time.count(), script_init_time.count(), http_connection_process_time.count(), script_rusage.voluntary_context_switches, script_rusage.involuntary_context_switches); diff --git a/server/server-stats.h b/server/server-stats.h index 81a016c15e..170459da41 100644 --- a/server/server-stats.h +++ b/server/server-stats.h @@ -20,7 +20,7 @@ class ServerStats : vk::not_copyable { public: void init() noexcept; - void add_request_stats(double script_time_sec, double net_time_sec, double script_init_time_sec, double connection_process_time_sec, + void add_request_stats(double script_time_sec, double net_time_sec, double script_max_running_interval_sec, double script_init_time_sec, double connection_process_time_sec, int64_t script_queries, int64_t long_script_queries, const memory_resource::MemoryStats &script_memory_stats, int64_t curl_total_allocated, process_rusage_t script_rusage, script_error_t error) noexcept; diff --git a/server/statshouse/statshouse-manager.cpp b/server/statshouse/statshouse-manager.cpp index 78b492ebb5..da0c88b6c7 100644 --- a/server/statshouse/statshouse-manager.cpp +++ b/server/statshouse/statshouse-manager.cpp @@ -100,7 +100,7 @@ void StatsHouseManager::generic_cron_check_if_tag_host_needed() { } } -void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, script_error_t error, +void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error, const memory_resource::MemoryStats &script_memory_stats, uint64_t script_queries, uint64_t long_script_queries, uint64_t script_user_time_ns, uint64_t script_system_time_ns, uint64_t script_init_time, uint64_t http_connection_process_time, @@ -110,6 +110,7 @@ void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_ client.metric("kphp_request_time").tag("script").tag(worker_type).tag(status).write_value(script_time_ns); client.metric("kphp_request_time").tag("net").tag(worker_type).tag(status).write_value(net_time_ns); + client.metric("kphp_request_script_time_max_running_interval").tag(worker_type).tag(status).write_value(script_max_running_interval_ns); client.metric("kphp_request_cpu_time").tag("user").tag(worker_type).tag(status).write_value(script_user_time_ns); client.metric("kphp_request_cpu_time").tag("system").tag(worker_type).tag(status).write_value(script_system_time_ns); client.metric("kphp_request_init_time").tag(worker_type).tag(status).write_value(script_init_time); diff --git a/server/statshouse/statshouse-manager.h b/server/statshouse/statshouse-manager.h index 141de2e885..fd8a552710 100644 --- a/server/statshouse/statshouse-manager.h +++ b/server/statshouse/statshouse-manager.h @@ -55,7 +55,7 @@ class StatsHouseManager : vk::not_copyable { return this->instance_cache_key_normalization_function != nullptr; } - void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, script_error_t error, const memory_resource::MemoryStats &script_memory_stats, + void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error, const memory_resource::MemoryStats &script_memory_stats, uint64_t script_queries, uint64_t long_script_queries, uint64_t script_user_time_ns, uint64_t script_system_time_ns, uint64_t script_init_time, uint64_t http_connection_process_time,