Understanding Linux CPU stats
blog.scoutapp.com
blog.scoutapp.com
If it's exposed to userspace, you can log it. You can then replay it or graph it, changing the granularity from the sample period upwards.
E.g.
$> perf stat echo "hi"
Performance counter stats for 'echo hi':
0.718209 task-clock (msec) # 0.595 CPUs utilized
2 context-switches # 0.003 M/sec
0 cpu-migrations # 0.000 K/sec
59 page-faults # 0.082 M/sec
844,067 cycles # 1.175 GHz
561,879 stalled-cycles-frontend # 66.57% frontend cycles idle
<not supported> stalled-cycles-backend
611,918 instructions # 0.72 insns per cycle
# 0.92 stalled cycles per insn
127,740 branches # 177.859 M/sec
7,279 branch-misses # 5.70% of all branches
0.001207821 seconds time elapsed
For more stats, check perf list