Sgenmi / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

A patch to make cpu profiler more easy-to-use for daemon like processes #452

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
For a daemon like process, it will never exit by itself. So there will be no 
ProfilerStop called if we use cpu profiler like this: "env 
LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=./myserver.prof ./myserver"

This patch will allow to profile a such process by step:
1. Use "env LD_PRELOAD=/usr/lib/libprofiler.so CPUPROFILE=./myserver.prof 
CPUPROFILESIG=12 ./myserver" to start the process
2. Use "killall -12 myserver" to start profiling when you like
3. After a proper period, use "killall -12 myserver" to stop profiling.

You also can use "env LD_PRELOAD=/usr/lib/libprofiler.so 
CPUPROFILE=./myserver.prof ./myserver" just like before when CPUPROFILESIG is 
not defined

Unified diffs for patching attached. (for file src/profiler.cc)

Original issue reported on code.google.com by qifa.z...@gmail.com on 25 Jul 2012 at 3:46

Attachments:

GoogleCodeExporter commented 9 years ago
Maybe this patch will be better
Include function CpuProfilerSwitch by #ifdef __GUNC__ and #endif

Original comment by qifa.z...@gmail.com on 27 Jul 2012 at 6:21

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by chapp...@gmail.com on 3 Nov 2012 at 4:54

GoogleCodeExporter commented 9 years ago
Accepted the patch with a bit of rework on my behalf :)

r182 | chappedm@gmail.com | 2012-11-04 23:45:01 -0500 (Sun, 04 Nov 2012) | 8 
lines

issue-452: Adds a control mechanism to the cpu profiler to be switched on and 
off using a user defined signal.

CPUPROFILESIGNAL - Takes a signal number between the value of 1 and 64 
inclusive which represents a signal number as defined by signal.h. The signal 
must not be in use by the program. Sending this signal to the program turns 
profiling on and off like a switch. By default the switch is off when the 
program starts. Successive profiles are suffixed with a monotonically 
increasing number.

Original comment by chapp...@gmail.com on 5 Nov 2012 at 4:47