将gperftools与sort一起使用时,性能分析计时器已过期 [英] Profiling timer expired when using gperftools with sort

查看:133
本文介绍了将gperftools与sort一起使用时,性能分析计时器已过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整天都在尝试使 gperftools 正常工作:/

I spent the whole day trying to make gperftools working :/

我厌倦了不同的libunwind版本,但是当我成功安装它时,每当我使用std :: system时,都会出现以下错误分析计时器已过期".

I tired different libunwind versions but when I successed in installing it I got the following error "Profiling timer expired" whenever I used std::system.

main.cpp:

#include <cstdlib>
int main(int argc, char** argv) {
    std::system("cut -f1 anyExistingFile | sort > newSortedFile");
    return 0;
}

我很疲倦地执行以下分析:

I tired to perform profiling as following:

$ 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"时,

排序不起作用!!

sort was not working when I had LD_PRELOAD set to "/usr/local/lib/libprofiler.so" !!

然后,我尝试使用该库的静态版本:

then I tried to use the static versions of the library:

$ g++ main.cpp -o myApp -std=c++11 /usr/local/lib/libtcmalloc_and_profiler.a
$ env CPUPROFILE=out.prof ./myApp

什么也没有发生,并且out.prof没有创建!

nothing happened, and out.prof was not created!

所以我想知道为什么在使用std :: system(sort)时为什么会出现分析计时器已过期"的信息?是使用gperftools库静态版本的正确方法吗?

so I am wondering why I get "Profiling timer expired" when I use std::system(sort)? and is it the right way to use the static version of gperftools library?

PS:64位,gperftools = 2.5,libunwind = 1.1,Linux Ubuntu 16.04.1

P.S: 64-bit, gperftools=2.5, libunwind=1.1, linux Ubuntu 16.04.1

推荐答案

问题似乎是,当您设置LD_PRELOAD时,实际上是针对当前Shell作业中的所有内容(包括程序产生的子进程)进行设置. CPUPROFILE环境变量也是如此.因此,CPU profiler也被激活以进行排序.而且看起来排序程序中的某件事正在将SIGPROF信号处理程序重置为默认值,而没有实际重置相应的间隔计时器.因此,当排序完成足够的工作时,它将发出信号,并且默认处理程序退出程序.一个简单的解决方法是在您的排序程序周围取消设置CPUPROFILE.例如:

The issue seems to be that when you set LD_PRELOAD you actually set it for everything in current shell's job, including childs processes that your program spawns. Same happens to CPUPROFILE environment variable. So cpu profiler gets activated for sort as well. And it looks like something within sort program is resetting SIGPROF signal handler to default without actually resetting corresponding interval timer. So when sort completes enough work it gets signal and default handler exits the program. Simple workaround is to unsetenv CPUPROFILE around your sort program. E.g.:

#include <cstdlib>
int main(int argc, char** argv) {
    std::system("cut -f1 /usr/share/dict/american-english-insane | CPUPROFILE='' sort  > /tmp/insane");
    return 0;
}

关于为什么静态链接不起作用的原因,是因为程序中什么都没有拉进探查器符号,所以实际上变成了无操作.剖析.

As for why static linking didn't work, it is because nothing in your program pulls in profiler symbols, so becomes effectively no-op w.r.t. profiling.

这篇关于将gperftools与sort一起使用时,性能分析计时器已过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