Callgrind:分析我的代码的特定部分 [英] Callgrind: Profile a specific part of my code

查看:95
本文介绍了Callgrind:分析我的代码的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试(通过Callgrind)通过消除不需要的噪声和计算来分析代码的特定部分。
这是我要执行的操作的示例:

I'm trying to profile (with Callgrind) a specific part of my code by removing noise and computation that I don't care about. Here is an example of what I want to do:

for (int i=0; i<maxSample; ++i) {
    //Prepare data to be processed...
    //Method to be profiled with these data
    //Post operation on the data
}

我的用例是回归测试,我想确保所讨论的方法仍然足够快(自上次实施以来,不到10%的额外指令)。
这就是为什么我要使用更干净的Callgrind输出形式。
(我需要一个for循环,以便处理大量数据,以便对要分析的方法的行为进行良好的估计)

My use-case is a regression test, I want to make sure that the method in question is still fast enough (something like less than 10% extra instructions since the last implementation). This is why I'd like to have the cleaner output form Callgrind. (I need a for loop in order to have a significant amount of data processed in order to have a good estimation of the behavior of the method I want to profile)

我的第一次尝试是将代码更改为:

My first try was to change the code to:

for (int i=0; i<maxSample; ++i) {
    //Prepare data to be processed...
    CALLGRIND_START_INSTRUMENTATION;
    //Method to be profiled with these data
    CALLGRIND_STOP_INSTRUMENTATION;
    //Post operation on the data
}
CALLGRIND_DUMP_STATS;

添加Callgrind宏来控制检测。我还添加了--instr-atstart = no选项,以确保仅对我想要的部分代码进行配置...

Adding the Callgrind macros to control the instrumentation. I also added the --instr-atstart=no options to be sure that I profile only the part of the code I want...

不幸的是,当我使用此配置时开始使用callgrind启动我的可执行文件,但它永远不会结束...这不是缓慢的问题,因为完整的仪器运行持续不到一分钟。

Unfortunately with this configuration when I start to launch my executable with callgrind, it never ends... It is not a question of slowness, because a full instrumentation run last less than one minute.

我还

for (int i=0; i<maxSample; ++i) {
    //Prepare data to be processed...
    CALLGRIND_TOGGLE_COLLECT;
    //Method to be profiled with these data
    CALLGRIND_TOGGLE_COLLECT;
    //Post operation on the data
}
CALLGRIND_DUMP_STATS;

(或--toggle-collect = myMethod选项)
但Callgrind返回了我没有任何调用的日志(KCachegrind像雪一样白:(并说零指令...)

(or the --toggle-collect="myMethod" option) But Callgrind returned me a log without any call (KCachegrind is white as snow :( and says zero instructions...)

我正确使用了宏/选项吗?我需要进行更改才能获得预期的结果?

Did I use the macros/options correctly? Any idea of what I need to change in order to get the expected result?

推荐答案

我终于设法解决了这个问题...配置问题:

I finally managed to solve this issue... This was a config issue:

我保留了代码

for (int i=0; i<maxSample; ++i) {
    //Prepare data to be processed...
    CALLGRIND_TOGGLE_COLLECT;
    //Method to be profiled with these data
    CALLGRIND_TOGGLE_COLLECT;
    //Post operation on the data
}
CALLGRIND_DUMP_STATS;

但是使用-collect-atstart = no (并且没有--instr-atstart = no !!!)运行callgrind,它在合理的时间内(〜1分钟)完美运行。

But ran the callgrind with --collect-atstart=no (and without the --instr-atstart=no!!!) and it worked perfectly, in a reasonable time (~1min).

START /问题STOP工具是callgrind在每次迭代(每次STOP)时都转储一个文件(callgrind.out。#number),因此它真的很慢...(5分钟后,我只进行了5000次运行30万次迭代的基准测试...不适合进行回归测试)。

The issue with START/STOP instrumentation was that callgrind dumps a file (callgrind.out.#number) at each iteration (each STOP) thus it was really really slow... (after 5min I had only 5000 runs for a 300 000 iterations benchmark... unsuitable for a regression test).

这篇关于Callgrind:分析我的代码的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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