Entity Generator 1.1.0
Composable, deterministic entity generation for C++23
Loading...
Searching...
No Matches
dasmig::ext::stats_observer Class Reference

Observer that collects comprehensive generation statistics. More...

#include <stats_observer.hpp>

Inheritance diagram for dasmig::ext::stats_observer:
dasmig::generation_observer

Public Types

using clock = std::chrono::steady_clock
 Clock type used for timing.
 
using duration = std::chrono::steady_clock::duration
 Duration type.
 

Public Member Functions

Computed Helpers
duration avg_entity_time () const
 Average generation time per entity (zero if none generated).
 
duration avg_component_time (const std::wstring &key) const
 Average generation time per component key.
 
double avg_components_per_entity () const
 Average components produced per entity (0.0 if none generated).
 
double component_retry_rate () const
 Retry rate: total retries / total component generations.
 
double entity_retry_rate () const
 Entity retry rate: entity retries / entities generated.
 
Report
std::wstring report () const
 Produce a human-readable wide-string report of all collected stats.
 
Reset
void reset ()
 Zero all counters, timers, and distributions.
 
- Public Member Functions inherited from dasmig::generation_observer
virtual ~generation_observer ()=default
 Virtual destructor.
 
virtual void on_before_retry (const std::wstring &key, std::size_t attempt)
 Called before a component validation retry.
 
virtual void on_before_entity_retry (std::size_t attempt)
 Called before an entity validation retry.
 
virtual void on_before_add (const std::wstring &key)
 Called before a component is registered.
 
virtual void on_after_add (const std::wstring &key)
 Called after a component is registered.
 
virtual void on_before_remove (const std::wstring &key)
 Called before a component is removed.
 
virtual void on_after_remove (const std::wstring &key)
 Called after a component is removed.
 

Public Attributes

Entity Counters
std::size_t entities_generated {0}
 Total entities successfully generated.
 
std::size_t entity_retries {0}
 Total entity-level validation retries.
 
std::size_t entity_failures {0}
 Total entity-level validation failures.
 
Entity Timing
duration total_generation_time {duration::zero()}
 Wall-clock time summed across all entities.
 
duration min_entity_time {duration::max()}
 Fastest entity generation.
 
duration max_entity_time {duration::zero()}
 Slowest entity generation.
 
Component Counters
std::size_t components_generated {0}
 Total components successfully generated.
 
std::size_t components_skipped {0}
 Total components skipped (weight or conditional).
 
std::size_t component_failures {0}
 Total component validation failures.
 
Per-Component-Key Counters
std::map< std::wstring, std::size_t > component_retries
 Total retries per key.
 
std::map< std::wstring, std::size_t > component_counts
 Successful generations per key.
 
std::map< std::wstring, std::size_t > component_skip_counts
 Skips per key.
 
std::map< std::wstring, std::size_t > component_failure_counts
 Failures per key.
 
Per-Component-Key Timing
std::map< std::wstring, durationcomponent_times
 Total generation time per key.
 
std::map< std::wstring, durationcomponent_min_times
 Fastest per key.
 
std::map< std::wstring, durationcomponent_max_times
 Slowest per key.
 
Components-per-Entity Tracking
std::size_t min_components_per_entity
 Fewest components in any entity.
 
std::size_t max_components_per_entity {0}
 Most components in any entity.
 
std::size_t total_components_in_entities {0}
 Sum for computing the average.
 
Value Distribution
std::map< std::wstring, std::map< std::wstring, std::size_t > > value_distribution
 Per-component key, counts how many times each display string appeared.
 

Hook Overrides

void on_before_generate () override
 Called before an entity is generated.
 
void on_after_generate (const entity &) override
 Called after an entity is successfully generated.
 
void on_before_component (const std::wstring &key) override
 Called before a component is generated.
 
void on_after_component (const std::wstring &key, const std::any &value) override
 Called after a component is successfully generated.
 
void on_skip (const std::wstring &key) override
 Called when a component is skipped (weight roll or conditional exclusion).
 
void on_after_retry (const std::wstring &key, std::size_t, const std::any &) override
 Called after a component validation retry.
 
void on_component_fail (const std::wstring &key) override
 Called when component validation is exhausted (precedes exception).
 
void on_after_entity_retry (std::size_t) override
 Called after an entity validation retry.
 
void on_entity_fail () override
 Called when entity validation is exhausted (precedes exception).
 

Detailed Description

