Home:ALL Converter>How to properly handle signals, so that gperftools CPU profiler still works?

How to properly handle signals, so that gperftools CPU profiler still works?

Ask Time:2013-10-25T13:52:45         Author:abyss.7

Json Formatter

I want to profile my daemon program, that pauses the main thread:

sigset_t signal_mask;
sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGTERM);
sigaddset(&signal_mask, SIGINT);

int sig;
sigwait(&signal_mask, &sig);

All other threads simply block all signals. As far as I know the profiler uses SIGPROF signal for its operations. If I start profiling with such a code, the output .prof file is empty:

env CPUPROFILE=daemon.prof ./daemon

How should I properly handle signals in main thread and other threads to enable profiling? Or may be an issue is somewhere else?

Author:abyss.7,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/19582060/how-to-properly-handle-signals-so-that-gperftools-cpu-profiler-still-works
Vladimír Čunát :

\n All other threads simply block all signals.\n\n\nYou simply need to unblock SIGPROF in all threads (or in those that you want to profile). We were just solving exactly the same problem in a multi-threaded daemon.",
2016-07-21T07:34:31
yy