gperftools CPU分析器到底如何启动? [英] How exactly does gperftools CPU profiler start?

查看:267
本文介绍了gperftools CPU分析器到底如何启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gperftools文档 libprofiler 链接到目标程序中:

  $ gcc myprogram.c -lprofiler 

(不改变程序代码)。

然后程序应该使用特定的环境变量运行:

  CPUPROFILE = / tmp / profiler_output ./a.out 

问题是: libprofile 如何有一个机会来启动和完成一个分析器时,它只是加载,但其函数不被称为?



该库中没有构造函数(证明)。
所有场合



我没有想法,下一步要看哪里?

p>

解决方案

根据链接网页的文档,在链接库下,它描述了-lprofiler步骤与链接使用LD_PRELOAD选项共享目标文件。



共享目标文件与头文件不同。头文件包含函数声明,这些函数声明在编译程序时被查找,所以函数的名称会解析,但名称只是名称,而不是实现。共享对象文件(.so)包含函数的实现。有关更多信息,请参阅以下StackOverflow答案



源文件/ trunk / src / profiler.cc 在第182行上有一个CPUProfiler构造函数,它根据CPUPROFILE环境变量(第187行和第230行)检查是否启用分析。



然后调用第237行的Start函数。根据此文件中的注释,析构函数在第273行调用Stop函数。



要回答你的问题我相信第132行 CpuProfiler CpuProfiler :: instance _; 是CpuProfiler实例化的行。



gperftools文档缺乏明确性是已知问题请参阅此处


gperftools documentation says that libprofiler should be linked into a target program:

$ gcc myprogram.c -lprofiler

(without changing a code of the program).

And then program should be run with a specific environment variable:

CPUPROFILE=/tmp/profiler_output ./a.out

The question is: how does libprofile have a chance to start and finish a profiler when it is merely loaded, but its functions are not called?

There is no constructor function in that library (proof). All occasions of "CPUPROFILE" in library code do not refer to any place where profiler is started.

I am out of ideas, where to look next?

解决方案

As per the documentation the linked webpage, under Linking the library, it describes that the -lprofiler step is the same as linking against the shared object file with LD_PRELOAD option.

The shared object file isn't the same as just the header file. The header file contains function declarations which are looked up by when compiling a program , so the names of the functions resolve, but the names are just names, not implementations. The shared object file (.so) contains the implementations of the functions. For more information see the following StackOverflow answer.

Source file of /trunk/src/profiler.cc on Line 182, has a CPUProfiler constructor, that checks for whether profiling should be enabled or not based on the CPUPROFILE environment variable (Line 187 and Line 230).

It then calls the Start function on Line 237. As per the comments in this file, the destructor calls the Stop function on Line 273.

To answer your question I believe Line 132 CpuProfiler CpuProfiler::instance_; is the line where the CpuProfiler is instantiated.

This lack of clarity in the gperftools documentation is known issue see here.

这篇关于gperftools CPU分析器到底如何启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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