測試程式
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void test1(void)
{
for (int x = 0; x < 5000; x++);
}
void test2(void)
{
usleep(1);
}
void test3(void)
{
usleep(100);
}
int main(int argc, char** argv)
{
while (1) {
test1();
test2();
test3();
}
}
編譯
$ gcc -o test main.c
執行
$ ./test & $ sudo perf record -p `pidof test`
3秒後,使用(Ctrl + C)停止perf
$ sudo perf report
完成