From 6e064ba6ce975d1ea61b89a2b79e7552b322f453 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:29:04 +0800 Subject: [PATCH] feat auto stop profiler --- 3party/gperftools/src/profiler.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/3party/gperftools/src/profiler.cc b/3party/gperftools/src/profiler.cc index dd175d5..0ff4adc 100644 --- a/3party/gperftools/src/profiler.cc +++ b/3party/gperftools/src/profiler.cc @@ -65,6 +65,7 @@ typedef int ucontext_t;// just to quiet the compiler, mostly #include #include #include +#include using std::string; @@ -160,6 +161,14 @@ CpuProfilerSwitch(int signal_number) RAW_LOG(FATAL, "Can't turn on cpu profiling for '%s': %s\n", full_profile_name, strerror(errno)); } RAW_LOG(INFO, "Start New cpu Profiling for '%s'", full_profile_name); + + char *auto_stop_interval = getenv("CPUPROFILESTOP"); + if (auto_stop_interval != NULL) { + long int interval = strtol(auto_stop_interval, NULL, 10); + if (interval > 0) { + std::thread([interval] { std::this_thread::sleep_for(std::chrono::seconds(interval)); }).detach(); + } + } } else { ProfilerStop(); RAW_LOG(INFO, "Stop cpu Profiling for '%s'", full_profile_name);