Profile_Timer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //==========================================================================
00004 /**
00005  *  @file    Profile_Timer.h
00006  *
00007  *  Profile_Timer.h,v 4.29 2006/05/30 11:11:09 jwillemsen Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //==========================================================================
00012 
00013 
00014 #ifndef ACE_PROFILE_TIMER_H
00015 #define ACE_PROFILE_TIMER_H
00016 #include /**/ "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #include "ace/High_Res_Timer.h"
00025 
00026 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00027 
00028 /**
00029  * @class ACE_Profile_Timer
00030  *
00031  * @brief This class provides both a timing mechanism and a mechanism
00032  * for reporting the resource usage of a process.
00033  */
00034 class ACE_Export ACE_Profile_Timer
00035 {
00036 public:
00037 
00038   /**
00039    * @class ACE_Elapsed_Time
00040    *
00041    * @brief Keeps track of the various user, system, and elapsed (real)
00042    * times.
00043    */
00044   class ACE_Elapsed_Time
00045   {
00046   public:
00047     /// Elapsed wall clock time.
00048     ACE_timer_t real_time;
00049 
00050     /// CPU time spent in user space.
00051     ACE_timer_t user_time;
00052 
00053     /// CPU time spent in system space.
00054     ACE_timer_t system_time;
00055   };
00056 
00057   typedef ACE_Rusage Rusage;
00058 
00059   // = Initialization and termination methods.
00060   /// Default constructor. Clears all time values to 0.
00061   ACE_Profile_Timer (void);
00062 
00063   /// Shutdown the timer.
00064   ~ACE_Profile_Timer (void);
00065 
00066   // = Timer methods.
00067   /// Activate the timer.
00068   int start (void);
00069 
00070   /// Stop the timer.
00071   int stop (void);
00072 
00073   // = Resource utilization methods.
00074   /// Compute the time elapsed between calls to @c start() and @c stop().
00075   int elapsed_time (ACE_Elapsed_Time &et);
00076 
00077   /// Compute the amount of resource utilization between calls to @c start()
00078   /// and @c stop().
00079   void elapsed_rusage (ACE_Profile_Timer::Rusage &rusage);
00080 
00081   /// Return the resource utilization (don't recompute it).
00082   void get_rusage (ACE_Profile_Timer::Rusage &rusage);
00083 
00084   /// Dump the state of an object.
00085   void dump (void) const;
00086 
00087   /// Declare the dynamic allocation hooks.
00088   ACE_ALLOC_HOOK_DECLARE;
00089 
00090 private:
00091   /// Compute how much time has elapsed.
00092   void compute_times (ACE_Elapsed_Time &et);
00093 
00094   /// Keep track of the starting resource utilization.
00095   ACE_Profile_Timer::Rusage begin_usage_;
00096 
00097   /// Keep track of the ending resource utilization.
00098   ACE_Profile_Timer::Rusage end_usage_;
00099 
00100   /// Keep track of the last rusage for incremental timing.
00101   ACE_Profile_Timer::Rusage last_usage_;
00102 
00103 #if defined (ACE_HAS_PRUSAGE_T)
00104   /// Substract two timestructs and store their difference.
00105   void subtract (timespec_t &tdiff, timespec_t &t0, timespec_t &t1);
00106 
00107   /// I/O handle for /proc file system.
00108   ACE_HANDLE proc_handle_;
00109 
00110 #elif defined (ACE_HAS_GETRUSAGE)
00111   /// Substract two timestructs and store their difference.
00112   void subtract (timeval &tdiff,
00113                  timeval &t0,
00114                  timeval &t1);
00115 
00116   /// Keep track of the beginning time.
00117   timeval begin_time_;
00118 
00119   /// Keep track of the ending time.
00120   timeval end_time_;
00121 
00122   /// Keep track of the last time for incremental timing.
00123   timeval last_time_;
00124 #endif /* ACE_HAS_PRUSAGE_T */
00125 
00126 #if defined (ACE_WIN32) || (!defined (ACE_HAS_PRUSAGE_T) && !defined (ACE_HAS_GETRUSAGE))
00127   /// The high resolution timer
00128   ACE_High_Res_Timer timer_;
00129 #endif /* ACE_WIN32 || !ACE_HAS_PRUSAGE_T && !ACE_HAS_GETRUSAGE */
00130 };
00131 
00132 ACE_END_VERSIONED_NAMESPACE_DECL
00133 
00134 #if defined (__ACE_INLINE__)
00135 # include "ace/Profile_Timer.inl"
00136 #endif /* __ACE_INLINE__ */
00137 
00138 #include /**/ "ace/post.h"
00139 #endif /* ACE_PROFILE_TIMER_H */

Generated on Thu Nov 9 09:42:00 2006 for ACE by doxygen 1.3.6