Fro*_*zan 5 c++ valgrind callgrind kcachegrind
我想使用valgrind来分析我的代码。问题是,我有一个我不感兴趣的巨大启动序列。
我在valgrind/callgrind.h中找到了应该对我有帮助的定义:
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:
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?
我现在明白了,但我不是 100% 确定为什么。我将尝试描述一下我的代码:
我有一个 Application 类,它负责很多子系统。在我最初的尝试中,我尝试像这样测量应用程序内部的性能:
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;
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,定义被忽略,我得到了整个构造函数的性能测量以及在 ComplexSystem 成员的 configure() 调用中完成的所有操作。
所以现在我使用这段似乎有效的代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
虽然它与我最初的尝试并不完全相同,但我现在可以开始寻找慢速函数了。
| 归档时间: |
|
| 查看次数: |
1064 次 |
| 最近记录: |