在Mac OS X上使用gperftools的问题 [英] Problems with using gperftools on Mac OS X

查看:1440
本文介绍了在Mac OS X上使用gperftools的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个主题上发现了几个冲突的答案。 博客post需要libuwind,但是在Mac OS X上不起作用。我的代码中包括 #include< google / profiler.h> ,但是我的编译器找不到图书馆。我通过homebrew安装了 gperftools 。此外,我发现 stackoverflow问题显示此:

I have found several conflicting answers over this topic. This blog post requires libuwind, but that doesn't work on Mac OS X. I included #include <google/profiler.h> in my code, however my compiler (g++) could not find the library. I installed gperftools via homebrew. In addition, I found this stackoverflow question showing this:


然后我运行pprof生成输出:

Then I ran pprof to generate the output:

[hidden ~]$ pprof --text ./a.out cpu.profile 
Using local file ./a.out.
Using local file cpu.profile.
Removing __sigtramp from all stack traces.
Total: 282 samples
     107  37.9%  37.9%      107  37.9% 0x000000010d72229e
      16   5.7%  43.6%       16   5.7% 0x000000010d721a5f
      12   4.3%  47.9%       12   4.3% 0x000000010d721de8
...


运行该命令步骤)得到我:

Running that command (without any of the prior steps) gets me this:

[hidden]$ pprof --text ./a.out cpu.profile 
Using remote profile at ./a.out.
Failed to get the number of symbols from http://cpu.profile/pprof/symbol

为什么它尝试访问我的机器上的一个互联网网站和他/她的本地文​​件?

Why does it try to access an internet site on my machine and a local file on his/hers?

尝试链接lib profiler作为干运行与g ++获得我:

Attempting to link lib profiler as a dry run with g++ gets me:

[hidden]$ g++ -l libprofiler
ld: library not found for -llibprofiler
clang: error: linker command failed with exit code 1 (use -v to see invocation)

看看手册页,帮助选项文本,官方在线指南,博客文章和许多其他来源。

I have looked at the man pages, the help option text, the official online guide, blog posts, and many other sources.

我现在很困惑。有人可以帮我使用gperftools吗?

I am so confused right now. Can someone help me use gperftools?

我与@osgx交谈的结果是此脚本。我试图清理一下。

The result of my conversation with @osgx was this script. I tried to clean it up a bit. It likely contains quite a few unnecessary options too.

推荐答案

博客帖子 https://dudefrommangalore.wordpress.com/2012/02/09/ profiling-c-code-using-google-performance-tools / 使用Google Performance Tools分析C ++代码2012由dudefrommangalore错过了关键步骤。

The blog post https://dudefrommangalore.wordpress.com/2012/02/09/profiling-c-code-using-google-performance-tools/ "Profiling C++ code using Google Performance Tools" 2012 by dudefrommangalore missed the essential step.

您应该使用gperftools库的cpu profiler库来链接您要编程的程序。

You should link your program (which you want to be profiled) with cpu profiler library of gperftools library.

查看官方手册: http://goog-perftools.sourceforge .net / doc / cpu_profiler.html 部分链接到库

Check official manual: http://goog-perftools.sourceforge.net/doc/cpu_profiler.html, part "Linking in the Library"


添加 lprofiler 到您的可执行文件的链接时间步骤。 (也可以在运行时使用 LD_PRELOAD 添加分析器,但这不一定是推荐的。)

add -lprofiler to the link-time step for your executable. (It's also probably possible to add in the profiler at run-time using LD_PRELOAD, but this isn't necessarily recommended.)

第二步是收集配置文件,运行启用了分析的代码。在linux世界里,它是通过在运行之前设置控制环境变量 CPUPROFILE 来完成的:

Second step is to collect the profile, run the code with profiling enabled. In linux world it was done by setting controlling environment variable CPUPROFILE before running:

CPUPROFILE=name_of_profile ./program_to_be_profiled

第三步是使用 pprof google-pprof ubuntu world )。检查是否生成了空的 name_of_profile 配置文件;它没有这样的文件,pprof会尝试远程配置文件fetch(你看到这样输出的try)。

Third step is to use pprof (google-pprof in ubuntu world). Check that there is not-empty name_of_profile profile file generated; it there is no such file, pprof will try to do remote profile fetch (you see output of such try).

pprof ./program_to_be_profiled name_of_profile

这篇关于在Mac OS X上使用gperftools的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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