00001 // -*- C++ -*- 00002 // 00003 // $Id: Profile_Timer.inl 69619 2005-11-24 09:48:55Z ossama $ 00004 00005 #include "ace/OS_NS_sys_time.h" 00006 #include "ace/OS_NS_sys_resource.h" 00007 #include "ace/Global_Macros.h" 00008 00009 #if (defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE)) && !defined (ACE_WIN32) 00010 00011 # if defined (ACE_HAS_PRUSAGE_T) 00012 # include "ace/OS_NS_stropts.h" 00013 00014 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00015 00016 ACE_INLINE int 00017 ACE_Profile_Timer::start (void) 00018 { 00019 ACE_TRACE ("ACE_Profile_Timer::start"); 00020 return ACE_OS::ioctl (this->proc_handle_, 00021 PIOCUSAGE, 00022 &this->begin_usage_); 00023 } 00024 00025 ACE_INLINE int 00026 ACE_Profile_Timer::stop (void) 00027 { 00028 ACE_TRACE ("ACE_Profile_Timer::stop"); 00029 this->last_usage_ = this->end_usage_; 00030 return ACE_OS::ioctl (this->proc_handle_, 00031 PIOCUSAGE, 00032 &this->end_usage_); 00033 } 00034 00035 ACE_END_VERSIONED_NAMESPACE_DECL 00036 00037 # elif defined (ACE_HAS_GETRUSAGE) 00038 00039 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00040 00041 ACE_INLINE int 00042 ACE_Profile_Timer::start (void) 00043 { 00044 ACE_TRACE ("ACE_Profile_Timer::start"); 00045 this->begin_time_ = ACE_OS::gettimeofday (); 00046 ACE_OS::getrusage (RUSAGE_SELF, 00047 &this->begin_usage_); 00048 return 0; 00049 } 00050 00051 ACE_INLINE int 00052 ACE_Profile_Timer::stop (void) 00053 { 00054 ACE_TRACE ("ACE_Profile_Timer::stop"); 00055 this->last_time_ = this->end_time_; 00056 this->end_time_ = ACE_OS::gettimeofday (); 00057 this->last_usage_ = this->end_usage_; 00058 ACE_OS::getrusage (RUSAGE_SELF, 00059 &this->end_usage_); 00060 return 0; 00061 } 00062 00063 ACE_END_VERSIONED_NAMESPACE_DECL 00064 00065 # endif /* ACE_HAS_PRUSAGE_T */ 00066 00067 #elif defined (ACE_WIN32) 00068 00069 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00070 00071 ACE_INLINE 00072 ACE_Profile_Timer::~ACE_Profile_Timer (void) 00073 { 00074 } 00075 00076 ACE_INLINE int 00077 ACE_Profile_Timer::start (void) 00078 { 00079 ACE_TRACE ("ACE_Profile_Timer::start"); 00080 # if defined (ACE_HAS_GETRUSAGE) 00081 ACE_OS::getrusage (RUSAGE_SELF, 00082 &this->begin_usage_); 00083 # endif /* ACE_HAS_GETRUSAGE */ 00084 this->timer_.start (); 00085 return 0; 00086 } 00087 00088 ACE_INLINE int 00089 ACE_Profile_Timer::stop (void) 00090 { 00091 ACE_TRACE ("ACE_Profile_Timer::stop"); 00092 this->timer_.stop (); 00093 # if defined (ACE_HAS_GETRUSAGE) 00094 this->last_usage_ = this->end_usage_; 00095 ACE_OS::getrusage (RUSAGE_SELF, &this->end_usage_); 00096 # endif /* ACE_HAS_GETRUSAGE */ 00097 return 0; 00098 } 00099 00100 ACE_END_VERSIONED_NAMESPACE_DECL 00101 00102 #else 00103 00104 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00105 00106 ACE_INLINE int 00107 ACE_Profile_Timer::start (void) 00108 { 00109 ACE_TRACE ("ACE_Profile_Timer::start"); 00110 this->timer_.start (); 00111 return 0; 00112 } 00113 00114 ACE_INLINE int 00115 ACE_Profile_Timer::stop (void) 00116 { 00117 ACE_TRACE ("ACE_Profile_Timer::stop"); 00118 this->timer_.stop (); 00119 return 0; 00120 } 00121 00122 ACE_INLINE 00123 ACE_Profile_Timer::~ACE_Profile_Timer (void) 00124 { 00125 } 00126 00127 ACE_END_VERSIONED_NAMESPACE_DECL 00128 00129 #endif /* defined (ACE_HAS_PRUSAGE_T) || defined (ACE_HAS_GETRUSAGE) */