summaryrefslogtreecommitdiff
path: root/ace/High_Res_Timer.h
blob: e7a40ba1dea2887695e7f18a193b174786ec93aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- C++ -*- */
// $Id$


// ============================================================================
//
// = LIBRARY
//    ace
// 
// = FILENAME
//    High_Res_Timer.h
//
// = AUTHOR
//    Doug Schmidt 
// 
// ============================================================================

#if !defined (ACE_HIGH_RES_TIMER_H)
#define ACE_HIGH_RES_TIMER_H

#include "ace/ACE.h"

#if defined (ACE_HAS_HI_RES_TIMER) || defined (ACE_HAS_AIX_HIRES_TIMER)

class ACE_Export ACE_High_Res_Timer
  // = TITLE
  //     A high resolution timer class wrapper that encapsulates
  //     Solaris timers. 
{
public:
  // = Initialization method.

  ACE_High_Res_Timer (void);
  // Initialize the timer.

  void reset (void);
  // Reinitialize the timer.

  void start (void);
  // Start timing.

  void stop (void);
  // Stop timing.

  void start_incr (void);
  // Start incremental timing.

  void stop_incr (void);
  // Stop incremental timing.

#if defined (ACE_HAS_POSIX_TIME)
  const timespec_t &elapsed_time (void);
  // returns the elapsed (stop - start) time in a timespec_t (sec, nsec)
#endif /* ACE_HAS_POSIX_TIME */

  void elapsed_microseconds (hrtime_t &usecs) const;
  // Sets <usecs> to the elapsed (stop - start) time in microseconds

  void print_total (const char *message,
		    const int iterations = 1,
		    ACE_HANDLE handle = ACE_STDOUT);
  // Print total time.  NOTE:  only use print_total ()
  // if incremental timings had been used!

  void print_ave (const char *message,
		  const int iterations = 1,
		  ACE_HANDLE handle = ACE_STDOUT);
  // Print average time.

  void dump (void) const;
  // Dump the state of an object.

  ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

private:
  hrtime_t start_;
  // Starting time.

  hrtime_t end_;
  // Ending time.

  hrtime_t total_;
  // Total elapsed time.

  hrtime_t temp_;
  // Temp time used for incremental timing.

#if defined (ACE_HAS_POSIX_TIME)
  timespec_t elapsed_time_;
#endif /* ACE_HAS_POSIX_TIME */
};

#if defined (__ACE_INLINE__)
#include "ace/High_Res_Timer.i"
#endif /* __ACE_INLINE__ */

#endif /* ACE_HAS_HI_RES_TIMER || ACE_HAS_AIX_HIRES_TIMER */
#endif /* ACE_HIGH_RES_TIMER_H */