hpp-centroidal-dynamics: Stopwatch Class Reference

hpp-centroidal-dynamics 9.0.2 Utility classes for testing (robust) equilibrium of a system in contact with the environment, and other centroidal dynamics methods.

Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Attributes | List of all members
Stopwatch Class Reference

A class representing a stopwatch. More...

`#include <hpp/centroidal-dynamics/stop-watch.hh>`

## Classes
struct | PerformanceData

## Public Member Functions
| Stopwatch (StopwatchMode _mode=NONE)
| ~Stopwatch ()
bool | performance_exists (std::string perf_name)
void | set_mode (StopwatchMode mode)
void | start (std::string perf_name)
void | stop (std::string perf_name)
void | pause (std::string perf_name)
void | reset (std::string perf_name)
void | reset_all ()
void | report (std::string perf_name, int precision=2, std::ostream &output=std::cout)
void | report_all (int precision=2, std::ostream &output=std::cout)
long double | get_total_time (std::string perf_name)
long double | get_average_time (std::string perf_name)
long double | get_min_time (std::string perf_name)
long double | get_max_time (std::string perf_name)
long double | get_last_time (std::string perf_name)
long double | get_time_so_far (std::string perf_name)
void | turn_off ()
void | turn_on ()
long double | take_time ()

## Protected Attributes
bool | active
StopwatchMode | mode
std::map< std::string, PerformanceData > * | records_of

## Detailed Description

A class representing a stopwatch.

Stopwatch swatch();
Stopwatch
A class representing a stopwatch.
Definition stop-watch.hh:142

The Stopwatch class can be used to measure execution time of code, algorithms, etc., // TODO: he Stopwatch can be initialized in two time-taking modes, CPU time and real time:

swatch.set_mode(REAL_TIME);
REAL_TIME
@ REAL_TIME
Definition stop-watch.hh:47

CPU time is the time spent by the processor on a certain piece of code, while real time is the real amount of time taken by a certain piece of code to execute (i.e. in general if you are doing hard work such as image or video editing on a different process the measured time will probably increase).

How does it work? Basically, one wraps the code to be measured with the following method calls:

swatch.start("My astounding algorithm");
// Hic est code
swatch.stop("My astounding algorithm");

A string representing the code ID is provided so that nested portions of code can be profiled separately:

swatch.start("My astounding algorithm");
swatch.start("My astounding algorithm - Super smart init");
// Initialization
swatch.stop("My astounding algorithm - Super smart init");
swatch.start("My astounding algorithm - Main loop");
// Loop
swatch.stop("My astounding algorithm - Main loop");
swatch.stop("My astounding algorithm");

Note: ID strings can be whatever you like, in the previous example I have used "My astounding algorithm - *" only to enforce the fact that the measured code portions are part of My astounding algorithm, but there's no connection between the three measurements.

If the code for a certain task is scattered through different files or portions of the same file one can use the start-pause-stop method:

swatch.start("Setup");
// First part of setup
swatch.pause("Setup");
swatch.start("Main logic");
// Main logic
swatch.stop("Main logic");
swatch.start("Setup");
// Cleanup (part of the setup)
swatch.stop("Setup");

Finally, to report the results of the measurements just run:

swatch.report("Code ID");

Thou can also provide an additional std::ostream& parameter to report() to redirect the logging on a different output. Also, you can use the get_total/min/max/average_time() methods to get the individual numeric data, without all the details of the logging. You can also extend Stopwatch to implement your own logging syntax.

To report all the measurements:

swatch.report_all();

Same as above, you can redirect the output by providing a std::ostream& parameter.

## Constructor & Destructor Documentation

## ◆ Stopwatch()

Stopwatch::Stopwatch | ( | StopwatchMode | _mode = NONE | ) |

Constructor

## ◆ ~Stopwatch()

Stopwatch::~Stopwatch | ( |  | ) |

Destructor

## Member Function Documentation

## ◆ get_average_time()

long double Stopwatch::get_average_time | ( | std::string | perf_name | ) |

Returns average execution time of a certain performance

## ◆ get_last_time()

long double Stopwatch::get_last_time | ( | std::string | perf_name | ) |

Return last measurement of a certain performance

## ◆ get_max_time()

long double Stopwatch::get_max_time | ( | std::string | perf_name | ) |

Returns maximum execution time of a certain performance

## ◆ get_min_time()

long double Stopwatch::get_min_time | ( | std::string | perf_name | ) |

Returns minimum execution time of a certain performance

## ◆ get_time_so_far()

long double Stopwatch::get_time_so_far | ( | std::string | perf_name | ) |

Return the time since the start of the last measurement of a given performance.

## ◆ get_total_time()

long double Stopwatch::get_total_time | ( | std::string | perf_name | ) |

Returns total execution time of a certain performance

## ◆ pause()

void Stopwatch::pause | ( | std::string | perf_name | ) |

Stops the stopwatch related to a certain piece of code

## ◆ performance_exists()

bool Stopwatch::performance_exists | ( | std::string | perf_name | ) |

Tells if a performance with a certain ID exists

## ◆ report()

void Stopwatch::report | ( | std::string | perf_name,
|  | int | precision = 2,
|  | std::ostream & | output = std::cout )

Dump the data of a certain performance record

## ◆ report_all()

void Stopwatch::report_all | ( | int | precision = 2,
|  | std::ostream & | output = std::cout )

Dump the data of all the performance records

## ◆ reset()

void Stopwatch::reset | ( | std::string | perf_name | ) |

Reset a certain performance record

## ◆ reset_all()

void Stopwatch::reset_all | ( |  | ) |

Resets all the performance records

## ◆ set_mode()

void Stopwatch::set_mode | ( | StopwatchMode | mode | ) |

Initialize stopwatch to use a certain time taking mode

## ◆ start()

void Stopwatch::start | ( | std::string | perf_name | ) |

Start the stopwatch related to a certain piece of code

## ◆ stop()

void Stopwatch::stop | ( | std::string | perf_name | ) |

Stops the stopwatch related to a certain piece of code

## ◆ take_time()

long double Stopwatch::take_time | ( |  | ) |

Take time, depends on mode

## ◆ turn_off()

void Stopwatch::turn_off | ( |  | ) |

Turn off clock, all the Stopwatch::* methods return without doing anything after this method is called.

## ◆ turn_on()

void Stopwatch::turn_on | ( |  | ) |

Turn on clock, restore clock operativity after a turn_off().

## Member Data Documentation

## ◆ active

bool Stopwatch::active
| protected

Flag to hold the clock's status

## ◆ mode

StopwatchMode Stopwatch::mode
| protected

Time taking mode

## ◆ records_of

std::map<std::string, PerformanceData>* Stopwatch::records_of
| protected

Pointer to the dynamic structure which holds the collection of performance data

The documentation for this class was generated from the following files:

- include/hpp/centroidal-dynamics/stop-watch.hh
- src/stop-watch.cpp