diff --git a/presto-native-execution/presto_cpp/main/PrestoServer.cpp b/presto-native-execution/presto_cpp/main/PrestoServer.cpp index 91e70c4f2c0bd..9c06fa12d4bdd 100644 --- a/presto-native-execution/presto_cpp/main/PrestoServer.cpp +++ b/presto-native-execution/presto_cpp/main/PrestoServer.cpp @@ -1194,6 +1194,16 @@ void PrestoServer::addServerPeriodicTasks() { 1'000'000, // 1 second "populate_mem_cpu_info"); + periodicTaskManager_->addTask( + [start = start_]() { + const auto seconds = std::chrono::duration_cast( + std::chrono::steady_clock::now() - start) + .count(); + RECORD_METRIC_VALUE(kCounterWorkerRuntimeUptimeSecs, seconds); + }, + 2'000'000, // 2 seconds + "worker_runtime_uptime_secs"); + const auto timeslice = SystemConfig::instance()->taskRunTimeSliceMicros(); if (timeslice > 0) { periodicTaskManager_->addTask( diff --git a/presto-native-execution/presto_cpp/main/common/Counters.cpp b/presto-native-execution/presto_cpp/main/common/Counters.cpp index da56b7c9df91c..2704568c28c19 100644 --- a/presto-native-execution/presto_cpp/main/common/Counters.cpp +++ b/presto-native-execution/presto_cpp/main/common/Counters.cpp @@ -112,6 +112,8 @@ void registerPrestoMetrics() { DEFINE_METRIC( kCounterPartitionedOutputBufferGetDataLatencyMs, facebook::velox::StatType::AVG); + DEFINE_METRIC( + kCounterWorkerRuntimeUptimeSecs, facebook::velox::StatType::AVG); DEFINE_METRIC(kCounterOsUserCpuTimeMicros, facebook::velox::StatType::AVG); DEFINE_METRIC(kCounterOsSystemCpuTimeMicros, facebook::velox::StatType::AVG); DEFINE_METRIC(kCounterOsNumSoftPageFaults, facebook::velox::StatType::AVG); diff --git a/presto-native-execution/presto_cpp/main/common/Counters.h b/presto-native-execution/presto_cpp/main/common/Counters.h index 52ecc1356e06b..c6379c575f011 100644 --- a/presto-native-execution/presto_cpp/main/common/Counters.h +++ b/presto-native-execution/presto_cpp/main/common/Counters.h @@ -157,6 +157,9 @@ constexpr std::string_view kCounterTotalPartitionedOutputBuffer{ /// OutputBufferManager. constexpr std::string_view kCounterPartitionedOutputBufferGetDataLatencyMs{ "presto_cpp.partitioned_output_buffer_get_data_latency_ms"}; +/// Worker runtime uptime in seconds after the worker process started. +constexpr std::string_view kCounterWorkerRuntimeUptimeSecs{ + "presto_cpp.worker_runtime_uptime_secs"}; /// ================== OS Counters =================