Observer that collects comprehensive generation statistics.

All fields are public for direct access. Use reset() to zero everything and report() to produce a formatted summary.

See also
generation_observer, eg::add_observer()

Definition at line 24 of file stats_observer.hpp.

Member Typedef Documentation

◆ clock

using dasmig::ext::stats_observer::clock = std::chrono::steady_clock

Clock type used for timing.

Definition at line 27 of file stats_observer.hpp.

◆ duration

using dasmig::ext::stats_observer::duration = std::chrono::steady_clock::duration

Duration type.

Definition at line 28 of file stats_observer.hpp.

Member Function Documentation

◆ avg_component_time()

duration dasmig::ext::stats_observer::avg_component_time ( const std::wstring &  key) const
inline

Average generation time per component key.

Parameters
keyThe component key.
Returns
Average duration, or zero if no data for the key.

Definition at line 97 of file stats_observer.hpp.

◆ avg_components_per_entity()

double dasmig::ext::stats_observer::avg_components_per_entity ( ) const
inline

Average components produced per entity (0.0 if none generated).

Definition at line 108 of file stats_observer.hpp.

◆ avg_entity_time()

duration dasmig::ext::stats_observer::avg_entity_time ( ) const
inline

Average generation time per entity (zero if none generated).

Definition at line 88 of file stats_observer.hpp.

◆ component_retry_rate()

double dasmig::ext::stats_observer::component_retry_rate ( ) const
inline

Retry rate: total retries / total component generations.

Definition at line 116 of file stats_observer.hpp.

◆ entity_retry_rate()

double dasmig::ext::stats_observer::entity_retry_rate ( ) const
inline

Entity retry rate: entity retries / entities generated.

Definition at line 126 of file stats_observer.hpp.

◆ on_after_component()

void dasmig::ext::stats_observer::on_after_component ( const std::wstring &  key,
const std::any &  value 
)
inlineoverridevirtual

Called after a component is successfully generated.

Parameters
keyThe component key.
valueThe generated value.

Reimplemented from dasmig::generation_observer.

Definition at line 350 of file stats_observer.hpp.

◆ on_after_entity_retry()

void dasmig::ext::stats_observer::on_after_entity_retry ( std::size_t  attempt)
inlineoverridevirtual

Called after an entity validation retry.

Parameters
attemptThe entity retry attempt number.

Reimplemented from dasmig::generation_observer.

Definition at line 404 of file stats_observer.hpp.

◆ on_after_generate()

void dasmig::ext::stats_observer::on_after_generate ( const entity e)
inlineoverridevirtual

Called after an entity is successfully generated.

Parameters
eThe generated entity.

Reimplemented from dasmig::generation_observer.

Definition at line 329 of file stats_observer.hpp.

◆ on_after_retry()

void dasmig::ext::stats_observer::on_after_retry ( const std::wstring &  key,
std::size_t  attempt,
const std::any &  value 
)
inlineoverridevirtual

Called after a component validation retry.

Parameters
keyThe component key.
attemptThe retry attempt number.
valueThe newly generated value.

Reimplemented from dasmig::generation_observer.

Definition at line 391 of file stats_observer.hpp.

◆ on_before_component()

void dasmig::ext::stats_observer::on_before_component ( const std::wstring &  key)
inlineoverridevirtual

Called before a component is generated.

Parameters
keyThe component key about to be generated.

Reimplemented from dasmig::generation_observer.

Definition at line 345 of file stats_observer.hpp.

◆ on_before_generate()

void dasmig::ext::stats_observer::on_before_generate ( )
inlineoverridevirtual

Called before an entity is generated.

Reimplemented from dasmig::generation_observer.

Definition at line 323 of file stats_observer.hpp.

◆ on_component_fail()

void dasmig::ext::stats_observer::on_component_fail ( const std::wstring &  key)
inlineoverridevirtual

Called when component validation is exhausted (precedes exception).

Parameters
keyThe failed component key.

Reimplemented from dasmig::generation_observer.

Definition at line 398 of file stats_observer.hpp.

◆ on_entity_fail()

void dasmig::ext::stats_observer::on_entity_fail ( )
inlineoverridevirtual

Called when entity validation is exhausted (precedes exception).

Reimplemented from dasmig::generation_observer.

Definition at line 409 of file stats_observer.hpp.

◆ on_skip()

void dasmig::ext::stats_observer::on_skip ( const std::wstring &  key)
inlineoverridevirtual

