|
Shinya Kitaoka |
810553 |
#pragma once
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef T_STOPWATCH_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
#define T_STOPWATCH_INCLUDED
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#undef DVAPI
|
|
Toshihiro Shimizu |
890ddd |
#undef DVVAR
|
|
Toshihiro Shimizu |
890ddd |
#ifdef TNZCORE_EXPORTS
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_EXPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_EXPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define DVAPI DV_IMPORT_API
|
|
Toshihiro Shimizu |
890ddd |
#define DVVAR DV_IMPORT_VAR
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
#include "windows.h"
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//===============================================================
|
|
Toshihiro Shimizu |
890ddd |
/**
|
|
Toshihiro Shimizu |
890ddd |
* This is an example of how to use stopwatch.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
/*! The TStopWatch class allows you to recording time (in milliseconds)
|
|
Toshihiro Shimizu |
890ddd |
taken by your process or by system to perform various tasks.
|
|
Toshihiro Shimizu |
890ddd |
It is possible to record these times:
|
|
Toshihiro Shimizu |
890ddd |
Total Time, User Time and System Time.
|
|
Toshihiro Shimizu |
890ddd |
A stop watch is identified by a name that describes meaningfully its use.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define TM_TOTAL DWORD
|
|
Toshihiro Shimizu |
890ddd |
#define TM_USER __int64 //user time (time associated to the process calling stop watch)(unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
#define TM_SYSTEM __int64 //system time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
#define START DWORD //total starting reference time in milliseconds
|
|
Toshihiro Shimizu |
890ddd |
#define START_USER FILETIME //process starting reference time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
#define START_SYSTEM FILETIME //system starting reference time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define TM_TOTAL clock_t
|
|
Toshihiro Shimizu |
890ddd |
#define TM_USER clock_t
|
|
Toshihiro Shimizu |
890ddd |
#define TM_SYSTEM clock_t
|
|
Toshihiro Shimizu |
890ddd |
#define START clock_t
|
|
Toshihiro Shimizu |
890ddd |
#define START_USER clock_t
|
|
Toshihiro Shimizu |
890ddd |
#define START_SYSTEM clock_t
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
class DVAPI TStopWatch
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
3bfa54 |
std::string m_name; //stopwatch name
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TM_TOTAL m_tm; //elapsed total time (in milliseconds)
|
|
Toshihiro Shimizu |
890ddd |
TM_USER m_tmUser; //elapsed user time (time associated to the process calling stop watch)(unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
TM_SYSTEM m_tmSystem; //elapsed system time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
START m_start; //total starting reference time in milliseconds
|
|
Toshihiro Shimizu |
890ddd |
START_USER m_startUser; //process starting reference time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
START_SYSTEM m_startSystem; //system starting reference time (unit=100-nanosecond)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
Toshihiro Shimizu |
890ddd |
LARGE_INTEGER m_hrStart; // high resolution starting reference (total) time
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool m_active; // sw e' stato usato (e' stato invocato il metodo start())
|
|
Toshihiro Shimizu |
890ddd |
bool m_isRunning; // fra start() e stop()
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void setStartToCurrentTime();
|
|
Toshihiro Shimizu |
890ddd |
void getElapsedTime(TM_TOTAL &tm, TM_USER &user, TM_SYSTEM &system);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
3bfa54 |
TStopWatch(std::string name = "");
|
|
Toshihiro Shimizu |
890ddd |
~TStopWatch();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void reset();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Start the stop watch. If reset=true the stop watch is firstly reset.*/
|
|
Toshihiro Shimizu |
890ddd |
void start(bool resetFlag = false);
|
|
Toshihiro Shimizu |
890ddd |
void stop();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Returns the number of milliseconds that have elapsed in all the start()-stop() intervals since
|
|
Toshihiro Shimizu |
890ddd |
the stopWatch was resetted up to the getTotalTime() call. The method can be called during a start()-stop() interval */
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getTotalTime();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Returns the amount of time that the process has spent executing application code. see getTotalTime() */
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getUserTime();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Returns the amount of time that the process has spent executing operating system code. see getTotalTime() */
|
|
Toshihiro Shimizu |
890ddd |
TUINT32 getSystemTime();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
const std::string &getName() { return m_name; };
|
|
Shinya Kitaoka |
3bfa54 |
void setName(std::string name) { m_name = name; };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Returns a string containing the recorded times.*/
|
|
Shinya Kitaoka |
3bfa54 |
operator std::string();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!Print (to cout) the name and the relative total,user and system times of the stop watch. see getTotalTime()*/
|
|
Shinya Kitaoka |
3bfa54 |
void print(std::ostream &out);
|
|
Toshihiro Shimizu |
890ddd |
void print();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
private:
|
|
Toshihiro Shimizu |
890ddd |
static TStopWatch StopWatch[10];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
TStopWatch::global(index) is a global array of 10 stop watches.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
static TStopWatch &global(int index)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(0 <= index && index < 10);
|
|
Toshihiro Shimizu |
890ddd |
return StopWatch[index];
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Allows you to print the name and the relative total,
|
|
Toshihiro Shimizu |
890ddd |
user and system times of all the active stop watches.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
3bfa54 |
static void printGlobals(std::ostream &out);
|
|
Toshihiro Shimizu |
890ddd |
static void printGlobals();
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif // __T_STOPWATCH_INCLUDED
|