diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-12-31 21:04:53 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-12-31 21:04:53 +0000 |
commit | 1c89c16043f96f23b699a52ce31c0dc0cd2f6c51 (patch) | |
tree | ce5c965882164a1bab5a1ed5b57a62d87f41a661 | |
parent | d6ae1a1ed58cb8f66e7f0c90801d01b7dae210f0 (diff) | |
download | ATCD-1c89c16043f96f23b699a52ce31c0dc0cd2f6c51.tar.gz |
added comment to print_total () saying it should only be used for incremental timings; added defaults to a few print_ave/print_total args; trimmed output if count is 1; rounded instead of truncated usecs portion of time
-rw-r--r-- | ace/High_Res_Timer.cpp | 50 | ||||
-rw-r--r-- | ace/High_Res_Timer.h | 17 | ||||
-rw-r--r-- | ace/High_Res_Timer.i | 9 |
3 files changed, 51 insertions, 25 deletions
diff --git a/ace/High_Res_Timer.cpp b/ace/High_Res_Timer.cpp index c345c407ec9..4f04453ace6 100644 --- a/ace/High_Res_Timer.cpp +++ b/ace/High_Res_Timer.cpp @@ -32,42 +32,58 @@ ACE_High_Res_Timer::reset (void) (void) ACE_OS::memset (&this->temp_, 0, sizeof this->temp_); } -ACE_High_Res_Timer::ACE_High_Res_Timer (void) -{ - ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer"); - this->reset (); -} - void -ACE_High_Res_Timer::print_ave (char *str, int count, ACE_HANDLE handle) +ACE_High_Res_Timer::print_ave (const char *str, const int count, ACE_HANDLE handle) { ACE_TRACE ("ACE_High_Res_Timer::print_ave"); #if defined (ACE_HAS_LONGLONG_T) hrtime_t total = this->end_ - this->start_; - hrtime_t avg_nsecs = total / count; hrtime_t total_secs = total / (1000 * 1000 * 1000); - hrtime_t extra_nsecs = total - (total_secs * (1000 * 1000 * 1000)); - char buf[100]; + u_long extra_nsecs = total - (total_secs * (1000 * 1000 * 1000)); - ACE_OS::sprintf (buf, "%s count = %d, total (secs %lld, usecs %lld), avg usecs = %lld\n", - str, count, total_secs, extra_nsecs / 1000, avg_nsecs / 1000); + char buf[100]; + if (count > 1) + { + hrtime_t avg_nsecs = total / count; + ACE_OS::sprintf (buf, " count = %d, total (secs %lld, usecs %lu), avg usecs = %lld\n", + count, total_secs, (extra_nsecs + 500) / 1000, + (avg_nsecs + 500) / 1000); + } + else + ACE_OS::sprintf (buf, " total %3lld.%06lu secs\n", + total_secs, (extra_nsecs + 500) / 1000); + + ACE_OS::write (handle, str, strlen (str)); ACE_OS::write (handle, buf, strlen (buf)); +#else +# error must have ACE_HAS_LONGLONG_T with ACE_HAS_HI_RES_TIMER #endif /* ACE_HAS_LONGLONG_T */ } void -ACE_High_Res_Timer::print_total (char *str, int count, ACE_HANDLE handle) +ACE_High_Res_Timer::print_total (const char *str, const int count, ACE_HANDLE handle) { ACE_TRACE ("ACE_High_Res_Timer::print_total"); #if defined (ACE_HAS_LONGLONG_T) - hrtime_t avg_nsecs = this->total_ / count; hrtime_t total_secs = this->total_ / (1000 * 1000 * 1000); - hrtime_t extra_nsecs = this->total_ - (total_secs * (1000 * 1000 * 1000)); + u_long extra_nsecs = this->total_ - (total_secs * (1000 * 1000 * 1000)); + char buf[100]; + if (count > 1) + { + hrtime_t avg_nsecs = this->total_ / count; + ACE_OS::sprintf (buf, " count = %d, total (secs %lld, usecs %lu), avg usecs = %lld\n", + count, total_secs, (extra_nsecs + 500) / 1000, + (avg_nsecs + 500) / 1000); + } + else + ACE_OS::sprintf (buf, " total %3lld.%06lu secs\n", + total_secs, (extra_nsecs + 500) / 1000); - ACE_OS::sprintf (buf, "%s count = %d, total (secs %lld, usecs %lld), avg usecs = %lld\n", - str, count, total_secs, extra_nsecs / 1000, avg_nsecs / 1000); + ACE_OS::write (handle, str, strlen (str)); ACE_OS::write (handle, buf, strlen (buf)); +#else +# error must have ACE_HAS_LONGLONG_T with ACE_HAS_HI_RES_TIMER #endif /* ACE_HAS_LONGLONG_T */ } #endif /* ACE_HAS_HI_RES_TIMER */ diff --git a/ace/High_Res_Timer.h b/ace/High_Res_Timer.h index 76ac9409fff..b0a31a7c057 100644 --- a/ace/High_Res_Timer.h +++ b/ace/High_Res_Timer.h @@ -48,14 +48,15 @@ public: void stop_incr (void); // Stop incremental timing. - void print_total (char *message, - int iterations, - ACE_HANDLE handle); - // Print total time. - - void print_ave (char *message, - int iterations, - ACE_HANDLE handle); + void print_total (const char *message, + const int iterations = 1, + ACE_HANDLE handle = ACE_STDOUT); + // Print total time. NOTE: only use print_total () + // if incremental timings had been used! + + void print_ave (const char *message, + const int iterations = 1, + ACE_HANDLE handle = ACE_STDOUT); // Print average time. void dump (void) const; diff --git a/ace/High_Res_Timer.i b/ace/High_Res_Timer.i index c33a1ded0c4..ac2182fa8f4 100644 --- a/ace/High_Res_Timer.i +++ b/ace/High_Res_Timer.i @@ -5,6 +5,13 @@ #if defined (ACE_HAS_HI_RES_TIMER) +ACE_INLINE +ACE_High_Res_Timer::ACE_High_Res_Timer (void) +{ + ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer"); + this->reset (); +} + ACE_INLINE void ACE_High_Res_Timer::start (void) { @@ -32,6 +39,8 @@ ACE_High_Res_Timer::stop_incr (void) ACE_TRACE ("ACE_High_Res_Timer::stop_incr"); #if defined (ACE_HAS_LONGLONG_T) this->total_ += (ACE_OS::gethrtime () - this->temp_); +#else +# error must have ACE_HAS_LONGLONG_T with ACE_HAS_HI_RES_TIMER #endif /* ACE_HAS_LONGLONG_T */ } #endif /* ACE_HAS_HI_RES_TIMER */ |