我想学习 gprof.所以我从一个简单的程序开始。我在下面用c写了一个小程序:
#include<stdio.h>
#include<unistd.h>
void hello(void);
int main()
{
hello();
return 0;
}
void hello()
{
int i;
for(i=0; i<60; i++)
{
sleep(1);
printf("hello world\n");
}
}
我使用 -pg 选项编译了我的程序。我执行它以确保它工作正常。
然后我做了
gprof -f hello a.out > gout
这给了我创建的痛风文件。在痛风文件中,我可以看到以下信息。
% cumulative self self total
time seconds seconds calls ms/call ms/call name
-nan 0.00 0.00 3 0.00 0.00 __1cH__CimplWnew_atexit_implemented6F_b_ (1561)
-nan 0.00 0.00 1 0.00 0.00 __1cFhello6F_v_ (1562)
-nan 0.00 0.00 1 0.00 0.00 __1cG__CrunMdo_exit_code6F_v_ (1563)
-nan 0.00 0.00 1 0.00 0.00 __1cG__CrunSregister_exit_code6FpG_v_v_ (1564)
-nan 0.00 0.00 1 0.00 0.00 __1cG__CrunVdo_exit_code_in_range6Fpv1_v_ (1565)
-nan 0.00 0.00 1 0.00 0.00 __1cH__CimplKcplus_fini6F_v_ (1566)
-nan 0.00 0.00 1 0.00 0.00 __1cH__CimplQ__type_info_hash2t5B6M_v_ (1567)
-nan 0.00 0.00 1 0.00 0.00 __1cU__STATIC_CONSTRUCTOR6F_v_ (1568)
-nan 0.00 0.00 1 0.00 0.00 __SLIP.FINAL__A (1569)
-nan 0.00 0.00 1 0.00 0.00 __SLIP.INIT_A (1570)
-nan 0.00 0.00 1 0.00 0.00 __cplus_fini_at_exit (1571)
-nan 0.00 0.00 1 0.00 0.00 _ex_deregister (1572)
-nan 0.00 0.00 1 0.00 0.00 main (1)
^L
Index by function name
(1562) __1cFhello6F_v_ (1567) __1cH__CimplQ__type(1571) __cplus_fini_at_exi
(1563) __1cG__CrunMdo_exit(1561) __1cH__CimplWnew_at(1572) _ex_deregister
(1564) __1cG__CrunSregiste(1568) __1cU__STATIC_CONST (1) main
(1565) __1cG__CrunVdo_exit(1569) __SLIP.FINAL__A
(1566) __1cH__CimplKcplus_(1570) __SLIP.INIT_A
我给了 60 秒的睡眠时间。我在 gprof 输出中没有看到 60 秒。我相信它可能隐藏在输出中。有人可以帮我理解gprof的输出吗?