Debian >> Performance

如何使用gprof找出程式耗時的副程式


測試程式

#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)
{
  int cnt=10000;
  while(cnt--){
    test1();
    test2();
    test3();
  }
}

編譯並且執行

$ gcc -pg -g -no-pie main.c -o test
$ ./test
$ gprof -b test gmon.out

完成


返回上一頁