I need some means of recording the performance of an application on a Linux machine. I won't have an IDE.
Ideally, I need an app that will attach to a process and log periodic snapshots of: memory usage number of threads CPU usage
Any ideas?
I need some means of recording the performance of an application on a Linux machine. I won't have an IDE.
Ideally, I need an app that will attach to a process and log periodic snapshots of: memory usage number of threads CPU usage
Any ideas?
Have you looked into gprof? You need to compile the code with the -pg option, which instruments the code. After that you can run the prorgam and use gprof to see the results.
Well, in order to collect this types of information about your process you don't actuall need a profiler on Linux.
1) You can use
top
in batch mode. It runs in the batch mode either until it is killed or until N iterations is done :or
and you wiil get this:
2) You can use
ps
(for instance in a shell script)In order to do this you need to use
perf
if your Linux Kernal is greater than 2.6.32 or Oprofile if it is older. Both programs don't require from you to instrucment your program (likegporf
requires). However in order to ger call graph correctly inperf
you need to build you program with -fno-omit-frame-pointer. For example:g++ -fno-omit-frame-pointer -O2 main.cpp
.As for Linux
perf
:1) To record performance data:
or to record for 10 secs:
or to record with call graph ()
2) To analyze the recorded data
On RHEL 6.3 it is allowed to read /boot/System.map-2.6.32-279.el6.x86_64 so I usually add --kallsyms=/boot/System.map-2.6.32-279.el6.x86_64 when do perf report:
Here I wrote some more information on using Linux perf:
First of all - this is tutorial about Linux profiling with perf
You can use perf if your Linux Kernel is greater than 2.6.32 or oprofile if it is older. Both programs don't require from you to instrument your program (like gprof requires). However in order to get call graph correctly in perf you need to build you program with
-fno-omit-frame-pointer
. For example:g++ -fno-omit-frame-pointer -O2 main.cpp
. You can see "live" analysis of your application with perf top:Or you can record performance data of a running application and analyze them after that: 1) To record performance data:
or to record for 10 secs:
or to record with call graph ()
2) To analyze the recorded data
Or you can record performace data of a application and analyze them after that just by launching the application in this way and waiting for it to exit:
This is an example of profiling a test program The test program is in file main.cpp (I will put main.cpp at the bottom of the message): I compile it in this way:
I use libmalloc_minimial.so since it is compiled with -fno-omit-frame-pointer while libc malloc seems to be compiled without this option. Then I run my test program
Then I record performance data of a running process:
Then I analyze load per module:
Then load per function is analyzed:
Then call chains are analyzed:
So at this point you know where your program spends time. And this is main.cpp for the test:
You can use valgrind. It records data in a file which you can analyse later using a proper gui like KCacheGrind
A usage example would be :
It'll generate a file called
callgrind.out.xxx
where xxx is the pid of the programedit: unlike gprof valgrind works with many different languages including java with some limitations.
You can also try out cpuprofiler.com. It gets the information you would normally get from top command, and the cpu usage data can be even viewed remotely from a web browser.
If you are looking for things to do to possibly speed up the program, you need stackshots. A simple way to do this is to use the pstack utility, or lsstack if you can get it.
You can do better than gprof. If you want to use an official profiling tool, you want something that samples the call stack on wall-clock time and presents line-level cost, such as Oprofile or RotateRight/Zoom.
Quoting Linus Torvalds himself:
and later ...
See: http://marc.info/?l=git&m=126262088816902&w=2
Good luck!