3 //==========================================================================
5 * @file Profile_Timer.h
7 * $Id: Profile_Timer.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
11 //==========================================================================
14 #ifndef ACE_PROFILE_TIMER_H
15 #define ACE_PROFILE_TIMER_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/config-all.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/High_Res_Timer.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 * @class ACE_Profile_Timer
31 * @brief This class provides both a timing mechanism and a mechanism
32 * for reporting the resource usage of a process.
34 class ACE_Export ACE_Profile_Timer
39 * @class ACE_Elapsed_Time
41 * @brief Keeps track of the various user, system, and elapsed (real)
44 class ACE_Elapsed_Time
47 /// Elapsed wall clock time.
48 ACE_timer_t real_time
;
50 /// CPU time spent in user space.
51 ACE_timer_t user_time
;
53 /// CPU time spent in system space.
54 ACE_timer_t system_time
;
57 typedef ACE_Rusage Rusage
;
59 // = Initialization and termination methods.
60 /// Default constructor. Clears all time values to 0.
61 ACE_Profile_Timer (void);
63 /// Shutdown the timer.
64 ~ACE_Profile_Timer (void);
67 /// Activate the timer.
73 // = Resource utilization methods.
74 /// Compute the time elapsed between calls to @c start() and @c stop().
75 int elapsed_time (ACE_Elapsed_Time
&et
);
77 /// Compute the amount of resource utilization between calls to @c start()
79 void elapsed_rusage (ACE_Profile_Timer::Rusage
&rusage
);
81 /// Return the resource utilization (don't recompute it).
82 void get_rusage (ACE_Profile_Timer::Rusage
&rusage
);
84 /// Dump the state of an object.
85 void dump (void) const;
87 /// Declare the dynamic allocation hooks.
88 ACE_ALLOC_HOOK_DECLARE
;
91 /// Compute how much time has elapsed.
92 void compute_times (ACE_Elapsed_Time
&et
);
94 /// Keep track of the starting resource utilization.
95 ACE_Profile_Timer::Rusage begin_usage_
;
97 /// Keep track of the ending resource utilization.
98 ACE_Profile_Timer::Rusage end_usage_
;
100 /// Keep track of the last rusage for incremental timing.
101 ACE_Profile_Timer::Rusage last_usage_
;
103 #if defined (ACE_HAS_PRUSAGE_T)
104 /// Substract two timestructs and store their difference.
105 void subtract (timespec_t
&tdiff
, timespec_t
&t0
, timespec_t
&t1
);
107 /// I/O handle for /proc file system.
108 ACE_HANDLE proc_handle_
;
110 #elif defined (ACE_HAS_GETRUSAGE)
111 /// Substract two timestructs and store their difference.
112 void subtract (timeval
&tdiff
,
116 /// Keep track of the beginning time.
119 /// Keep track of the ending time.
122 /// Keep track of the last time for incremental timing.
124 #endif /* ACE_HAS_PRUSAGE_T */
126 #if defined (ACE_WIN32) || (!defined (ACE_HAS_PRUSAGE_T) && !defined (ACE_HAS_GETRUSAGE))
127 /// The high resolution timer
128 ACE_High_Res_Timer timer_
;
129 #endif /* ACE_WIN32 || !ACE_HAS_PRUSAGE_T && !ACE_HAS_GETRUSAGE */
132 ACE_END_VERSIONED_NAMESPACE_DECL
134 #if defined (__ACE_INLINE__)
135 # include "ace/Profile_Timer.inl"
136 #endif /* __ACE_INLINE__ */
138 #include /**/ "ace/post.h"
139 #endif /* ACE_PROFILE_TIMER_H */