Called when a component is skipped (weight roll or conditional exclusion).

Parameters
keyThe skipped component key.

Reimplemented from dasmig::generation_observer.

Definition at line 385 of file stats_observer.hpp.

◆ report()

std::wstring dasmig::ext::stats_observer::report ( ) const
inline

Produce a human-readable wide-string report of all collected stats.

Returns
A multi-line formatted report string.

Definition at line 139 of file stats_observer.hpp.

◆ reset()

void dasmig::ext::stats_observer::reset ( )
inline

Zero all counters, timers, and distributions.

Definition at line 289 of file stats_observer.hpp.

Member Data Documentation

◆ component_counts

std::map<std::wstring, std::size_t> dasmig::ext::stats_observer::component_counts

Successful generations per key.

Definition at line 54 of file stats_observer.hpp.

◆ component_failure_counts

std::map<std::wstring, std::size_t> dasmig::ext::stats_observer::component_failure_counts

Failures per key.

Definition at line 56 of file stats_observer.hpp.

◆ component_failures

std::size_t dasmig::ext::stats_observer::component_failures {0}

Total component validation failures.

Definition at line 48 of file stats_observer.hpp.

◆ component_max_times

std::map<std::wstring, duration> dasmig::ext::stats_observer::component_max_times

Slowest per key.

Definition at line 63 of file stats_observer.hpp.

◆ component_min_times

std::map<std::wstring, duration> dasmig::ext::stats_observer::component_min_times

Fastest per key.

Definition at line 62 of file stats_observer.hpp.

◆ component_retries

std::map<std::wstring, std::size_t> dasmig::ext::stats_observer::component_retries

Total retries per key.

Definition at line 53 of file stats_observer.hpp.

◆ component_skip_counts

std::map<std::wstring, std::size_t> dasmig::ext::stats_observer::component_skip_counts

Skips per key.

Definition at line 55 of file stats_observer.hpp.

◆ component_times

std::map<std::wstring, duration> dasmig::ext::stats_observer::component_times

Total generation time per key.

Definition at line 61 of file stats_observer.hpp.

◆ components_generated

std::size_t dasmig::ext::stats_observer::components_generated {0}

Total components successfully generated.

Definition at line 46 of file stats_observer.hpp.

◆ components_skipped

std::size_t dasmig::ext::stats_observer::components_skipped {0}

Total components skipped (weight or conditional).

Definition at line 47 of file stats_observer.hpp.

◆ entities_generated

std::size_t dasmig::ext::stats_observer::entities_generated {0}

Total entities successfully generated.

Definition at line 32 of file stats_observer.hpp.

◆ entity_failures

std::size_t dasmig::ext::stats_observer::entity_failures {0}

Total entity-level validation failures.

Definition at line 34 of file stats_observer.hpp.

◆ entity_retries

std::size_t dasmig::ext::stats_observer::entity_retries {0}

Total entity-level validation retries.

Definition at line 33 of file stats_observer.hpp.

◆ max_components_per_entity

std::size_t dasmig::ext::stats_observer::max_components_per_entity {0}

Most components in any entity.

Definition at line 70 of file stats_observer.hpp.

◆ max_entity_time

duration dasmig::ext::stats_observer::max_entity_time {duration::zero()}

Slowest entity generation.

Definition at line 41 of file stats_observer.hpp.

◆ min_components_per_entity

std::size_t dasmig::ext::stats_observer::min_components_per_entity
Initial value:
{
std::numeric_limits<std::size_t>::max()}

Fewest components in any entity.

Definition at line 68 of file stats_observer.hpp.

◆ min_entity_time

duration dasmig::ext::stats_observer::min_entity_time {duration::max()}

Fastest entity generation.

Definition at line 40 of file stats_observer.hpp.

◆ total_components_in_entities

std::size_t dasmig::ext::stats_observer::total_components_in_entities {0}

Sum for computing the average.

Definition at line 71 of file stats_observer.hpp.

◆ total_generation_time

duration dasmig::ext::stats_observer::total_generation_time {duration::zero()}

Wall-clock time summed across all entities.

Definition at line 39 of file stats_observer.hpp.

◆ value_distribution

std::map<std::wstring, std::map<std::wstring, std::size_t> > dasmig::ext::stats_observer::value_distribution

Per-component key, counts how many times each display string appeared.

Useful for analysing uniformity of random components.

Definition at line 81 of file stats_observer.hpp.


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