Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
Profiler Class Reference

Collects high-resolution timing data for labeled code sections. More...

#include <profiler.hpp>

Public Types

using time_point = std::chrono::high_resolution_clock::time_point
using TimeCounter = std::pair<std::size_t, std::size_t>

Static Public Member Functions

static void setEnabled (bool enabled)
 Turn recording on or off (on by default), outside timed regions: a stop() without its start() records a wrong time. When off, start/stop with a literal label cost one branch.
static void start (const char *label)
 start(label) when recording is on.
static void stop (const char *label)
 stop(label) when recording is on.
static void startInterval (const char *label)
 startInterval(label) when recording is on.
static void stopInterval (const char *label)
 stopInterval(label) when recording is on.
static void start (const std::string &label)
 Begin timing a single interval for the specified label.
static void startInterval (const std::string &label)
 Mark the start of one interval among multiple for a label.
static void stop (const std::string &label)
 End timing a single interval for the specified label.
static void stopInterval (const std::string &label)
 End one interval among multiple for the specified label.
static void print ()
 Print accumulated timings for all labels in milliseconds.
static void clear ()
 Remove all recorded timing data.
static nlohmann::json dumpJson ()
 Export collected profile data as a JSON object including interval timestamps.
static size_t getDuration (const std::string &label)
 Get the time elapsed for a certain label.

Static Public Attributes

static bool s_enabled = true
static std::unordered_map< std::string, TimeCounter > time_map = {}
static std::unordered_map< std::string, time_point > start_times = {}
 Pending start time recorded per label via start(), consumed by stop().
static std::unordered_map< std::string, std::vector< time_point > > stop_time_intervals = {}
 Interval end timestamps recorded per label via stopInterval().
static std::unordered_map< std::string, std::vector< time_point > > start_time_intervals = {}
 Interval start timestamps recorded per label via startInterval().

Detailed Description

Collects high-resolution timing data for labeled code sections.

When NPROFILE is not defined, start/stop calls record durations in nanoseconds under a given label. Intervals support multiple start/stop pairs to measure repeated events. Accumulated times can be printed or cleared. A JSON dump method provides machine-readable output.

Member Typedef Documentation

◆ time_point

using Profiler::time_point = std::chrono::high_resolution_clock::time_point

◆ TimeCounter

using Profiler::TimeCounter = std::pair<std::size_t, std::size_t>

Member Function Documentation

◆ clear()

void Profiler::clear ( )
static

Remove all recorded timing data.

◆ dumpJson()

nlohmann::json Profiler::dumpJson ( )
static

Export collected profile data as a JSON object including interval timestamps.

Returns
nlohmann::json JSON object mapping each label to its total duration and arrays of interval start/end timestamps.

Structure: { "label": { "total_ns": uint64, "interval_starts_ns": [uint64, ...], "interval_ends_ns": [uint64, ...] }, ... }

◆ getDuration()

size_t Profiler::getDuration ( const std::string & label)
static

Get the time elapsed for a certain label.

◆ print()

void Profiler::print ( )
static

Print accumulated timings for all labels in milliseconds.

Outputs a table sorted by descending total time. Labels are left- aligned, and times are right-aligned with three decimal places.

◆ setEnabled()

void Profiler::setEnabled ( bool enabled)
inlinestatic

Turn recording on or off (on by default), outside timed regions: a stop() without its start() records a wrong time. When off, start/stop with a literal label cost one branch.

◆ start() [1/2]

void Profiler::start ( const char * label)
inlinestatic

start(label) when recording is on.

◆ start() [2/2]

void Profiler::start ( const std::string & label)
static

Begin timing a single interval for the specified label.

Parameters
labelUnique identifier for the timed block.

Records the current high-resolution clock time as the start point. Subsequent stop(label) call will add the elapsed time (in ns) to the cumulative total for this label.

◆ startInterval() [1/2]

void Profiler::startInterval ( const char * label)
inlinestatic

startInterval(label) when recording is on.

◆ startInterval() [2/2]

void Profiler::startInterval ( const std::string & label)
static

Mark the start of one interval among multiple for a label.

Parameters
labelIdentifier grouping related intervals.

Pushes the current high-resolution clock time onto a stack associated with the label. Each push should correspond to a matching stopInterval(label) to compute individual durations.

◆ stop() [1/2]

void Profiler::stop ( const char * label)
inlinestatic

stop(label) when recording is on.

◆ stop() [2/2]

void Profiler::stop ( const std::string & label)
static

End timing a single interval for the specified label.

Parameters
labelLabel previously used with start(label).

Calculates the time difference between now and the last start(label) call, then adds the duration (in ns) to the cumulative total.

◆ stopInterval() [1/2]

void Profiler::stopInterval ( const char * label)
inlinestatic

stopInterval(label) when recording is on.

◆ stopInterval() [2/2]

void Profiler::stopInterval ( const std::string & label)
static

End one interval among multiple for the specified label.

Parameters
labelIdentifier matching a previous startInterval(label).

Pushes the current time as the interval's end counterpart.

Member Data Documentation

◆ s_enabled

bool Profiler::s_enabled = true
inlinestatic

◆ start_time_intervals

std::unordered_map< std::string, std::vector< std::chrono::high_resolution_clock::time_point > > Profiler::start_time_intervals = {}
static

Interval start timestamps recorded per label via startInterval().

◆ start_times

std::unordered_map< std::string, std::chrono::high_resolution_clock::time_point > Profiler::start_times = {}
static

Pending start time recorded per label via start(), consumed by stop().

◆ stop_time_intervals

std::unordered_map< std::string, std::vector< std::chrono::high_resolution_clock::time_point > > Profiler::stop_time_intervals = {}
static

Interval end timestamps recorded per label via stopInterval().

◆ time_map

std::unordered_map< std::string, std::pair< std::size_t, std::size_t > > Profiler::time_map = {}
static

Cumulative {total_duration_ns, call_count} recorded per label via start()/stop().


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