使用带有排序的 gperftools 时,分析计时器已过期
Profiling timer expired when using gperftools with sort
我花了一整天的时间试图让gperftools工作:/
我厌倦了不同的libunwind版本,但是当我成功安装它时,每当我使用std::system时,我都会收到以下错误"分析计时器已过期"。
主.cpp:
#include <cstdlib>
int main(int argc, char** argv) {
std::system("cut -f1 anyExistingFile | sort > newSortedFile");
return 0;
}
我厌倦了执行以下分析:
$ g++ main.cpp -o myApp -std=c++11
$ env CPUPROFILE=out.prof LD_PRELOAD="/usr/local/lib/libprofiler.so" ./myApp
Profiling timer expired
PROFILE: interrupts/evictions/bytes = 0/0/64
然后我做到了:
$ env LD_PRELOAD="/usr/local/lib/libprofiler.so"
$ sort file
$ env LD_PRELOAD=
$ sort file
当我LD_PRELOAD设置为"/usr/local/lib/libprofiler.so"时,排序不起作用!
然后我尝试使用库的静态版本:
$ g++ main.cpp -o myApp -std=c++11 /usr/local/lib/libtcmalloc_and_profiler.a
$ env CPUPROFILE=out.prof ./myApp
什么也没发生,也没有创建Out.Prof!
所以我想知道为什么当我使用 std::system(sort) 时我得到"分析计时器已过期"? 这是使用静态版本的 gperftools 库的正确方法吗?
P.S: 64 位, gperftools=2.5, libunwind=1.1, linux Ubuntu 16.04.1
问题似乎是,当你设置LD_PRELOAD时,你实际上是为当前shell作业中的所有内容设置的,包括程序生成的子进程。同样的情况也发生在 CPUPROFILE 环境变量上。因此,cpu 分析器也会被激活以进行排序。看起来排序程序中的某些东西正在将 SIGPROF 信号处理程序重置为默认值,而无需实际重置相应的间隔计时器。因此,当排序完成足够的工作时,它会得到信号,默认处理程序退出程序。简单的解决方法是围绕排序程序取消设置CPUPROFILE。例如:
#include <cstdlib>
int main(int argc, char** argv) {
std::system("cut -f1 /usr/share/dict/american-english-insane | CPUPROFILE='' sort > /tmp/insane");
return 0;
}
至于为什么静态链接不起作用,那是因为程序中没有任何内容会拉入探查器符号,因此实际上变成了无操作 w.r.t. 分析。
相关文章:
- Linux的Cpp上的计时器
- 提升 ASIO 无法识别计时器对象
- 提升 asio 并发计时器取消问题与链
- 使用单体计时器的pthread_cond_timedwait有时会比预期晚超时
- 窗口中的微秒计时器
- 计时器是否从另一个线程启动?
- 如何在 c++ 中创建计时器
- C++回调计时器实现
- 在计时器或主线程外部的命令上销毁/替换线程
- 如何制作每秒从 30 乘 1 倒计时的计时器?
- 保留计时器集合(对象与指针)的最佳方法
- 在网络套接字计时器滴答后增加asio短读错误
- 是否可以仅使用标准 c++/c++11 实现不带"sleep"的计时器?
- 在没有NtSetTimerResolution的Windows上提高计时器分辨率(高分辨率)
- 计时器坏了或者其他什么的
- 功能计时器阻止主功能继续
- IO服务重新启动后,Boost最后期限计时器持续触发
- 使用带有排序的 gperftools 时,分析计时器已过期
- 截止日期计时器过期,现在怎么办
- boost截止日期计时器在iOS中过期不准确