Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiler that attaches to running processes?

I need a good profiler for both Windows and Linux (they don't have to be the same one; separate recommendations for each OS are fine) that can attach to an already running process that was not compiled in any "special" way and give me statistics on what functions the process is spending most of its time in. I have some long running scientific code and I want to get snapshots of where it's spending most of its time at various stages of execution, and be able to get the results without having to run the whole program start to finish.

The compiler I'm using (Digital Mars D) comes with an instrumenting profiler. It's way too slow for the jobs I'm running. Since I'm only interested in identifying major bottlenecks, I want something fast and easy to use, even if it's only roughly accurate. Ideally it should also be able to profile all threads simultaneously and give me an aggregate report.

On Linux, I've been using GDB as a poor man's sampling profiler (pausing my app a few times and seeing what function it's in). Basically, a more automated version of this is what I'm looking for.

One last requirement: On Linux it has to be easy to install without root privileges, since I'm going to be running it on a server that I don't have root access to.

Edit: While the code was written in D, D's compilation model, etc. is similar enough to C's that tools written for C should work fine.

like image 908
dsimcha Avatar asked Feb 21 '11 21:02

dsimcha


4 Answers

If you have a fairly recent kernel you can use perf:

perf record -p <pid> -g

...then perf report once you've gathered enough samples.

like image 90
caf Avatar answered Nov 12 '22 20:11

caf


You're looking for oprofile:

http://oprofile.sourceforge.net/

like image 39
R.. GitHub STOP HELPING ICE Avatar answered Nov 12 '22 19:11

R.. GitHub STOP HELPING ICE


For Linux, try Zoom. ALso, for rough work, lsstack is useful for finding bottlenecks.

like image 2
Mike Dunlavey Avatar answered Nov 12 '22 19:11

Mike Dunlavey


I haven't tried it, but xProf was written specifically for D. It's a statistical profiler.

like image 2
Peter Alexander Avatar answered Nov 12 '22 21:11

Peter Alexander