Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Profiling

Malte Langkabel edited this page Nov 26, 2019 · 1 revision

Profiling the Sourcetrail applicationwith the use of external tools can quickly become impractical due to the large amount of gathered data that slows down the used machine. Thus, we implemented our own macro based profiling with the TRACE() macro, that you can enable on demand and use on the desired parts of the code.

To enable tracing for your build, uncomment the following line in the tracing.h file

#define TRACING_ENABLED

Now you can use the TRACE() macro in any scope of your choice and it will track the time from hitting that line of code until the end of the respecting scope.

After building you can start Sourcetrail and press the space bar to print all recorded traces to the console.

TRACING
--------------------------

HISTORY:

    time                 name                     function                                          location
-----------------------------------------------------------------------------------------------------------------------------
thread: 6816
   0.015                 app refresh              Application::handleMessage()                      application.cpp:326
   0.000                                          PersistentStorage::getFileInfoForAllFiles()       persistentstorage.cpp:416
   0.001                                          PersistentStorage::getReferencing()               persistentstorage.cpp:377
   0.001                                          PersistentStorage::getReferenced()                persistentstorage.cpp:366
   0.001                                          PersistentStorage::getReferenced()                persistentstorage.cpp:366


REPORT:

    time      count      name                     function                                          location
-----------------------------------------------------------------------------------------------------------------------------
   0.015         1       app refresh              Application::handleMessage()                      application.cpp:326
   0.002         2                                PersistentStorage::getReferenced()                persistentstorage.cpp:366
   0.001         1                                PersistentStorage::getReferencing()               persistentstorage.cpp:377
   0.000         1                                PersistentStorage::getFileInfoForAllFiles()       persistentstorage.cpp:416

Pressing the space bar again will print the traces that have been recorded since the last time you printed the list.

TRACING: No trace events collected.

You can also uncomment the following line in the tracing.h file:

#define USE_ACCUMULATED_TRACING

This will only print the accumulated list of TRACE()s, which may be desired behavior if a lot of individual trace events have been recorded that would otherwise take ages to print:

REPORT:

    time      count      name                     function                                          location
-----------------------------------------------------------------------------------------------------------------------------
   0.010         1       app refresh              Application::handleMessage()                      application.cpp:326
   0.002         2                                PersistentStorage::getReferenced()                persistentstorage.cpp:366
   0.001         1                                PersistentStorage::getReferencing()               persistentstorage.cpp:377
   0.000         1                                PersistentStorage::getFileInfoForAllFiles()       persistentstorage.cpp:416
Clone this wiki locally