Commit 78b7cc8e authored by tqcq's avatar tqcq
Browse files

fix auto stop cpu profiler

parent 6e064ba6
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -156,7 +156,6 @@ CpuProfilerSwitch(int signal_number)
    char full_profile_name[PATH_MAX + 16];
    snprintf(full_profile_name, sizeof(full_profile_name), "%s.%u", base_profile_name, profile_count);
    if (!started) {
        ++profile_count;
        if (!ProfilerStart(full_profile_name)) {
            RAW_LOG(FATAL, "Can't turn on cpu profiling for '%s': %s\n", full_profile_name, strerror(errno));
        }
@@ -166,9 +165,19 @@ CpuProfilerSwitch(int signal_number)
        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();
                RAW_LOG(INFO, "Auto Stop cpu Profiling After %ss", interval);
                int cur_profile_count = profile_count;
                std::thread([interval, cur_profile_count] {
                    std::this_thread::sleep_for(std::chrono::seconds(interval));
                    if (profile_count == cur_profile_count) {
                        RAW_LOG(INFO, "Trigger Auto stop CPU Profiling, duration=%ss", interval);
                        ProfilerStop();
                    }
                }).detach();
            }
        }

        ++profile_count;
    } else {
        ProfilerStop();
        RAW_LOG(INFO, "Stop cpu Profiling for '%s'", full_profile_name);