summaryrefslogtreecommitdiff
path: root/ace/Profile_Timer.h
blob: 63d055db4dcc553073c95d46eb005f2ca41b66dc (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
/* -*- C++ -*- */
// $Id$

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

#ifndef ACE_PROFILE_TIMER_H
#define ACE_PROFILE_TIMER_H

#include "ace/ACE.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

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

class ACE_Export ACE_Profile_Timer
{
  // = TITLE
  //     This class provides both a timing mechanism and a mechanism
  //     for reporting the resource usage of a process.
public:

  class ACE_Elapsed_Time
  {
    // = TITLE
    //    Keeps track of the various user, system, and elapsed (real)
    //    times.
    //
    // = DESCRIPTION
    //   If <ACE_HAS_FLOATING_POINT> is enabled these values are in
    //   microseconds, otherwise, they are in seconds.
  public:
    ACE_timer_t real_time;
    ACE_timer_t user_time;
    ACE_timer_t system_time;
  };

  typedef ACE_Rusage Rusage;

  // = 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 (timespec_t &tdiff, timespec_t &t0, timespec_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.
#endif /* ACE_HAS_PRUSAGE_T */

#if defined (ACE_WIN32) || (!defined (ACE_HAS_PRUSAGE_T) && !defined (ACE_HAS_GETRUSAGE))
  ACE_High_Res_Timer timer_;
  // The high resolution timer
#endif /* ACE_WIN32 || !ACE_HAS_PRUSAGE_T && !ACE_HAS_GETRUSAGE */
};

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

#endif /* ACE_PROFILE_TIMER_H */