Possible Duplicate:
Saving gmon.out before killing a process
I'm trying to profile a server (source code available to me. c-code) on Linux environment. This server runs continuously like a web server. I'm trying to use gprof to profile the server. If the server exits by itself, gmon.out file is generated. I can use gprof and gmon.out to understand profiled data. Now the problem I have is, this server is running continuously, waiting for incoming socket connections, requests etc. If I kill this server, gmon.out is not generated. At this point I see the following options.
- change the source code to profile itself and log this information after receiving SIGKILL signal. This is by far the ugliest solution and may introduce noise in the measurement.
- Maybe there is a way to profile this server using gprof while the server is still running.
- Other tools to try?
EDIT: The server is multi-process server. running on FreeBSD 7.2
I'm sure, people have solved these kind of problems before. I failed to find useful information on SO or outside.
I appreciate any thoughts/solutions people have.
Thanks a bunch.
UPDATE 1:
- gprof doesn't seem to work with multi-process server. When I manage to get gmon.out after executing my server, only parent process is instrumented which actually doesnt do real work!.
- oProfile doesn't support FreeBSD which is what my server is running on. For various reasons I can't(not allowed to) change OS.
- Valgrind website doesnt have a port for FreeBSD. But there are some references to a port to FreeBSD. I failed to find FreeBSD port source.
Somehow I managed to get ports for valgrind. When I run make I get the following errors.
=> valgrind-stable-352.tar.gz doesn't seem to exist in /usr/obj/ports/distfiles/.
=> Attempting to fetch from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/.
fetch: ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/valgrind-stable-352.tar.gz: File unavailable (e.g., file not found, no access)
=> Attempting to fetch from http://www.rabson.org/.
fetch: http://www.rabson.org/valgrind-stable-352.tar.gz: No address record
=> Couldn't fetch it - please try to retrieve this
=> port manually into /usr/obj/ports/distfiles/ and try again.
*** Error code 1
I tried to find valgrind-stable-352.tar.gz on web. All of the links I found are dead.
I got pstack installed on my freebsd and the realised pstack gives only stack trace. reference : http://sourceforge.net/projects/bsd-pstack/
My understanding is that systemtap is only for kernel-space events, instrumentation etc.
I could be wrong or have insufficient information. Please correct me and give your thoughts. I really appreciate your assistance.
UPDATE 2: I think it will be helpful to give some details about the server that I'm trying to profile.
- it is multi-server program. I/O bound, to be specific mysql database.
- No threads involved. Each child-server-process handles only one request. configurable number of processes are created when the server starts.
- I would like to find time spent in each function and its frequency. function codes are a mix of CPU-bound and IO bound (I believe more IO).
- it is running on FreeBSD 7.2
- written in c. number of reads is much greater than writes to the database via this server.