問題描述
使用 perf 或其他方式獲取 C 程序的運行時間(或其他統計信息) (Getting running time (or other stats) for C Program using perf or otherwise)
I need to write a C program (for a school assignment to determine cache size). I have used clock()
as a means of getting timing info. But was told that might lead to inaccurate results.
So I was thinking of using other libraries, introduced in recent labs, perf or papi, to record performance. But the way we used them was via command line:
perf stat ./test
I think its possible to use perf in the app? I am new to C, more used to higher level languages like Python/JS/Java etc. So I think I need to create a make file, include the library etc. Also what functions do I have?
I saw http://www.rzg.mpg.de/computing/hardware/BGP/perf.html
libperf.a
perf library for MPI programs.
libperfhpm.a
Use perf instrumentation to call hpmtoolkit.
libperfdummy.a
Provides dummies for the perf instrumentation. You can link against this library to avoid the perf overhead in production runs.
Which do I use? Its not a MPI program. Then how do I use it actually? I am using C and gcc. This looks like compilation but ... whats mpixlf90
mpixlf90_r -o tperf tperf.f -L/usr/local/lib -lperf
參考解法
方法 1:
There are lots of performance analysis tools (which provide information about running time, memory consumption) for C and C++ programs, some of which are,
Valgrind
Google Perf Tools
Hope this is what you are looking for!