PStatCollector

class PStatCollector

A lightweight class that represents a single element that may be timed and/or counted via stats.

Collectors can be used to measure two different kinds of values: elapsed time, and “other”.

To measure elapsed time, call start() and stop() as appropriate to bracket the section of code you want to time (or use a PStatTimer to do this automatically).

To measure anything else, call set_level() and/or add_level() to set the “level” value associated with this collector. The meaning of the value set for the “level” is entirely up to the user; it may represent the number of triangles rendered or the kilobytes of texture memory consumed, for instance. The level set will remain fixed across multiple frames until it is reset via another set_level() or adjusted via a call to add_level(). It may also be completely removed via clear_level().

Inheritance diagram

Inheritance diagram of PStatCollector

explicit PStatCollector(std::string const &name, PStatClient *client = nullptr)
explicit PStatCollector(PStatCollector const &parent, std::string const &name)
PStatCollector(PStatCollector const &copy)

Normally, this constructor is called only from PStatClient. Use one of the constructors below to create your own Collector.

Creates a new PStatCollector, ready to start accumulating data. The name of the collector uniquely identifies it among the other collectors; if two collectors share the same name then they are really the same collector.

The name may also be a compound name, something like “Cull:Sort”, which indicates that this is a collector named “Sort”, a child of the collector named “Cull”. The parent may also be named explicitly by reference in the other flavor of the constructor; see further comments on this for that constructor.

If the client pointer is non-null, it specifies a particular client to register the collector with; otherwise, the global client is used.

Creates a new PStatCollector, ready to start accumulating data. The name of the collector uniquely identifies it among the other collectors; if two collectors share the same name then they are really the same collector.

The parent is the collector that conceptually includes all of the time measured for this collector. For instance, a particular character’s animation time is owned by the “Animation” collector, which is in turn owned by the “Frame” collector. It is not strictly necessary that all of the time spent in a particular collector is completely nested within time spent in its parent’s collector. If parent is the empty string, the collector is owned by “Frame”.

This constructor does not take a client pointer; it always creates the new collector on the same client as its parent.

void add_level(double increment)
void add_level(PStatThread const &thread, double increment)

Adds the indicated increment (which may be negative) to the level setting associated with this collector for the main thread. If the collector did not already have a level setting for the main thread, it is initialized to 0.

As an optimization, the data is not immediately set to the PStatClient. It will be sent the next time flush_level() is called.

Adds the indicated increment (which may be negative) to the level setting associated with this collector for the indicated thread. If the collector did not already have a level setting for this thread, it is initialized to 0.

void add_level_now(double increment)

Calls add_level() and immediately calls flush_level().

void add_thread_level(double increment)

Adds the indicated increment (which may be negative) to the level setting associated with this collector for the current thread. If the collector did not already have a level setting for the current thread, it is initialized to 0.

void clear_level(void)
void clear_level(PStatThread const &thread)

Removes the level setting associated with this collector for the main thread. The collector will no longer show up on any level graphs in the main thread. This implicitly calls flush_level().

Removes the level setting associated with this collector for the indicated thread. The collector will no longer show up on any level graphs in this thread.

void clear_thread_level(void)

Removes the level setting associated with this collector for the current thread. The collector will no longer show up on any level graphs in the current thread.

void flush_level(void)

Updates the PStatClient with the recent results from add_level() and sub_level().

std::string get_fullname(void) const

Returns the full name of this collector. This includes the names of all the collector’s parents, concatenated together with colons.

int get_index(void) const

Returns the index number of this particular collector within the PStatClient.

double get_level(void)
double get_level(PStatThread const &thread)

Returns the current level value of the given collector in the main thread. This implicitly calls flush_level().

Returns the current level value of the given collector.

std::string get_name(void) const

Returns the local name of this collector. This is the rightmost part of the fullname, after the rightmost colon.

double get_thread_level(void)

Returns the current level value of the given collector in the current thread.

bool is_active(void)
bool is_active(PStatThread const &thread)

Returns true if this particular collector is active on the default thread, and we are currently transmitting PStats data.

Returns true if this particular collector is active on the indicated thread, and we are currently transmitting PStats data.

bool is_started(void)
bool is_started(PStatThread const &thread)

Returns true if this particular collector has been started on the default thread, or false otherwise.

Returns true if this particular collector has been started on the indicated thread, or false otherwise.

bool is_valid(void) const

Returns true if collector is valid and may be used, or false if it was constructed with the default constructor (in which case any attempt to use it will crash).

void output(std::ostream &out) const
void set_level(double level)
void set_level(PStatThread const &thread, double level)

Sets the level setting associated with this collector for the main thread to the indicated value. This implicitly calls flush_level().

Sets the level setting associated with this collector for the indicated thread to the indicated value.

void set_thread_level(double level)

Sets the level setting associated with this collector for the current thread to the indicated value.

void start(void)
void start(PStatThread const &thread)
void start(PStatThread const &thread, double as_of)

Starts this particular timer ticking. This should be called before the code you want to measure.

Starts this timer ticking within a particular thread.

Marks that the timer should have been started as of the indicated time. This must be a time based on the PStatClient’s clock (see PStatClient::get_clock()), and care should be taken that all such calls exhibit a monotonically increasing series of time values.

void stop(void)
void stop(PStatThread const &thread)
void stop(PStatThread const &thread, double as_of)

Stops this timer. This should be called after the code you want to measure.

Stops this timer within a particular thread.

Marks that the timer should have been stopped as of the indicated time. This must be a time based on the PStatClient’s clock (see PStatClient::get_clock()), and care should be taken that all such calls exhibit a monotonically increasing series of time values.

void sub_level(double decrement)
void sub_level(PStatThread const &thread, double decrement)

Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the main thread. If the collector did not already have a level setting for the main thread, it is initialized to 0.

As an optimization, the data is not immediately set to the PStatClient. It will be sent the next time flush_level() is called.

Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the indicated thread. If the collector did not already have a level setting for this thread, it is initialized to 0.

void sub_level_now(double decrement)

Calls sub_level() and immediately calls flush_level().

void sub_thread_level(double decrement)

Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the current thread. If the collector did not already have a level setting for the current thread, it is initialized to 0.