libhatchet
Loading...
Searching...
No Matches
hxprofiler.hpp File Reference

Go to the source code of this file.

Macros

#define hxprofile_scope(label_string_literal_)
#define hxprofile_scope_min(label_string_literal_, min_cycles_)
#define hxprofiler_start()
#define hxprofiler_stop()
#define hxprofiler_log()
#define hxprofiler_write_to_chrome_tracing(filename_)

Typedefs

using hxcycles_t = size_t

Functions

hxcycles_t hxtime_sample_cycles (void)

Variables

constexpr double hxcycles_per_second = 3.0e+9
constexpr double hxmilliseconds_per_cycle = 1.0e+3 / hxcycles_per_second
constexpr double hxmicroseconds_per_cycle = 1.0e+6 / hxcycles_per_second

Detailed Description

Provides macros for RAII-style profiling (hxprofile_scope, hxprofile_scope_min with optional cycle cutoffs).

Allows exporting to Chrome's tracing format (hxprofiler_write_to_chrome_tracing). Profiling is enabled only if HX_USE_PROFILER is defined.

Macro Purpose
hxprofile_scope Records scoped samples keyed by a string literal.
hxprofile_scope_min Records scoped samples when the cycle cutoff is met.
hxprofiler_start Clears existing samples then starts recording.
hxprofiler_stop Stops recording while retaining samples.
hxprofiler_log Logs captured samples to the system log.
hxprofiler_write_to_chrome_tracing Writes captured samples to Chrome tracing JSON.

Macro Definition Documentation

◆ hxprofile_scope

#define hxprofile_scope ( label_string_literal_)
Value:
HX_PROFILE_ONLY_(const HX_NS_PREFIX_ hxdetail_::hxprofiler_scope_internal_<> \
HX_APPEND_COUNTER(hxprofile_scope_)(label_string_literal_))

hxprofile_scope(const char* label_string_literal) - Declares an RAII-style profiling sample.

WARNING: A pointer to label_string_literal is kept. Compiles to a NOP when not in use.

  • label_string_literal : A string literal label for the sample.

◆ hxprofile_scope_min

#define hxprofile_scope_min ( label_string_literal_,
min_cycles_ )
Value:
HX_PROFILE_ONLY_(const HX_NS_PREFIX_ hxdetail_::hxprofiler_scope_internal_<min_cycles_> \
HX_APPEND_COUNTER(hxprofile_scope_)(label_string_literal_))

hxprofile_scope_min(const char* label_string_literal, hxcycles_t min_cycles) - Declares an RAII-style profiling sample with a minimum cycle cutoff.

WARNING: A pointer to label_string_literal is kept. Compiles to a NOP when not in use.

  • label_string_literal : A string literal label for the sample.
  • min_cycles : A minimum number of cycles required for a sample to be recorded. Must be a compile-time constant.

◆ hxprofiler_log

#define hxprofiler_log ( )
Value:
HX_PROFILE_ONLY_(HX_NS_PREFIX_ hxdetail_::hxg_profiler_.log_())

hxprofiler_log(void) - Stops sampling and writes samples to the system log.

Compiles to a NOP when not in use.

◆ hxprofiler_start

#define hxprofiler_start ( )
Value:
HX_PROFILE_ONLY_(HX_NS_PREFIX_ hxdetail_::hxg_profiler_.start_())

hxprofiler_start(void) - Clears samples and begins sampling.

Compiles to a NOP when not in use.

◆ hxprofiler_stop

#define hxprofiler_stop ( )
Value:
HX_PROFILE_ONLY_(HX_NS_PREFIX_ hxdetail_::hxg_profiler_.stop_())

hxprofiler_stop(void) - Ends sampling.

Does not clear samples. Compiles to a NOP when not in use.

◆ hxprofiler_write_to_chrome_tracing

#define hxprofiler_write_to_chrome_tracing ( filename_)
Value:
HX_PROFILE_ONLY_(HX_NS_PREFIX_ hxdetail_::hxg_profiler_.write_to_chrome_tracing_(filename_))

hxprofiler_write_to_chrome_tracing(const char* filename) - Stops sampling and writes samples to the provided file in JSON format compatible with https://ui.perfetto.dev/.

Compiles to a NOP when not in use.

  • filename : Path to the output .json file.

Typedef Documentation

◆ hxcycles_t

using hxcycles_t = size_t

hxcycles_t - Stores approximately 1.5 seconds to 209 years worth of processor cycles starting from an unspecified origin and wrapping using unsigned rules.

This is intended for profiling, not calendaring. Used by the following include.

Function Documentation

◆ hxtime_sample_cycles()

hxcycles_t hxtime_sample_cycles ( void )
inline

hxtime_sample_cycles(void) - Set up the processor cycle counter for your architecture.

This is callable without enabling HX_USE_PROFILER.

Variable Documentation

◆ hxcycles_per_second

double hxcycles_per_second = 3.0e+9
inlineconstexpr

hxcycles_per_second - WARNING: Customize for your processor speed.

This assumes 2.8 GHz. These constants are primarily used with printf, which promotes everything to double anyway.

◆ hxmicroseconds_per_cycle

double hxmicroseconds_per_cycle = 1.0e+6 / hxcycles_per_second
inlineconstexpr

hxmicroseconds_per_cycle - The number of microseconds in a single processor cycle, derived from hxcycles_per_second.

◆ hxmilliseconds_per_cycle

double hxmilliseconds_per_cycle = 1.0e+3 / hxcycles_per_second
inlineconstexpr

hxmilliseconds_per_cycle - The number of milliseconds in a single processor cycle, derived from hxcycles_per_second.