Panda3D
Public Member Functions | List of all members
PStatCollector Class Reference

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

Public Member Functions

 __init__ (const PStatCollector copy)
 
 __init__ (const PStatCollector parent, str name)
 Creates a new PStatCollector, ready to start accumulating data. More...
 
 __init__ (str name, PStatClient client)
 Creates a new PStatCollector, ready to start accumulating data. More...
 
 addLevel (const PStatThread thread, double increment)
 Adds the indicated increment (which may be negative) to the level setting associated with this collector for the indicated thread. More...
 
 addLevel (double increment)
 Adds the indicated increment (which may be negative) to the level setting associated with this collector for the main thread. More...
 
 addLevelNow (double increment)
 Calls add_level() and immediately calls flush_level(). More...
 
 addThreadLevel (double increment)
 Adds the indicated increment (which may be negative) to the level setting associated with this collector for the current thread. More...
 
 clearLevel ()
 Removes the level setting associated with this collector for the main thread. More...
 
 clearLevel (const PStatThread thread)
 Removes the level setting associated with this collector for the indicated thread. More...
 
 clearThreadLevel ()
 Removes the level setting associated with this collector for the current thread. More...
 
 flushLevel ()
 Updates the PStatClient with the recent results from add_level() and sub_level(). More...
 
str getFullname ()
 Returns the full name of this collector. More...
 
int getIndex ()
 Returns the index number of this particular collector within the PStatClient. More...
 
double getLevel ()
 Returns the current level value of the given collector in the main thread. More...
 
double getLevel (const PStatThread thread)
 Returns the current level value of the given collector. More...
 
str getName ()
 Returns the local name of this collector. More...
 
double getThreadLevel ()
 Returns the current level value of the given collector in the current thread. More...
 
bool isActive ()
 Returns true if this particular collector is active on the default thread, and we are currently transmitting PStats data. More...
 
bool isActive (const PStatThread thread)
 Returns true if this particular collector is active on the indicated thread, and we are currently transmitting PStats data. More...
 
bool isStarted ()
 Returns true if this particular collector has been started on the default thread, or false otherwise. More...
 
bool isStarted (const PStatThread thread)
 Returns true if this particular collector has been started on the indicated thread, or false otherwise. More...
 
bool isValid ()
 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). More...
 
PStatCollector operator= (const PStatCollector copy)
 
 output (Ostream out)
 
 setLevel (const PStatThread thread, double level)
 Sets the level setting associated with this collector for the indicated thread to the indicated value. More...
 
 setLevel (double level)
 Sets the level setting associated with this collector for the main thread to the indicated value. More...
 
 setThreadLevel (double level)
 Sets the level setting associated with this collector for the current thread to the indicated value. More...
 
 start ()
 Starts this particular timer ticking. More...
 
 start (const PStatThread thread)
 Starts this timer ticking within a particular thread. More...
 
 start (const PStatThread thread, double as_of)
 Marks that the timer should have been started as of the indicated time. More...
 
 stop ()
 Stops this timer. More...
 
 stop (const PStatThread thread)
 Stops this timer within a particular thread. More...
 
 stop (const PStatThread thread, double as_of)
 Marks that the timer should have been stopped as of the indicated time. More...
 
 subLevel (const PStatThread thread, double decrement)
 Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the indicated thread. More...
 
 subLevel (double decrement)
 Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the main thread. More...
 
 subLevelNow (double decrement)
 Calls sub_level() and immediately calls flush_level(). More...
 
 subThreadLevel (double decrement)
 Subtracts the indicated decrement (which may be negative) to the level setting associated with this collector for the current thread. More...
 

Detailed Description

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().

Member Function Documentation

◆ __init__() [1/3]

__init__ ( const PStatCollector  copy)

◆ __init__() [2/3]

__init__ ( const PStatCollector  parent,
str  name 
)

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.

◆ __init__() [3/3]

__init__ ( str  name,
PStatClient  client 
)

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.

◆ addLevel() [1/2]

addLevel ( const PStatThread  thread,
double  increment 
)

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.

◆ addLevel() [2/2]

addLevel ( 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.

◆ addLevelNow()

addLevelNow ( double  increment)

Calls add_level() and immediately calls flush_level().

◆ addThreadLevel()

addThreadLevel ( 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.

◆ clearLevel() [1/2]

clearLevel ( )

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().

◆ clearLevel() [2/2]

clearLevel ( const PStatThread  thread)

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.

◆ clearThreadLevel()

clearThreadLevel ( )

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.

◆ flushLevel()

flushLevel ( )

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

◆ getFullname()

str getFullname ( )

Returns the full name of this collector.

This includes the names of all the collector's parents, concatenated together with colons.

◆ getIndex()

int getIndex ( )

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

◆ getLevel() [1/2]

double getLevel ( )

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

This implicitly calls flush_level().

◆ getLevel() [2/2]

double getLevel ( const PStatThread  thread)

Returns the current level value of the given collector.

◆ getName()

str getName ( )

Returns the local name of this collector.

This is the rightmost part of the fullname, after the rightmost colon.

◆ getThreadLevel()

double getThreadLevel ( )

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

◆ isActive() [1/2]

bool isActive ( )

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

◆ isActive() [2/2]

bool isActive ( const PStatThread  thread)

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

◆ isStarted() [1/2]

bool isStarted ( )

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

◆ isStarted() [2/2]

bool isStarted ( const PStatThread  thread)

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

◆ isValid()

bool isValid ( )

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).

◆ operator=()

PStatCollector operator= ( const PStatCollector  copy)

◆ output()

output ( Ostream  out)

◆ setLevel() [1/2]

setLevel ( const PStatThread  thread,
double  level 
)

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

◆ setLevel() [2/2]

setLevel ( double  level)

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

This implicitly calls flush_level().

◆ setThreadLevel()

setThreadLevel ( double  level)

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

◆ start() [1/3]

start ( )

Starts this particular timer ticking.

This should be called before the code you want to measure.

◆ start() [2/3]

start ( const PStatThread  thread)

Starts this timer ticking within a particular thread.

◆ start() [3/3]

start ( const PStatThread  thread,
double  as_of 
)

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.

◆ stop() [1/3]

stop ( )

Stops this timer.

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

◆ stop() [2/3]

stop ( const PStatThread  thread)

Stops this timer within a particular thread.

◆ stop() [3/3]

stop ( const PStatThread  thread,
double  as_of 
)

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.

◆ subLevel() [1/2]

subLevel ( const PStatThread  thread,
double  decrement 
)

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.

◆ subLevel() [2/2]

subLevel ( 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.

◆ subLevelNow()

subLevelNow ( double  decrement)

Calls sub_level() and immediately calls flush_level().

◆ subThreadLevel()

subThreadLevel ( 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.