标签: gperftools

如何使用谷歌perf工具

我刚开始使用谷歌性能工具(google-perftools以及libgoogle-perftools4ubuntu中的软件包),我发誓我正在谷歌上搜索一天,我没有找到答案!问题是我没有通过CPU分析获得所有函数的结果.这是我的代码:

#include "gperftools/profiler.h"
#include <iostream>
#include <math.h>
using namespace std;
void bar()
{
        int a,b,c,d,j,k;
        a=0;
        int z=0;
        b = 1000;
        while(z < b)
        {
                while (a < b)
                {
                        d = sin(a);
                        c = cos(a);
                        j = tan(a);
                        k = tan(a);
                        k = d * c + j *k;
                        a++;
                }
                a = 0;
                z++;
        }
}
void foo()
{
        cout << "hey " << endl;
}

int main()
{
        ProfilerStart("/home/mohammad/gperf/dump.txt");

        int a = 1000; …
Run Code Online (Sandbox Code Playgroud)

profiling gperftools

9
推荐指数
1
解决办法
2万
查看次数

gperftools CPU Profiler到底是怎么开始的?

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

$ gcc myprogram.c -lprofiler
Run Code Online (Sandbox Code Playgroud)

(不改变程序代码).

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

CPUPROFILE=/tmp/profiler_output ./a.out
Run Code Online (Sandbox Code Playgroud)

问题是:libprofile当仅仅加载探测器时,如何有机会启动和完成探查器,但是它的功能没有被调用?

该库中没有构造函数(证明). 库代码中"CPUPROFILE"的所有情况都不会引用启动分析器的任何位置.

我没有想法,在哪里看下一个?

linker gcc dynamic-linking google-perftools gperftools

9
推荐指数
1
解决办法
4852
查看次数

C++性能分析(谷歌cpu性能工具)到底测量的是什么?

我试图开始使用Google Perf Tools来分析一些CPU密集型应用程序.这是一个统计计算,使用`ofstream'将每个步骤转储到文件中.我不是C++专家,所以我遇到麻烦找到瓶颈.我的第一次传球给出结果:

Total: 857 samples
     357  41.7%  41.7%      357  41.7% _write$UNIX2003
     134  15.6%  57.3%      134  15.6% _exp$fenv_access_off
     109  12.7%  70.0%      276  32.2% scythe::dnorm
     103  12.0%  82.0%      103  12.0% _log$fenv_access_off
      58   6.8%  88.8%       58   6.8% scythe::const_matrix_forward_iterator::operator*
      37   4.3%  93.1%       37   4.3% scythe::matrix_forward_iterator::operator*
      15   1.8%  94.9%       47   5.5% std::transform
      13   1.5%  96.4%      486  56.7% SliceStep::DoStep
      10   1.2%  97.5%       10   1.2% 0x0002726c
       5   0.6%  98.1%        5   0.6% 0x000271c7
       5   0.6%  98.7%        5   0.6% _write$NOCANCEL$UNIX2003

这是令人惊讶的,因为所有真正的计算都发生在SliceStep :: DoStep中."_write $ UNIX2003"(我在哪里可以找到它是什么?)似乎来自编写输出文件.现在,让我感到困惑的是,如果我注释掉所有outfile << "text" …

c++ profiling gperftools

8
推荐指数
1
解决办法
1835
查看次数

gperftools cpu profiler不支持多进程?

根据文档http://gperftools.googlecode.com/svn/trunk/doc/cpuprofile.html,cpu配置文件支持多进程并将生成独立的输出文件:

如果您的程序分叉,子项也将被分析(因为它们继承了相同的CPUPROFILE设置).每个过程都是单独分析的; 为了区分子配置文件与父配置文件以及彼此之间的所有子配置,所有子节点都将其process-id附加到CPUPROFILE名称.

但是当我尝试如下:

// main_cmd_argv.cpp

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <gperftools/profiler.h>

int loop(int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            sum = i + j;
            if (sum %3 == 0) {
                sum /= 3;
            }
        }
    }
    return 0;
}

int main(int argc, char* argv[]) {

    printf("%s\n%s\n", getenv("CPUPROFILE"), getenv("CPUPROFILESIGNAL"));

    if …
Run Code Online (Sandbox Code Playgroud)

linux profiling google-perftools gperftools

7
推荐指数
1
解决办法
1768
查看次数

gperftools如何在引擎盖下工作?

我正在寻找一个关于gperftools如何工作的简单解释.到目前为止,这是我所学到的:

  • 它运行一个世界各地的采样器.换句话说,它会定期停止正在分析的程序以收集信息.
  • Golang的pprof库使用下面的gperftools.

除了一般概述,以下是我想回答的一些具体问题:

  • gperftools是" 基于事件的分析器 "还是" 仪器分析器 ".据我所知,这些分析器修改程序运行的方式并通过这些修改收集样本
  • 在操作系统的"级别"中,gperftools的配置文件是什么?它是否像SystemTapperf一样描述核心?
  • gperftools可以安全地在高流量的生产服务器上运行吗?

我问这个问题来推断在Go服务器上使用pprof引入的开销.

google-perftools gperftools pprof

7
推荐指数
1
解决办法
773
查看次数

使用pprof和gperftools会导致卷曲错误

所以我一直在做以下事情:

$ pprof /bin/ls ls.prof
Using local file /bin/ls.
Gathering CPU profile from http://ls.prof/pprof/profile?seconds=30 for 30 seconds to
  /home/user/csteifel/pprof/ls.1414597606.ls.prof
Be patient...

curl: (7) couldn't connect to host
Failed to get profile: curl 'http://ls.prof/pprof/profile?seconds=30' > /home/user/csteifel/pprof/.tmp.ls.1414597606.ls.prof: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我不确定这里是什么,因为这是他们在这里展示的一个例子:http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html

现在我明白ls实际上不会有信息,但我也知道它不应该给我一个关于curl的错误,在这种情况下它应该是别的东西.我在这做错了什么?

我也尝试过这样做我创建的示例程序(例如:pprof --callgrind /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf ~/testing2/prof.out > callgrind.out我得到一个类似的错误:

Using local file /home/user/csteifel/testing2/X86_64_DEBUG/el6/wtf.
Use of uninitialized value $host in substitution (s///) at /home/user/csteifel/usr/local/lib/bin/pprof line 3195.
Use of uninitialized value $hostport in concatenation (.) or …
Run Code Online (Sandbox Code Playgroud)

profiling gperftools pprof

6
推荐指数
1
解决办法
2902
查看次数

如何正确处理信号,以便gperftools CPU Profiler仍然有效?

我想描述我的守护程序,它暂停主线程:

sigset_t signal_mask;
sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGTERM);
sigaddset(&signal_mask, SIGINT);

int sig;
sigwait(&signal_mask, &sig);
Run Code Online (Sandbox Code Playgroud)

所有其他线程只是阻止所有信号.据我所知,探查器使用SIGPROF信号进行操作.如果我使用这样的代码开始分析,则输出.prof文件为空:

env CPUPROFILE = daemon.prof ./daemon

我应该如何正确处理主线程和其他线程中的信号以启用性能分析?或者可能是其他地方的问题?

c++ profiler multithreading signals gperftools

5
推荐指数
1
解决办法
851
查看次数

'f'后缀对C++库名称的含义是什么?如何加载它?

我正在使用gperftools v2.3rc,并希望使用改进的线程分析功能.发行说明部分说明:

现在实现了Linux上的新cpu分析模式.它为单独的线程设置单独的分析定时器.... [它]是,如果同时启用librt.f被加载并CPUPROFILE_PER_THREAD_TIMERS环境变量设置....

我的C++应用程序与librt.so(-lrt - POSIX.1b Realtime Extensions库)链接,但我之前没有听说过带有.f后缀的库..f意味着什么,我在哪里可以找到这个库,以及如何在我的应用程序中加载它?

c++ posix real-time gperftools

5
推荐指数
1
解决办法
244
查看次数

我在探查器输出中看到的 __nss_passwd_lookup() 调用是什么?

我正在使用gperftools来分析一个 C++ 应用程序,该应用程序是使用 GCC 5.4.0(使用 -O3)编译的。

代码高度优化,所以我在输出中没有看到很多分支,但是有一个名为__nss_passwd_lookup()的分支,它需要大量时间:

在此处输入图片说明

我唯一的猜测是它以某种方式与内存分配有关。

操作系统:Ubuntu 16.04 x86_64,内核:4.8。

c++ linux linux-kernel gperftools

5
推荐指数
1
解决办法
1553
查看次数

如何分析 Rcpp 代码(在 linux 上)

我用 Rcpp 制作了一个 R 包,其中整个模拟在 C++ 中运行,结果在 R 中分析。现在我需要分析我的函数,以便我可以优化它们,但 R 分析器无法区分 C++ 函数内部发生了什么,我当函数只能从 R 内部运行时,不知道如何运行 C++ 分析器。

到目前为止,我已经找到了一些使用 gperftools 的建议(问题教程),但指南不完整(也许他们假设我缺乏一定的知识水平?),缺少链接,我一直在撞墙。因此这个问题。这是我所在的位置:

  1. 安装 gperftools(我用 pacman 从 extra/gperftools 安装)
  2. 在 C++ 头文件中包含 gperftools/profiler.h
  3. 在我想要分析的 C++ 代码中添加 ProfilerStart("myprof.log") 和 ProfilerStop()
  4. 使用 -lprofiler 编译
  5. 运行 "$ CPUPROFILE="myprof.log" R -f myscript.R"

当前的墙是 gcc 告诉我“未定义符号:ProfilerStart”,所以我认为链接有问题?

c++ profiling r rcpp gperftools

5
推荐指数
1
解决办法
921
查看次数