如何使用KCachegrind和Callgrind只测量我的代码的一部分? [英] How to use KCachegrind and Callgrind to measure only parts of my code?
问题描述
我想使用 valgrind 来分析我的代码。问题是,我有一个巨大的启动序列,我不感兴趣。
我在 valgrind / callgrind.h
根据本文我必须使用以下选项执行 valgrind :
valgrind --tool = callgrind --instr-atstart = no ./application
当创建这两个文件时, p>
- callgrind.out.16060
- callgrind.out.16060.1
然后我想使用kcachegrind可视化我的结果。这工作很好,但是我的启动顺序跳过的makros似乎什么也没做。
现在我已经知道了, '不是100%肯定为什么。我将尝试描述我的代码有点:
我有一个Application类,负责很多子系统。在我最初的尝试中,我试图测量应用程序内的性能,如下所示:
int main(int argc,char * argv [ ])
{
应用程序a(argc,argv);
return a.exec();
}
void Application :: Application(int& argc,char ** argv)
{
m_pComplexSystem = new ComplexSystem
m_pComplexSystem-> configure();
CALLGRIND_START_INSTRUMENTATION;
m_Configurator-> start();
}
应用程序::〜Application()
{
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
m_pComplexSystem - > stop();
delete m_pComplexSystem;
m_pComplexSystem = 0;
}
由于某些原因,定义被忽略,我得到了整体的性能度量构造函数和在ComplexSystem成员的configure()调用中完成的一切。
现在我使用这个似乎工作的代码:
int main(int argc,char * argv [])
{
应用程序(argc,argv);
CALLGRIND_START_INSTRUMENTATION;
int result = a.exec();
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
return result;
}
虽然它与我原来的尝试不完全一样,适用于慢速功能。
I want to use valgrind to analyze my code. The problem is, that I have a huge startup sequence which I'm not interested in.
I found defines in the valgrind/callgrind.h that should help me:
- CALLGRIND_START_INSTRUMENTATION
- CALLGRIND_STOP_INSTRUMENTATION
- CALLGRIND_DUMP_STATS
According to this article I have to execute valgrind with the following options:
valgrind --tool=callgrind --instr-atstart=no ./application
When I do this two files are created:
- callgrind.out.16060
- callgrind.out.16060.1
I then want to use kcachegrind to visualize my results. This works great but the makros for the skipping of my startup-sequence seem to do nothing. What do I have to do to measure the performance only in places where I want to?
I got it now, but I'm not 100% sure why. I will try to describe my code a bit:
I have an Application class that is responsible for a lot of subsystems. In my original attempt I tried to measure the performance inside the Application like this:
int main(int argc, char *argv[])
{
Application a(argc, argv);
return a.exec();
}
void Application::Application(int &argc, char **argv)
{
m_pComplexSystem = new ComplexSystem();
m_pComplexSystem->configure();
CALLGRIND_START_INSTRUMENTATION;
m_Configurator->start();
}
Application::~Application()
{
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
m_pComplexSystem ->stop();
delete m_pComplexSystem;
m_pComplexSystem = 0;
}
For some reason the defines were ignored and I got the performance measures of the whole constructor and everything that was done in the configure() call of the ComplexSystem member.
So now I use this code that seems to work:
int main(int argc, char *argv[])
{
Application a(argc, argv);
CALLGRIND_START_INSTRUMENTATION;
int result = a.exec();
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS;
return result;
}
Although it is not exactly the same as my original attempt, I can start looking for slow functions now.
这篇关于如何使用KCachegrind和Callgrind只测量我的代码的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!