Profiling timer expired when using gperftools with sort

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

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

then I did:

$ env LD_PRELOAD="/usr/local/lib/libprofiler.so" 
$ sort file
$ env LD_PRELOAD=
$ sort file

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

nothing happened, and out.prof was not created!

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-bit, gperftools=2.5, libunwind=1.1, linux Ubuntu 16.04.1


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. Eg:

#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 wrt profiling.

链接地址: http://www.djcxy.com/p/87958.html

上一篇: 个人档案文件未被倾倒

下一篇: 使用排序方式使用gperftools时,分析计时器已过期