Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 555
abyss.7 Avatar asked Nov 12 '22 19:11

abyss.7


1 Answers

All other threads simply block all signals.

You 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.

like image 103
Vladimír Čunát Avatar answered Nov 15 '22 05:11

Vladimír Čunát