Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
timer.h File Reference
#include "lib/config2.h"
#include "lib/utf8.h"
#include <cstring>
Include dependency graph for timer.h:

Go to the source code of this file.

Classes

class  ScopeTimer
 used by TIMER More...
 
class  TimerUnit
 
struct  TimerClient
 
class  ScopeTimerAccrue
 used by TIMER_ACCRUE More...
 

Macros

#define TIMER(description)   ScopeTimer UID__(description)
 Measures the time taken to execute code up until end of the current scope; displays it via debug_printf. More...
 
#define TIMER_BEGIN(description)   { ScopeTimer UID__(description)
 Measures the time taken to execute code between BEGIN and END markers; displays it via debug_printf. More...
 
#define TIMER_END(description)   }
 
#define TIMER_ADD_CLIENT(id)
 "allocate" a new TimerClient that will keep track of the total time billed to it, along with a description string. More...
 
#define TIMER_ACCRUE(client)   ScopeTimerAccrue UID__(client)
 Measure the time taken to execute code up until end of the current scope; bill it to the given TimerClient object. More...
 

Typedefs

typedef i64 Cycles
 

Functions

void timer_Init ()
 timer_Time will subsequently return values relative to the current time. More...
 
double timer_Time ()
 
double timer_Resolution ()
 
std::string StringForSeconds (double seconds)
 internal helper functions for returning an easily readable string (i.e. More...
 
std::string StringForCycles (Cycles cycles)
 
TimerClienttimer_AddClient (TimerClient *tc, const wchar_t *description)
 make the given TimerClient (usually instantiated as static data) ready for use. More...
 
void timer_DisplayClientTotals ()
 display all clients' totals; does not reset them. More...
 

Macro Definition Documentation

◆ TIMER

#define TIMER (   description)    ScopeTimer UID__(description)

Measures the time taken to execute code up until end of the current scope; displays it via debug_printf.

Can safely be nested. Useful for measuring time spent in a function or basic block. must remain valid over the lifetime of this object; a string literal is safest.

Example usage: void func() { TIMER(L"description"); // code to be measured }

◆ TIMER_ACCRUE

#define TIMER_ACCRUE (   client)    ScopeTimerAccrue UID__(client)

Measure the time taken to execute code up until end of the current scope; bill it to the given TimerClient object.

Can safely be nested. Useful for measuring total time spent in a function or basic block over the entire program. ‘client’ is an identifier registered via TIMER_ADD_CLIENT.

Example usage: TIMER_ADD_CLIENT(client);

void func() { TIMER_ACCRUE(client); // code to be measured }

[later or at exit] timer_DisplayClientTotals();

◆ TIMER_ADD_CLIENT

#define TIMER_ADD_CLIENT (   id)
Value:
static TimerClient UID__;\
static TimerClient* id = timer_AddClient(&UID__, WIDEN(#id))
#define WIDEN(x)
Definition: code_annotation.h:404
#define UID__
Definition: code_annotation.h:193
Definition: timer.h:249
TimerClient * timer_AddClient(TimerClient *tc, const wchar_t *description)
make the given TimerClient (usually instantiated as static data) ready for use.
Definition: timer.cpp:177

"allocate" a new TimerClient that will keep track of the total time billed to it, along with a description string.

These are displayed when timer_DisplayClientTotals is called. Invoke this at file or function scope; a (static) TimerClient pointer of name <id> will be defined, which should be passed to TIMER_ACCRUE.

◆ TIMER_BEGIN

#define TIMER_BEGIN (   description)    { ScopeTimer UID__(description)

Measures the time taken to execute code between BEGIN and END markers; displays it via debug_printf.

Can safely be nested. Useful for measuring several pieces of code within the same function/block. must remain valid over the lifetime of this object; a string literal is safest.

Caveats:

  • this wraps the code to be measured in a basic block, so any variables defined there are invisible to surrounding code.
  • the description passed to END isn't inspected; you are responsible for ensuring correct nesting!

Example usage: void func2() { // uninteresting code TIMER_BEGIN(L"description2"); // code to be measured TIMER_END(L"description2"); // uninteresting code }

◆ TIMER_END

#define TIMER_END (   description)    }

Typedef Documentation

◆ Cycles

typedef i64 Cycles

Function Documentation

◆ StringForCycles()

std::string StringForCycles ( Cycles  cycles)

◆ StringForSeconds()

std::string StringForSeconds ( double  seconds)

internal helper functions for returning an easily readable string (i.e.

re-scaled to appropriate units)

◆ timer_AddClient()

TimerClient * timer_AddClient ( TimerClient tc,
const wchar_t *  description 
)

make the given TimerClient (usually instantiated as static data) ready for use.

returns its address for TIMER_ADD_CLIENT's convenience. this client's total (which is increased by a BillingPolicy) will be displayed by timer_DisplayClientTotals. notes:

  • may be called at any time;
  • always succeeds (there's no fixed limit);
  • free() is not needed nor possible.
  • description must remain valid until exit; a string literal is safest.

◆ timer_DisplayClientTotals()

void timer_DisplayClientTotals ( )

display all clients' totals; does not reset them.

typically called at exit.

◆ timer_Init()

void timer_Init ( )

timer_Time will subsequently return values relative to the current time.

◆ timer_Resolution()

double timer_Resolution ( )
Returns
resolution [s] of the timer.

◆ timer_Time()

double timer_Time ( )
Returns
high resolution (> 1 us) timestamp [s].