I’m writing a small program in C, and I want to measure it’s performance.
I want to see how much time do it run in the processor and how many cache hit+misses has it made. Information about context switches and memory usage would be nice to have too.
The program takes less than a second to execute.
I like the information of /proc/[pid]/stat, but I don’t know how to see it after the program has died/been killed.
Any ideas?
EDIT: I think Valgrind adds a lot of overhead. That’s why I wanted a simple tool, like /proc/[pid]/stat, that is always there.
Use perf:
See the kernel wiki perf tutorial for details. This uses the hardware performance counters of your CPU, so the overhead is very small.
Example from the wiki:
No need to load a kernel module manually, on a modern debian system (with the linux-base package) it should just work. With the
perf record -a/perf reportcombo you can also do full-system profiling. Any application or library that has debugging symbols will show up with details in the report.For visualization flame graphs seem to work well. (Update 2020: the hotspot UI has flame graphs integrated.)