summaryrefslogtreecommitdiff
path: root/ace/Profile_Timer.h
blob: 4234aef14f617c001fe62b3515302a7b0fa2b651 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* -*- C++ -*- */
// $Id$


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

#if !defined (ACE_PROFILE_TIMER_H)
#define ACE_PROFILE_TIMER_H

#include "ace/ACE.h"
#include "ace/Time_Value.h"

#if !(defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE))

class ACE_Export ACE_Profile_Timer
{
public:
  struct ACE_Elapsed_Time
    {
      double real_time;
      double user_time;
      double system_time;
    };

  ACE_Profile_Timer (void) {}
  ~ACE_Profile_Timer (void) {}
  int  start (void) { errno = ENOTSUP; return -1; }
  int  stop (void) { errno = ENOTSUP; return -1; }
  int  elapsed_time (ACE_Elapsed_Time &et) { errno = ENOTSUP; return -1; }
};
#else
class ACE_Export ACE_Profile_Timer
  // = TITLE
  //     A C++ wrapper for UNIX interval timers.
{
public:
  struct ACE_Elapsed_Time
    {
      double real_time;
      double user_time;
      double system_time;
    };

#if defined (ACE_HAS_PRUSAGE_T)
    typedef prusage_t Rusage;
#elif defined (ACE_HAS_GETRUSAGE)
    typedef rusage Rusage;
#endif /* ACE_HAS_PRUSAGE_T */

  // = Initialization and termination methods.
  ACE_Profile_Timer (void);
  // Default constructor.
  
  ~ACE_Profile_Timer (void);
  // Shutdown the timer.

  // = Timer methods.
  int start (void);
  // Activate the timer.

  int stop (void);
  // Stop the timer.

  // = Resource utilization methods.
  int elapsed_time (ACE_Elapsed_Time &et);
  // Compute the time elapsed since <start>.

  void elapsed_rusage (ACE_Profile_Timer::Rusage &rusage);
  // Compute the amount of resource utilization since the start time. 
  
  void get_rusage (ACE_Profile_Timer::Rusage &rusage);
  // Return the resource utilization (don't recompute it).

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

  ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

private:
  void compute_times (ACE_Elapsed_Time &et);
  // Compute how much time has elapsed.

  ACE_Profile_Timer::Rusage begin_usage_;
  // Keep track of the starting resource utilization.

  ACE_Profile_Timer::Rusage end_usage_;
  // Keep track of the ending resource utilization.

  ACE_Profile_Timer::Rusage last_usage_;
  // Keep track of the last rusage for incremental timing.

#if defined (ACE_HAS_PRUSAGE_T)
  void subtract (timestruc_t &tdiff, timestruc_t &t0, timestruc_t &t1);
  // Substract two timestructs and store their difference.

  ACE_HANDLE proc_handle_;
  // I/O handle for /proc file system.

#elif defined (ACE_HAS_GETRUSAGE)
  void subtract (timeval &tdiff, timeval &t0, timeval &t1);
  // Substract two timestructs and store their difference.

  timeval begin_time_;
  // Keep track of the beginning time.

  timeval end_time_;
  // Keep track of the ending time.

  timeval last_time_;
  // Keep track of the last time for incremental timing.
#elif defined (ACE_WIN32)
  ACE_Time_Value begin_time_;
  // Keep track of the beginning time.

  ACE_Time_Value end_time_;
  // Keep track of the ending time.

  ACE_Time_Value last_time_;
  // Keep track of the last time for incremental timing.

#endif /* ACE_HAS_PRUSAGE_T */
};

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

#endif /* defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE) */
#endif /* ACE_PROFILE_TIMER_H */