gpt4 book ai didi

c++ - gprof 探查器不打印时间摘要

转载 作者:太空宇宙 更新时间:2023-11-04 11:54:04 29 4
gpt4 key购买 nike

我创建了一个简单的程序:

#include <unistd.h>

void ssleep(unsigned int s)
{
usleep(1000000*s);
}

int main(int, char**)
{
ssleep(1);
}

在这些命令之后:

sch@sch-K52F:~/test$ g++ -pedantic -Wall main.cpp -pg
sch@sch-K52F:~/test$ ./a.out
sch@sch-K52F:~/test$ gprof -b a.out > profile

我得到一个没有时间摘要的配置文件:

  %   cumulative   self              self     total           
time seconds seconds calls Ts/call Ts/call name
0.00 0.00 0.00 1 0.00 0.00 ssleep(unsigned int)

与任何其他代码的情况相同。我错过了什么吗?

我的系统:

sch@sch-K52F:~/test$ uname -a
Linux sch-K52F 3.2.0-45-generic-pae #70-Ubuntu SMP Wed May 29 20:31:05 UTC 2013 i686 i686 i386 GNU/Linux
sch@sch-K52F:~/test$ gprof -v
GNU gprof (GNU Binutils for Ubuntu) 2.22
Based on BSD gprof, copyright 1983 Regents of the University of California.
This program is free software. This program has absolutely no warranty.

谢谢


编辑 1)

其他例子:

 time   seconds   seconds    calls  Ts/call  Ts/call  name
0.00 0.00 0.00 1482 0.00 0.00 std::_Iter_base<unsigned char*, false>::_S_base(unsigned char*)
0.00 0.00 0.00 1482 0.00 0.00 std::_Niter_base<unsigned char*>::iterator_type std::__niter_base<unsigned char*>(unsigned char*)
0.00 0.00 0.00 1247 0.00 0.00 std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_get_Tp_allocator()
0.00 0.00 0.00 988 0.00 0.00 __gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >::base() const
0.00 0.00 0.00 988 0.00 0.00 std::move_iterator<unsigned char*>::base() const
0.00 0.00 0.00 988 0.00 0.00 std::vector<unsigned char, std::allocator<unsigned char> >::size() const
0.00 0.00 0.00 988 0.00 0.00 std::_Iter_base<std::move_iterator<unsigned char*>, true>::_S_base(std::move_iterator<unsigned char*>)
0.00 0.00 0.00 988 0.00 0.00 std::move_iterator<unsigned char*>::move_iterator(unsigned char*)
0.00 0.00 0.00 988 0.00 0.00 std::_Miter_base<std::move_iterator<unsigned char*> >::iterator_type std::__miter_base<std::move_iterator<unsigned char*> >(std::move_iterator<unsigned char*>)
0.00 0.00 0.00 988 0.00 0.00 std::move_iterator<unsigned char*> std::make_move_iterator<unsigned char*>(unsigned char* const&)
0.00 0.00 0.00 741 0.00 0.00 __gnu_cxx::new_allocator<unsigned char>::max_size() const
0.00 0.00 0.00 555 0.00 0.00 operator new(unsigned int, void*)
0.00 0.00 0.00 541 0.00 0.00 void std::_Destroy_aux<true>::__destroy<unsigned char*>(unsigned char*, unsigned char*)
0.00 0.00 0.00 541 0.00 0.00 std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_deallocate(unsigned char*, unsigned int)
0.00 0.00 0.00 541 0.00 0.00 void std::_Destroy<unsigned char*>(unsigned char*, unsigned char*)

对于任何代码、任何函数,我总是得到零时间;/

最佳答案

这是因为 sleep() 不算作进程执行时间的一部分,而是算作 sleep 。也就是说,您的进程在请求的持续时间内被内核置于 sleep 状态,并且不使用任何 CPU 周期。尝试使用一些进行实际计算的循环。此外,gprof 似乎无法为系统调用和其他东西计时。它还具有 other issues . Gprof 旨在比较您自己的代码在连续重构中的性能增益,而不是作为一个通用的基准测试工具。

关于c++ - gprof 探查器不打印时间摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16907782/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com