Linux has a tool called perf.
perf stat -B <command...>
When executed as above, performance indicators are output after the command output (i.e., after the program runs and exits) as follows:
<The screen output of the command>
Performance counter stats for 'ls':
2.076373 task-clock (msec) # 0.775 CPUs utilized
0 context-switches # 0.000 K/sec
0 cpu-migrations # 0.000 K/sec
262 page-faults # 0.126 M/sec
5,062,230 cycles # 2.438 GHz [64.69%]
3,657,439 stalled-cycles-frontend # 72.25% frontend cycles idle [52.08%]
3,131,202 stalled-cycles-backend # 61.85% backend cycles idle
2,006,362 instructions # 0.40 insns per cycle
# # 1.82 stalled cycles per insn
495,853 branches # 238.807 M/sec
14,877 branch-misses # 3.00% of all branches
0.002679898 seconds time elapsed
For the perf tool, see https://perf.wiki.kernel.org/index.php/Tutorial.
L2 Cache
If it's L2 cache, you can see LLC-loads and LLC-load-misses, LLC-store-misses, LLC-prefetch-misses. LLC stands for Last Level Cache.
To check with perf, do the following:
perf record -e LLC-loads, LLC-load-misses <command...>
If you run as above, you will see a file called perf.data that you can check the history by using the following command:
perf report
If compilation is possible, I think we can get better results if we use the -g option.
© 2024 OneMinuteCode. All rights reserved.