Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Profile_Timer.h

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

Generated on Mon Jun 16 11:20:56 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002