void main() { printf("hello, pid=%d\n", getpid()); while(1) { printf("begin sleep...\n"); sleep(1); } } [root@n16 dynamic-tracing]# gcc -o main main.c [root@n16 dynamic-tracing]# perf stat ./main hello, pid=3422281 begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... ^C./main: Interrupt
void for_loop() { for (int i = 0; i < 1000; i++) { for (int j = 0; j < 10000; j++) { int x = sin(i) + cos(j); } } }
void loopsmall() { for (int i = 0; i < 10; i++) { for_loop(); } }
void loopbig() { for (int i = 0; i < 100; i++) { for_loop(); } }
int main() { printf("pid=%d\n", getpid()); loopbig(); loopsmall();
return 0; } [root@n16 perf]# g++ -o perftest perftest.cpp [root@n16 perf]# ./perftest pid=3424465 ### 新开一个shell [root@n16 perf]# perf record -p 3424465 -a -g -F 99 -- sleep 10 Warning: PID/TID switch overriding SYSTEM [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.096 MB perf.data (982 samples) ] [root@n16 perf]# [root@n16 perf]# [root@n16 perf]# perf report
# man perf report
# man perf kmem # perf kmem record # perf kmem stat
[root@n16 perf]# ./main hello, pid=3430094 begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... begin sleep... ### 新开一个shell [root@n16 perf]# perf sched record -p 3430094 -- sleep 10 [root@n16 perf]# perf sched script [root@n16 perf]# perf sched latency [root@n16 perf]# perf report