CEPS  24.01
Cardiac ElectroPhysiology Simulator
Profiler Class Reference

Detailed Description

A Chronometer used to measure execution of blocks of code, plus some methods to get current memory usage of the process.

Several blocks of code can be tracked at the same time, by providing a name to the block that is measured. Usage:

Timer t;
t.Start("block1","do things in block 1");
t.Start("block2","do things in block 2, that is part of block1");
//...
t.Stop("block2");
//...
t.Start("block2");
//...
t.Stop("block1");
t.Stop("block2");
t.Display();

The profiler log can be used to plot the memory usage. Here is an example of gnuplot script

set title "Memory usage in kB"
set style data boxes
set boxwidth 1
set style fill solid border -1
set yrange [0:*]
unset xtics
set xtics nomirror rotate by -45
plot "plop.dat" u ($0-0.5):2:xtic(1) not

Definition at line 70 of file CepsProfiler.hpp.

#include <CepsProfiler.hpp>

Public Member Functions

 Profiler ()
 Constructor. More...
 
 Profiler (const Profiler &)=delete
 Copy constructor deleted, ideally, there should be one profiler per run. More...
 
Profileroperator= (const Profiler &)=delete
 Assignment operator deleted, ideally, there should be one profiler per run. More...
 
 ~Profiler ()
 Destructor. More...
 
void start (CepsString lbl, CepsString dspl="")
 Creates or continue a labeled chronometer. More...
 
void restart (CepsString lbl)
 Resets a labeled chronometer. More...
 
void stop (CepsString lbl)
 Stops the measure of a labeled chronometer. More...
 
void display (const CepsString &lbl, std::ostream &os) const
 Prints time spent by a specific chronometer. More...
 
void display (const CepsString &lbl) const
 Prints time spent by a specific chronometer. More...
 
void display (std::ostream &) const
 Prints time spent by all chronometers. More...
 
void display () const
 Prints time spent by all chronometers. More...
 
void logMemoryUsage (const CepsString &xtic)
 Writes a line with memory usage in profiling log, xtic is used to describe what the program is currently doing. More...
 
void logMemoryUsageIf (CepsBool ifexpr, const CepsString &xtic)
 Writes a line with memory usage in profiling log if 'ifexpr' is true, xtic is used to describe what the program is currently doing. More...
 
size_t localMemoryUsage ()
 Returns an estimation of the memory taken by the current process (in kB) More...
 
size_t globalMemoryUsage ()
 Returns an estimation of the memory taken by all the MPI process (in kB) More...
 

Private Attributes

CepsMap< CepsString, CepsRealm_seconds
 Times. More...
 
CepsMap< CepsString, clock_t > m_tmpTimes
 Temp evals for times. More...
 
CepsMap< CepsString, CepsStringm_dsplStrs
 Text to display at the end of computation, typically. More...
 
CepsUInt m_maxLen
 For nice output. More...
 

Constructor & Destructor Documentation

◆ Profiler() [1/2]

Profiler::Profiler ( )

Constructor.

Definition at line 41 of file CepsProfiler.cpp.

◆ Profiler() [2/2]

Profiler::Profiler ( const Profiler )
delete

Copy constructor deleted, ideally, there should be one profiler per run.

See also
CepsObject with inline static variable

◆ ~Profiler()

Profiler::~Profiler ( )

Destructor.

Definition at line 46 of file CepsProfiler.cpp.

Member Function Documentation

◆ display() [1/4]

void Profiler::display ( ) const

Prints time spent by all chronometers.

Definition at line 98 of file CepsProfiler.cpp.

◆ display() [2/4]

void Profiler::display ( const CepsString lbl) const

Prints time spent by a specific chronometer.

Parameters
[in]lblThe name of the chronometer.

Definition at line 91 of file CepsProfiler.cpp.

◆ display() [3/4]

void Profiler::display ( const CepsString lbl,
std::ostream &  os 
) const

Prints time spent by a specific chronometer.

Parameters
[in]lblThe name of the chronometer.
[in]osoutput stream

Definition at line 82 of file CepsProfiler.cpp.

◆ display() [4/4]

void Profiler::display ( std::ostream &  os) const

Prints time spent by all chronometers.

Definition at line 105 of file CepsProfiler.cpp.

◆ globalMemoryUsage()

size_t Profiler::globalMemoryUsage ( )

Returns an estimation of the memory taken by all the MPI process (in kB)

Note
: works only currently on linux (not on centos!)

Definition at line 158 of file CepsProfiler.cpp.

◆ localMemoryUsage()

size_t Profiler::localMemoryUsage ( )

Returns an estimation of the memory taken by the current process (in kB)

Note
: works only currently on linux (not on centos!)

Definition at line 138 of file CepsProfiler.cpp.

◆ logMemoryUsage()

void Profiler::logMemoryUsage ( const CepsString xtic)

Writes a line with memory usage in profiling log, xtic is used to describe what the program is currently doing.

Definition at line 120 of file CepsProfiler.cpp.

◆ logMemoryUsageIf()

void Profiler::logMemoryUsageIf ( CepsBool  ifexpr,
const CepsString xtic 
)

Writes a line with memory usage in profiling log if 'ifexpr' is true, xtic is used to describe what the program is currently doing.

Definition at line 130 of file CepsProfiler.cpp.

◆ operator=()

Profiler& Profiler::operator= ( const Profiler )
delete

Assignment operator deleted, ideally, there should be one profiler per run.

See also
CepsObject with inline static variable

◆ restart()

void Profiler::restart ( CepsString  lbl)

Resets a labeled chronometer.

Parameters
[in]lblThe name of the chronometer.

Definition at line 66 of file CepsProfiler.cpp.

◆ start()

void Profiler::start ( CepsString  lbl,
CepsString  dspl = "" 
)

Creates or continue a labeled chronometer.

Parameters
[in]lblThe name of the chronometer.
[in]dsplThe CepsString that will be displayed when printing results.

If the chronometer already exists, execution time will be added. (Start acts like continue)

Definition at line 51 of file CepsProfiler.cpp.

◆ stop()

void Profiler::stop ( CepsString  lbl)

Stops the measure of a labeled chronometer.

Parameters
[in]lblThe name of the chronometer.

Definition at line 74 of file CepsProfiler.cpp.

Field Documentation

◆ m_dsplStrs

CepsMap<CepsString,CepsString> Profiler::m_dsplStrs
private

Text to display at the end of computation, typically.

Definition at line 169 of file CepsProfiler.hpp.

◆ m_maxLen

CepsUInt Profiler::m_maxLen
private

For nice output.

Definition at line 170 of file CepsProfiler.hpp.

◆ m_seconds

CepsMap<CepsString,CepsReal> Profiler::m_seconds
private

Times.

Definition at line 167 of file CepsProfiler.hpp.

◆ m_tmpTimes

CepsMap<CepsString,clock_t> Profiler::m_tmpTimes
private

Temp evals for times.

Definition at line 168 of file CepsProfiler.hpp.


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