CGRA-ME
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ChronoSequence Struct Reference

#include <CodeProfiling.h>

Inheritance diagram for ChronoSequence:
PrintOnDestructionChronoSequence

Classes

struct  TickResult
 

Public Types

using Clock = std::chrono::steady_clock
 
using TimePoint = std::chrono::time_point< Clock >
 
using TimeEntry = std::pair< std::string, TimePoint >
 

Public Member Functions

 ChronoSequence (std::string sequence_name)
 
virtual ~ChronoSequence ()=default
 
auto now () const
 
TimeEntry makeNowTick (std::string timepoint_name) const
 
TickResult tick (std::string timepoint_name, double threshold=0.0, std::ostream *os=nullptr)
 
void printTo (std::ostream &os) const
 
void printEntry (const TimeEntry &entry, const TimeEntry &previous, std::ostream &os, std::ptrdiff_t name_width=0) const
 
double getTotal ()
 
double secondsSinceStart ()
 

Static Public Member Functions

static double differenceAsSecondFraction (const TimePoint &start, const TimePoint &end)
 

Protected Member Functions

void recordTick (TimeEntry new_entry, std::ostream *os)
 

Protected Attributes

std::string sequence_name
 
std::vector< TimeEntrytimes
 

Friends

std::ostream & operator<< (std::ostream &os, const ChronoSequence &cs)
 

Detailed Description

For taking timing measurements of a large piece of code, especially with multiple sections.

Ex. ChronoSequence timing_seq("my sequence"); std::this_thread::sleep_for(std::chrono::seconds(4)); timing_seq.tick("takes 4 seconds"); std::this_thread::sleep_for(std::chrono::seconds(2)); timing_seq.tick("takes 2 seconds"); std::cout << timing_seq << '
';

// prints something like: // start of my sequence +0.000000 @0.000000 // takes 4 seconds +4.000000 @4.000000 // takes 2 seconds +2.000000 @6.000000

Definition at line 26 of file CodeProfiling.h.

Member Typedef Documentation

◆ Clock

using ChronoSequence::Clock = std::chrono::steady_clock

Definition at line 27 of file CodeProfiling.h.

◆ TimeEntry

using ChronoSequence::TimeEntry = std::pair<std::string, TimePoint>

Definition at line 29 of file CodeProfiling.h.

◆ TimePoint

using ChronoSequence::TimePoint = std::chrono::time_point<Clock>

Definition at line 28 of file CodeProfiling.h.

Constructor & Destructor Documentation

◆ ChronoSequence()

ChronoSequence::ChronoSequence ( std::string  sequence_name)
inline

Definition at line 37 of file CodeProfiling.h.

◆ ~ChronoSequence()

virtual ChronoSequence::~ChronoSequence ( )
virtualdefault

Member Function Documentation

◆ differenceAsSecondFraction()

static double ChronoSequence::differenceAsSecondFraction ( const TimePoint start,
const TimePoint end 
)
inlinestatic

Definition at line 68 of file CodeProfiling.h.

◆ getTotal()

double ChronoSequence::getTotal ( )
inline

Definition at line 93 of file CodeProfiling.h.

◆ makeNowTick()

TimeEntry ChronoSequence::makeNowTick ( std::string  timepoint_name) const
inline

Definition at line 47 of file CodeProfiling.h.

◆ now()

auto ChronoSequence::now ( ) const
inline

Definition at line 46 of file CodeProfiling.h.

◆ printEntry()

void ChronoSequence::printEntry ( const TimeEntry entry,
const TimeEntry previous,
std::ostream &  os,
std::ptrdiff_t  name_width = 0 
) const
inline

Definition at line 87 of file CodeProfiling.h.

◆ printTo()

void ChronoSequence::printTo ( std::ostream &  os) const
inline

Definition at line 72 of file CodeProfiling.h.

◆ recordTick()

void ChronoSequence::recordTick ( TimeEntry  new_entry,
std::ostream *  os 
)
inlineprotected

Unconditionally append the given tick, new_entry, to the list of ticks.

Definition at line 104 of file CodeProfiling.h.

◆ secondsSinceStart()

double ChronoSequence::secondsSinceStart ( )
inline

Definition at line 94 of file CodeProfiling.h.

◆ tick()

TickResult ChronoSequence::tick ( std::string  timepoint_name,
double  threshold = 0.0,
std::ostream *  os = nullptr 
)
inline

Record how much time it has been since the last tick under a name No effect if it has been less than threshold seconds since the last tick. Will immediately print the tick information to the given ostream, if it is not null.

Definition at line 54 of file CodeProfiling.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ChronoSequence cs 
)
friend

Definition at line 96 of file CodeProfiling.h.

Member Data Documentation

◆ sequence_name

std::string ChronoSequence::sequence_name
protected

Definition at line 113 of file CodeProfiling.h.

◆ times

std::vector<TimeEntry> ChronoSequence::times
protected

Definition at line 114 of file CodeProfiling.h.


The documentation for this struct was generated from the following file: