Skip to main content

chronon::Counter

More...

#include <LocalCounter.hpp>

Public Functions

Name
~Counter() =default
const std::string &unit() const
voidreset()
Counter &operator=(const Counter & ) =delete
Counter &operator=(Counter && other)
Counter &operator+=(uint64_t delta)
Counter &operator++()
Counteroperator++(int )
const std::string &name() const
boolisRegistered() const
CounterIdid() const
uint64_tget() const
const std::string &description() const
Counter(ObservableUnit * owner, std::string_view name, std::string_view description ="", std::string_view unit ="")
Counter(const Counter & ) =delete
Counter(Counter && other)

Friends

Name
classObservableUnit

Detailed Description

class chronon::Counter;

Counter - Per-instance counter declared as a unit member.

Each unit instance has its own counter with separate values:

  • Counter names include the unit's hierarchical path (e.g., "cpu0.alu0.ops")
  • Fast increment path (~2-3ns) via direct context access

Usage:

class ALU : public TickableUnit, public ObservableUnit {
Counter ops_{this, "ops", "Operations executed"};
Counter stalls_{this, "stalls", "Stall cycles"};

void tick() override {
++ops_; // Fast: ~2-3ns
stalls_ += 5; // Add 5
}
};

Output (CSV):

cycle,unit_name,counter_name,value
10000,cpu0.alu0,ops,2500
10000,cpu0.alu1,ops,2400
10000,cpu1.alu0,ops,2550

Public Functions Documentation

function ~Counter

~Counter() =default

function unit

inline const std::string & unit() const

Get the counter unit.

function reset

inline void reset()

Reset value to zero.

function operator=

Counter & operator=(
const Counter &
) =delete

function operator=

Counter & operator=(
Counter && other
)

function operator+=

inline Counter & operator+=(
uint64_t delta
)

Add-assign operator.

function operator++

inline Counter & operator++()

Pre-increment operator.

function operator++

inline Counter operator++(
int
)

Post-increment operator.

function name

inline const std::string & name() const

Get the counter name.

function isRegistered

inline bool isRegistered() const

Check if the counter is registered.

function id

inline CounterId id() const

Get the counter ID (only valid if registered).

function get

inline uint64_t get() const

Get current value.

function description

inline const std::string & description() const

Get the counter description.

function Counter

Counter(
ObservableUnit * owner,
std::string_view name,
std::string_view description ="",
std::string_view unit =""
)

Parameters:

  • owner The ObservableUnit that owns this counter
  • name Counter name (will be prefixed with unit path)
  • description Counter description
  • unit Unit of measurement (e.g., "ops", "cycles", "bytes")

Construct a counter.

function Counter

Counter(
const Counter &
) =delete

function Counter

Counter(
Counter && other
)

Friends

friend ObservableUnit

friend class ObservableUnit(
ObservableUnit
);

Updated on 2026-05-26 at 05:42:32 +0000