I'm trying to monitor various hardware performance counters of a running system, however it seems that current PMC tool e.g. oprofile or perf tool can only record counters after the program finished, e.g.
~>perf record <command>;
~>perf report
the perf record returns only after the target program terminates, I'd like to periodically collect these counters like what vmstat does.
Edit: I want to collect hardware performance counters, e.g cache-misses,instructions,branch-misses, these counters are available in modern process.
It seems that current perf don't support Sar style output. However a very close emulation is possible with the help of watch command.
To collect counters periodically for the whole system, use the '-a' option. Below is an example of reporting the general hardware performance counters for every 60 seconds
It gives the output as
The usage of sleep command is a bit counter intuitive at first glance. Here the perf stat will NOT collect counters specific to sleep command ,instead sleep command simply act as a way to tell the perf stat the duration of collection(I realize that from the example in the perf wiki ) Note to collect system wise counters, administrative privilege is required, so the sudo before perf stat is necessary.
If you simply need collect counters specific to a running process(e.g., with pid 2785), then a sample command is
Note this time, sudo is NOT required.
I find that sar is a simple way to my needs for monitoring a linux system. It periodically collects stats on many things and you can have cron send you emails periodically with a table of the results which you can then process.
If you need to monitor more systems, or want fancy graphs or alerts, you might look at something like cacti or nagios.
don't forget collectl. collects a lot more data and its output is much earier to read than sar. if you do use sar, do youself a BIG favor and set the monitoring interval to 10 seconds rather than 10 minutes - only real gross problems will show up at a rate as coarse as 10 minutes. -mark
If you want to log really comprehensive data use Performance Co-Pilot. There's a nice GUI, too.