SEARCH
TOOLBOX
LANGUAGES
How to log time

How to log time

From SOFAWiki

Jump to: navigation, search
How to log time

Presentation of the different ways to log the time spent.

Contents

Simple Timer

TODO

Advanced Timer

A way to get the time spent on different parts of the code is to use the Advanced Timer. About what that timer does and how, have a look to $SOFA/framework/sofa/helper/AdvancedTimer.h.

To activate AdvancedTimer, you have to set an environment variable called SOFA_TIMER_XX to the period at which timing results should be written to the console, where XX is the name of the timer as set in the AdvancedTimer begin and end calls.

As an example, if you want to activate the "Animate" timer (i.e. the one used for each timestep within Simulation::animate()), use:

export SOFA_TIMER_Animate=100

Trace Visitor

A graphic tool using Qt exists, and is integrated inside the Sofa main application to trace and profile the execution of the visitors in Sofa. How to use the graphic trace of visitors

How to enable the trace of the visitors

You need to activate the option SOFA_DUMP_VISITOR_INFO in your sofa configuration. It should be enabled by default. If not, you can use SofaVerification to modify the configuration of Sofa. Image:TraceVisitorLogTime.png

Quickly find information

To find a specific visitor, or a call to a component, you can use the search bar:

Image:TraceVisitorLogTime_Focus.png

View State vectors

An other interesting feature is the possibility to trace the evolution of the state vectors: Just enable the option, and specify the number of particles; -1 meaning all the particles Image:TraceVisitorLogTime_Vector.png

Here, we trace the particles numero 2 and 3. A FixedConstraint acts in this scene on the particle 3: it filters its velocity and acceleration, and set it to zero, to act as a fixed particle. We can visualize the effect of the ApplyConstraint visitor on the state vector.

Add new debug information

Trace specific part of the code

To trace and profile the execution of a part of your program, put, at the beginning of the code to profile:

simulation::Visitor::printNode("NameMethod");

and at end the process

simulation::Visitor::printCloseNode("NameMethod");

The method printNode can take other arguments to get a more detailed log;

sofa::simulation::Visitor::TRACE_ARGUMENT arg;
arg.push_back(std::make_pair("ArgumentName", "Value"));
sofa::simulation::Visitor::printNode("MyDebug", arg);
//....
sofa::simulation::Visitor::printCloseNode("MyDebug");

Trace an additional state vector

At any time in your code, you can monitor a state vector of a given mechanical state writting:

if (sofa::simulation::Visitor::IsExportStateVectorEnabled())
{
   sofa::simulation::Visitor::printNode("MyDebug");
   sofa::simulation::Visitor::printVector(mstate, id); //mstate is a ptr to a mechanical state, id is a VecId, indicating the state vector
   sofa::simulation::Visitor::printCloseNode("MyDebug");
}