How to use KCachegrind and Callgrind to measure only parts of my code?

I want to use valgrind to parse my code. The problem is that I have a huge startup sequence that doesn't interest me.

I found definitions in valgrind / callgrind.h which should help me:

  • CALLGRIND_START_INSTRUMENTATION
  • CALLGRIND_STOP_INSTRUMENTATION
  • CALLGRIND_DUMP_STATS

According to this article , I have to execute valgrind with the following parameters:

valgrind --tool=callgrind --instr-atstart=no ./application

When I do this, two files are created:

  • callgrind.out.16060
  • callgrind.out.16060.1

Then I want to use kcachegrind to visualize my results. This works fine, but the macros to skip my startup sequence do not seem to do anything. What do I need to do to measure performance only in the places where I want?

+4
source share
1 answer

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 many subsystems. In my initial attempt, I tried to measure performance inside the application as follows:

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;
}

- , , configure() ComplexSystem.

, , , , :

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;
}

, , .

0

Source: https://habr.com/ru/post/1609947/


All Articles