OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
Public Member Functions | Static Public Member Functions | List of all members
InternalZGY::Timer Class Reference
Inheritance diagram for InternalZGY::Timer:
InternalZGY::PrintingTimer InternalZGY::RawPrintingTimer InternalZGY::SimpleTimer

Public Member Functions

 Timer (bool enable=true, const char *name=0, int skip=0, bool startrunning=true)
 
bool getEnabled () const
 
double getFrequency () const
 
double getLast () const
 
double getTotal () const
 
double getOverhead () const
 
int getCount () const
 
const char * getName () const
 
int getSkip () const
 
bool getRunning () const
 
int getVerbose () const
 
const char * getValue (bool details=false, bool msonly=false)
 
void setVerbose (int v)
 
void start ()
 
void stop ()
 
void reset ()
 

Static Public Member Functions

static void getValue_s (char *buf, int len, const char *name, int count, double total, bool running, bool details, bool msonly)
 

Constructor & Destructor Documentation

◆ Timer()

InternalZGY::Timer::Timer ( bool  enabled = true,
const char *  name = 0,
int  skip = 0,
bool  startrunning = true 
)

High resolution timer for performance measurement.

The timer starts running as soon as it is constructed, but for added accuracy it is recommended to invoke start() explicity. The previous start time is then ignored.

After calling stop(), the formatted elapsed time is available in getValue(). start() and stop() may be called multiple times to accumulate statistics. In this case, it might be useful to pass a "skip" argument to the constructor telling it that the first N laps are not representative and should be ignored.

The resolution and accuracy for timing short duration calls is approx. +/- 1 microsecond. Note that the class tries to adjust for the overhead of calling the Windows performance timer. This is done heuristically, so if you time something that takes just a few nanoseconds to execute then the result could end up negative.

Applications may use Timer directly, but the higher level NamedTimer will often be more convenient. The following examples show the use:

// One-shot timer:
static bool enable = Timer.getNumericEnv("SALMON_TIMERS")>0;
Timer t(enable);
DoTheWork();
t.Stop();
printf("It took %s\n", t.getValue());
//Statistics timer:
static Timer t(enable);
DoTheWork();
t.Stop();
if (last_call)
printf("It took %s\n", t.getValue());

The first example is often too noisy, and there is no way for the user to configure the timer to only print statistics. The second approach may be tricky because it is not always obvious when to print the gathered statistics. The higher level NamedTimer and TimerPool solves these problems. Create a new Timer instance, optionally giving it a name. Optionally pass enabled=false to create a low overhead stub. Optionally pass an initial count not to be included in statistics. Once the instance is created the enabled state cannot be changed.

Member Function Documentation

◆ getValue()

const char * InternalZGY::Timer::getValue ( bool  details = false,
bool  msonly = false 
)

Show the elapsed time and lap count as a human readable string. The function only uses public information, so callers need not use this method if they don't like the particular formatting being done.

The result of getValue() points to a class member that is overwritten at each call. So this method is definitely not thread safe. But safe to call in two different instances at the same time. The result from getValue_s() is thread safe because caller supplies the buffer,

By default the result is shown in a "reasonable" unit. us, ms, s, etc. depending on the elapsed time. This can be confusing if printing a list of timers wanting to quickly see where the time is being spent. Pass msonly=true for those cases.

Parameters
detailsIf true, include the timer name.
msonlyIf true, always show result in milliseconds.

◆ getValue_s()

void InternalZGY::Timer::getValue_s ( char *  result,
int  buffer_size,
const char *  name,
int  count,
double  total,
bool  running,
bool  details,
bool  msonly 
)
static

Show the elapsed time and lap count as a human readable string. The function only uses public information, so callers need not use this method if they don't like the particular formatting being done.

The result of getValue() points to a class member that is overwritten at each call. So this method is definitely not thread safe. But safe to call in two different instances at the same time. The result from getValue_s() is thread safe because caller supplies the buffer,

By default the result is shown in a "reasonable" unit. us, ms, s, etc. depending on the elapsed time. This can be confusing if printing a list of timers wanting to quickly see where the time is being spent. Pass msonly=true for those cases.

Parameters
detailsIf true, include the timer name.
msonlyIf true, always show result in milliseconds.

The documentation for this class was generated from the following files:
InternalZGY::Timer::Timer
Timer(bool enable=true, const char *name=0, int skip=0, bool startrunning=true)
Definition: timer.cpp:113