feat use raise auto stop profiler
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 2m1s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 2m4s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 2m9s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 2m21s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m29s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m52s
All checks were successful
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 2m1s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 2m4s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 2m9s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 2m21s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 2m29s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m52s
This commit is contained in:
parent
76ea4f1eea
commit
af261ab82e
@ -142,9 +142,9 @@ private:
|
|||||||
static void
|
static void
|
||||||
CpuProfilerSwitch(int signal_number)
|
CpuProfilerSwitch(int signal_number)
|
||||||
{
|
{
|
||||||
static unsigned profile_count;
|
|
||||||
static char base_profile_name[PATH_MAX];
|
static char base_profile_name[PATH_MAX];
|
||||||
static bool started = false;
|
static std::atomic<unsigned> profile_count;
|
||||||
|
static std::atomic<bool> started = false;
|
||||||
|
|
||||||
if (base_profile_name[0] == '\0') {
|
if (base_profile_name[0] == '\0') {
|
||||||
if (!GetUniquePathFromEnv("CPUPROFILE", base_profile_name)) {
|
if (!GetUniquePathFromEnv("CPUPROFILE", base_profile_name)) {
|
||||||
@ -154,7 +154,7 @@ CpuProfilerSwitch(int signal_number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char full_profile_name[PATH_MAX + 16];
|
char full_profile_name[PATH_MAX + 16];
|
||||||
snprintf(full_profile_name, sizeof(full_profile_name), "%s.%u", base_profile_name, profile_count);
|
snprintf(full_profile_name, sizeof(full_profile_name), "%s.%u", base_profile_name, profile_count.load());
|
||||||
if (!started) {
|
if (!started) {
|
||||||
if (!ProfilerStart(full_profile_name)) {
|
if (!ProfilerStart(full_profile_name)) {
|
||||||
RAW_LOG(FATAL, "Can't turn on cpu profiling for '%s': %s\n", full_profile_name, strerror(errno));
|
RAW_LOG(FATAL, "Can't turn on cpu profiling for '%s': %s\n", full_profile_name, strerror(errno));
|
||||||
@ -167,12 +167,10 @@ CpuProfilerSwitch(int signal_number)
|
|||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
RAW_LOG(INFO, "Auto Stop cpu Profiling After %ds", interval);
|
RAW_LOG(INFO, "Auto Stop cpu Profiling After %ds", interval);
|
||||||
int cur_profile_count = profile_count;
|
int cur_profile_count = profile_count;
|
||||||
std::thread([interval, cur_profile_count] {
|
std::thread([interval, cur_profile_count, signal_number] {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(interval));
|
std::this_thread::sleep_for(std::chrono::seconds(interval));
|
||||||
if (profile_count == cur_profile_count + 1) {
|
// send signal to self
|
||||||
RAW_LOG(INFO, "Trigger Auto stop CPU Profiling, duration=%ds", interval);
|
if (started && profile_count.load() == cur_profile_count + 1) { raise(signal_number); }
|
||||||
ProfilerStop();
|
|
||||||
}
|
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user