Skip to content
Nils Brinkmann edited this page Apr 25, 2014 · 3 revisions

CxxProf is a manual instrumented Profiling library for C++. This means you add specific measure points to your code in order to test its performance. It differs from sampling profilers, which in general collect data about your whole application.

The strength of instrumented profilers come into play when you have complex applications whose profiling generate a lot of data. CxxProf provides ways to visualize these data in a way where it is easy to keep a good overview and see potential ressource hogs easily.

##Goals

  • Easy integration: It just takes a few steps to integrate CxxProf into your project. See the integration-guide for how easy it is.

  • Easily remove the lib during compile time: The interface of CxxProf is macro-based. If you do not define USECXXPROF these macros will be empty and your compiler will take care of not having a single code of CxxProf in your project.

  • Easily remove the lib during runtime: You're compiling your software with a static library of CxxProf (called cxxprof_static for that reason). This library does not do anything more as providing the interface and loading a CxxProf-plugin with all the functionality. If this plugin is not available, cxxprof_static will do nothing but returning from all methods you call on it. Contrary to USECXXPROF this method keeps some overhead, but it's kept at a minimum and allows you to change whether your profiling or not at runtime.

  • Support for multithreaded applications: CxxProf stores information about which thread is profiling which activities. This way you can see how your threads interact with each other.

  • Support for distributed systems: The collected data is sent to a central server where it is stored and can be examined. By doing this CxxProf is able to receive data from several applications and showing it alongside of each other. That way it is possible to profile your networked software and what data causes which events.

  • Keep impact on a minimum: To not change the environment which should be profiled CxxProf tries to keep the impact on its hosting software on a minimum. All the above goals are implemented with the best performance and least overhead possible.

##What does it provide?

Activities

The main part of CxxProf are its Activities. These define sections which are measured. As soon as the context of where the Activity has been created is over, the measurement will be taken and stored.

The following code-snippet will create an Activity which measures the main function and another one which measures just an if-statement:

#include <cxxprof_static/CxxProf.h>

int main()
{
    CXXPROF_ACTIVITY("main");

    if(somethingIsTrue)
    {
        CXXPROF_ACTIVITY("main::somethingIsTrue");
        doSomething();
    }

    return 0;
}

Marks

To define when a certain state of an application is reached it is possible to define marks. A good example would be a video game where marks are set to see where the initialization stops and the gameloop begins:

#include "cxxprof_static/CxxProf.h"

int main()
{
    CXXPROF_MARK("Game Initialization");
    initSounds();
    initModels();
    initEngine();
    
    CXXPROF_MARK("Game Loop");
    while(true)
    {
        updateGame();
    }
    
    return 0;
}

Plots

It sometimes is useful to see how the application develops in reference to something measurable. In a game this could be the update times of the AI in reference to how many units are used:

#include "cxxprof_static/CxxProf.h"

int main()
{
    while(gameloopActive)
    {
        CXXPROF_PLOT("NumUnits", getUnitCount());
        updateAI();
    }
    
    return 0;
}