使用 perf 或其他方式獲取 C 程序的運行時間(或其他統計信息) (Getting running time (or other stats) for C Program using perf or otherwise)


問題描述

使用 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,

  1. Valgrind

  2. Google Perf Tools

Hope this is what you are looking for!

(by Jiew MengRaj)

參考文件

  1. Getting running time (or other stats) for C Program using perf or otherwise (CC BY-SA 3.0/4.0)

#perf #C






相關問題

使用 perf 或其他方式獲取 C 程序的運行時間(或其他統計信息) (Getting running time (or other stats) for C Program using perf or otherwise)

使用 perf_events/oprofile 在 Linux 上分析 JIT 的輸出? (Profiling output of JIT on Linux with perf_events/oprofile?)

如何提出高緩存未命中率示例? (How to come up with a high cache miss rate example?)

perf 關於嵌套函數的最佳結果 (perf top result about nested functions)

Haswell 微架構在 perf 中沒有 Stalled-cycles-backend (Haswell microarchitecture don't have Stalled-cycles-backend in perf)

perf 如何使用 offcore 事件? (How does perf use the offcore events?)

外部化 react 和 react-dom 依賴項是否會增加反應應用程序的加載時間 (Does externalising react and react-dom dependencies give a gain in load time of a react app)

使用 PERF_EVENT_IOC_PERIOD 在運行時更改採樣週期 (Usage of PERF_EVENT_IOC_PERIOD to change sampling period during runtime)

理解 perf stat 輸出中的數字 (Make sense of numbers in perf stat output)

perf_event_open 權限被拒絕,除了使用 sudo 或更改 perf_event_paranoid 文件之外,還有其他方法嗎? (Permission denied on perf_event_open, is there another way than to use sudo or changing the perf_event_paranoid file?)

有選擇地為特定參數記錄內核 Ftrace 點 (Logging the kernel Ftrace point selectively for particular arguments)

性能計數器和 IMC 計數器不匹配 (Performance Counters and IMC Counter Not Matching)







留言討論