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
//===============================================================
Shinya Kitaoka 120a6e
/**
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:
Shinya Kitaoka 120a6e
    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
Shinya Kitaoka 120a6e
#define TM_USER                                                                \
Shinya Kitaoka 120a6e
  __int64  // user time (time associated to the process calling stop
Shinya Kitaoka 120a6e
           // watch)(unit=100-nanosecond)
Shinya Kitaoka 120a6e
#define TM_SYSTEM __int64  // system time (unit=100-nanosecond)
Shinya Kitaoka 120a6e
#define START DWORD        // total starting reference time in milliseconds
Shinya Kitaoka 120a6e
#define START_USER                                                             \
Shinya Kitaoka 120a6e
  FILETIME  // process starting reference time (unit=100-nanosecond)
Shinya Kitaoka 120a6e
#define START_SYSTEM                                                           \
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
class DVAPI TStopWatch {
Shinya Kitaoka 120a6e
  std::string m_name;  // stopwatch name
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  TM_TOTAL m_tm;         // elapsed total time (in milliseconds)
Shinya Kitaoka 38fd86
  TM_USER m_tmUser;      // elapsed user time (time associated to the process
Shinya Kitaoka 38fd86
                         // calling stop watch)(unit=100-nanosecond)
Shinya Kitaoka 120a6e
  TM_SYSTEM m_tmSystem;  // elapsed system time (unit=100-nanosecond)
Shinya Kitaoka 120a6e
  START m_start;         // total starting reference time in milliseconds
Shinya Kitaoka 120a6e
  START_USER
Shinya Kitaoka 38fd86
  m_startUser;  // process starting reference time (unit=100-nanosecond)
Shinya Kitaoka 120a6e
  START_SYSTEM
Shinya Kitaoka 38fd86
  m_startSystem;  // system starting reference time  (unit=100-nanosecond)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  LARGE_INTEGER m_hrStart;  // high resolution starting reference (total) time
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_active;     // sw e' stato usato (e' stato invocato il metodo start())
Shinya Kitaoka 120a6e
  bool m_isRunning;  // fra start() e stop()
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setStartToCurrentTime();
Shinya Kitaoka 120a6e
  void getElapsedTime(TM_TOTAL &tm, TM_USER &user, TM_SYSTEM &system);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TStopWatch(std::string name = "");
Shinya Kitaoka 120a6e
  ~TStopWatch();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void reset();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Start the stop watch. If reset=true the stop watch is firstly reset.*/
Shinya Kitaoka 120a6e
  void start(bool resetFlag = false);
Shinya Kitaoka 120a6e
  void stop();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Returns the number of milliseconds that have elapsed in all the
Shinya Kitaoka 120a6e
start()-stop() intervals since
luz.paz ff76b7
the stopWatch was reset up to the getTotalTime() call. The method can be
Shinya Kitaoka 120a6e
called during a start()-stop() interval */
Shinya Kitaoka 120a6e
  TUINT32 getTotalTime();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Returns the amount of time that the process has spent executing application
Shinya Kitaoka 120a6e
   * code. see getTotalTime() */
Shinya Kitaoka 120a6e
  TUINT32 getUserTime();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Returns the amount of time that the process has spent executing operating
Shinya Kitaoka 120a6e
   * system code. see getTotalTime() */
Shinya Kitaoka 120a6e
  TUINT32 getSystemTime();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::string &getName() { return m_name; };
Shinya Kitaoka 120a6e
  void setName(std::string name) { m_name = name; };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Returns a string containing the recorded times.*/
Shinya Kitaoka 120a6e
  operator std::string();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*!Print (to cout) the name and the relative total,user and system times of
Shinya Kitaoka 120a6e
   * the stop watch. see getTotalTime()*/
Shinya Kitaoka 120a6e
  void print(std::ostream &out);
Shinya Kitaoka 120a6e
  void print();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  static TStopWatch StopWatch[10];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  /*!
Shinya Kitaoka 120a6e
TStopWatch::global(index) is a global array of 10 stop watches.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  static TStopWatch &global(int index) {
Shinya Kitaoka 120a6e
    assert(0 <= index && index < 10);
Shinya Kitaoka 120a6e
    return StopWatch[index];
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*!
Toshihiro Shimizu 890ddd
Allows you to print the name and the relative total,
Shinya Kitaoka 120a6e
user and system times of all the active stop watches.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
  static void printGlobals(std::ostream &out);
Shinya Kitaoka 120a6e
  static void printGlobals();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  //  __T_STOPWATCH_INCLUDED