#include <High_Res_Timer.h>
Public Member Functions | |
ACE_High_Res_Timer (void) | |
Initialize the timer. | |
~ACE_High_Res_Timer (void) | |
Destructor. | |
void | reset (void) |
Reinitialize the timer. | |
void | start (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
Start timing. | |
void | stop (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
Stop timing. | |
void | elapsed_time (ACE_Time_Value &tv) const |
Set tv to the number of microseconds elapsed. | |
void | elapsed_time (ACE_hrtime_t &nanoseconds) const |
Set nanoseconds to the number of nanoseconds elapsed. | |
void | elapsed_microseconds (ACE_hrtime_t &usecs) const |
Sets usecs to the elapsed (stop - start) time in microseconds. | |
void | start_incr (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
Start incremental timing. | |
void | stop_incr (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
Stop incremental timing. | |
void | elapsed_time_incr (ACE_Time_Value &tv) const |
void | elapsed_time_incr (ACE_hrtime_t &nanoseconds) const |
void | print_total (const ACE_TCHAR *message, const int iterations=1, ACE_HANDLE handle=ACE_STDOUT) const |
void | print_ave (const ACE_TCHAR *message, const int iterations=1, ACE_HANDLE handle=ACE_STDOUT) const |
Print average time. | |
void | dump (void) const |
Dump the state of an object. | |
Static Public Member Functions | |
void | global_scale_factor (ACE_UINT32 gsf) |
ACE_UINT32 | global_scale_factor (void) |
Returns the global_scale_factor. | |
int | get_env_global_scale_factor (const ACE_TCHAR *env=ACE_TEXT("ACE_SCALE_FACTOR")) |
ACE_UINT32 | calibrate (const ACE_UINT32 usec=500000, const u_int iterations=10) |
ACE_Time_Value | gettimeofday_hr (void) |
ACE_Time_Value | gettimeofday (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
void | hrtime_to_tv (ACE_Time_Value &tv, const ACE_hrtime_t hrt) |
Converts an to tv using global_scale_factor_. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Static Private Member Functions | |
ACE_hrtime_t | gettime (const ACE_OS::ACE_HRTimer_Op=ACE_OS::ACE_HRTIMER_GETTIME) |
ACE_hrtime_t | elapsed_hrtime (const ACE_hrtime_t end, const ACE_hrtime_t start) |
Private Attributes | |
ACE_hrtime_t | start_ |
Starting time. | |
ACE_hrtime_t | end_ |
Ending time. | |
ACE_hrtime_t | total_ |
Total elapsed time. | |
ACE_hrtime_t | start_incr_ |
Start time of incremental timing. | |
Static Private Attributes | |
ACE_UINT32 | global_scale_factor_ = 1u |
int | global_scale_factor_status_ = 0 |
Most of the member functions don't return values. The only reason that one would fail is if high-resolution time isn't supported on the platform. To avoid impacting performance and complicating the interface, in that case, <ACE_OS::gettimeofday> is used instead. The global scale factor is required for platforms that have high-resolution timers that return units other than microseconds, such as clock ticks. It is represented as a static u_long, can only be accessed through static methods, and is used by all instances of High Res Timer. The member functions that return or print times use the global scale factor. They divide the "time" that they get from <ACE_OS::gethrtime> by global_scale_factor_ to obtain the time in microseconds. Its units are therefore 1/microsecond. On Windows the global_scale_factor_ units are 1/millisecond. There's a macro which gives the units/second. Because it's possible that the units/second changes in the future, it's recommended to use it instead of a "hard coded" solution. Dependend on the platform and used class members, there's a maximum elapsed period before overflow (which is not checked). Look at the documentation with some members functions. On some (most?) implementations it's not recommended to measure "long" timeperiods, because the error's can accumulate fast. This is probably not a problem profiling code, but could be on if the high resolution timer class is used to initiate actions after a "long" timeout. On Solaris, a scale factor of 1000 should be used because its high-resolution timer returns nanoseconds. However, on Intel platforms, we use RDTSC which returns the number of clock ticks since system boot. For a 200MHz cpu, each clock tick is 1/200 of a microsecond; the global_scale_factor_ should therefore be 200 or 200000 if it's in unit/millisecond. On Windows ::QueryPerformanceCounter() is used, which can be a different implementation depending on the used windows HAL (Hardware Abstraction Layer). On some it uses the PC "timer chip" while it uses RDTSC on others.
Gabe <begeddov@proaxis.com> raises this issue regarding <ACE_OS::gethrtime>: on multi-processors, the processor that you query for your <timer.stop> value might not be the one you queried for <timer.start>. Its not clear how much divergence there would be, if any. This issue is not mentioned in the Solaris 2.5.1 gethrtime man page. A RDTSC NOTE: RDTSC is the Intel Pentium read-time stamp counter and is actualy a 64 bit clock cycle counter, which is increased with every cycle. It has a low overhead and can be read within 16 (pentium) or 32 (pentium II,III,...) cycles, but it doesn't serialize the processor, which could give wrong timings when profiling very short code fragments. Problematic is that some power sensitive devices (laptops for example, but probably also embedded devices), do change the cycle rate while running. Some pentiums can run on (at least) two clock frequency's. Another problem arises with multiprocessor computers, there are reports that the different RDTSC's are not always kept in sync. A windows "timer chip" NOTE: (8254-compatible real-time clock) When ::QueryPerformanceCounter() uses the 8254 it has a frequency off about 1.193 Mhz (or sometimes 3.579 Mhz?) and reading it requires some time (several thousand cycles).
Definition at line 100 of file High_Res_Timer.h.
|
Initialize the timer.
Definition at line 255 of file High_Res_Timer.cpp. References ACE_TRACE, global_scale_factor(), and reset().
00256 { 00257 ACE_TRACE ("ACE_High_Res_Timer::ACE_High_Res_Timer"); 00258 00259 this->reset (); 00260 00261 // Make sure that the global scale factor is set. 00262 (void) global_scale_factor (); 00263 } |
|
Destructor.
Definition at line 106 of file High_Res_Timer.inl.
00107 { 00108 } |
|
Set (and return, for info) the global scale factor by sleeping for usec and counting the number of intervening clock cycles. Average over iterations of usec each. On some platforms, such as Pentiums, this is called automatically during the first ACE_High_Res_Timer construction with the default parameter values. An application can override that by calling calibrate with any desired parameter values _prior_ to constructing the first ACE_High_Res_Timer instance. Beware for platforms that can change the cycle rate on the fly. Definition at line 266 of file High_Res_Timer.cpp. References ACE_hrtime_t, ACE_OS::gethrtime(), ACE_OS::gettimeofday(), global_scale_factor(), ACE_Stats::mean(), ACE_Time_Value::msec(), ACE_Stats::sample(), ACE_OS::sleep(), and ACE_Stats_Value::whole(). Referenced by global_scale_factor().
00268 { 00269 const ACE_Time_Value sleep_time (0, usec); 00270 ACE_Stats delta_hrtime; 00271 // In units of 100 usec, to avoid overflow. 00272 ACE_Stats actual_sleeps; 00273 00274 for (u_int i = 0; 00275 i < iterations; 00276 ++i) 00277 { 00278 const ACE_Time_Value actual_start = 00279 ACE_OS::gettimeofday (); 00280 const ACE_hrtime_t start = 00281 ACE_OS::gethrtime (); 00282 ACE_OS::sleep (sleep_time); 00283 const ACE_hrtime_t stop = 00284 ACE_OS::gethrtime (); 00285 const ACE_Time_Value actual_delta = 00286 ACE_OS::gettimeofday () - actual_start; 00287 00288 // Store the sample. 00289 delta_hrtime.sample (ACE_Utils::truncate_cast<ACE_INT32> (stop - start)); 00290 actual_sleeps.sample (actual_delta.msec () * 100u); 00291 } 00292 00293 // Calculate the mean value of the samples, with no fractional 00294 // precision. Use it for the global scale factor. 00295 ACE_Stats_Value ticks (0); 00296 delta_hrtime.mean (ticks); 00297 00298 ACE_Stats_Value actual_sleep (0); 00299 actual_sleeps.mean (actual_sleep); 00300 00301 // The addition of 5 below rounds instead of truncates. 00302 const ACE_UINT32 scale_factor = 00303 (ticks.whole () / actual_sleep.whole () + 5) / 00304 10u /* usec/100 usec */; 00305 ACE_High_Res_Timer::global_scale_factor (scale_factor); 00306 00307 return scale_factor; 00308 } |
|
Dump the state of an object.
Definition at line 311 of file High_Res_Timer.cpp. References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, end_, global_scale_factor(), LM_DEBUG, start_incr_, and total_. Referenced by ACE_Profile_Timer::dump().
00312 { 00313 #if defined (ACE_HAS_DUMP) 00314 ACE_TRACE ("ACE_High_Res_Timer::dump"); 00315 00316 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00317 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nglobal_scale_factor_: %u\n"), 00318 global_scale_factor ())); 00319 #if defined (ACE_LACKS_LONGLONG_T) 00320 ACE_DEBUG ((LM_DEBUG, 00321 ACE_TEXT (":\nstart_.hi (): %8x; start_.lo (): %8x;\n") 00322 ACE_TEXT ("end_.hi (): %8x; end_.lo (): %8x;\n") 00323 ACE_TEXT ("total_.hi (): %8x; total_.lo (): %8x;\n") 00324 ACE_TEXT ("start_incr_.hi () %8x; start_incr_.lo (): %8x;\n"), 00325 start_.hi (), start_.lo (), 00326 end_.hi (), end_.lo (), 00327 total_.hi (), total_.lo (), 00328 start_incr_.hi (), start_incr_.lo ())); 00329 #else /* ! ACE_LACKS_LONGLONG_T */ 00330 ACE_DEBUG ((LM_DEBUG, 00331 ACE_TEXT (":\nstart_.hi (): %8x; start_.lo (): %8x;\n") 00332 ACE_TEXT ("end_.hi (): %8x; end_.lo (): %8x;\n") 00333 ACE_TEXT ("total_.hi (): %8x; total_.lo (): %8x;\n") 00334 ACE_TEXT ("start_incr_.hi () %8x; start_incr_.lo (): %8x;\n"), 00335 static_cast<ACE_UINT32> (start_ >> 32), 00336 static_cast<ACE_UINT32> (start_ & 0xfffffffful), 00337 static_cast<ACE_UINT32> (end_ >> 32), 00338 static_cast<ACE_UINT32> (end_ & 0xfffffffful), 00339 static_cast<ACE_UINT32> (total_ >> 32), 00340 static_cast<ACE_UINT32> (total_ & 0xfffffffful), 00341 static_cast<ACE_UINT32> (start_incr_ >> 32), 00342 static_cast<ACE_UINT32> (start_incr_ & 0xfffffffful))); 00343 #endif /* ! ACE_LACKS_LONGLONG_T */ 00344 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00345 #endif /* ACE_HAS_DUMP */ 00346 } |
|
Calculate the difference between two ACE_hrtime_t values. It is assumed that the end time is later than start time, so if end is a smaller value, the time counter has wrapped around. Definition at line 97 of file High_Res_Timer.inl. References ACE_hrtime_t. Referenced by elapsed_microseconds(), elapsed_time(), and stop_incr().
00099 { 00100 if (end > start) 00101 return end - start; 00102 return (~start + 1 + end); // Wrapped-around counter diff 00103 } |
|
Sets usecs to the elapsed (stop - start) time in microseconds. Will overflow on windows when measuring more than appox. 2^^54 ticks. Is still more than 48 days with a 4 Ghz counter. Definition at line 141 of file High_Res_Timer.inl. References ACE_hrtime_t, elapsed_hrtime(), and global_scale_factor().
00142 { 00143 ACE_hrtime_t elapsed = ACE_High_Res_Timer::elapsed_hrtime (this->end_, 00144 this->start_); 00145 usecs = (ACE_hrtime_t) (elapsed / global_scale_factor ()); 00146 } |
|
Set nanoseconds to the number of nanoseconds elapsed. Will overflow when measuring more than 194 day's. Definition at line 403 of file High_Res_Timer.cpp. References ACE_hrtime_t, elapsed_hrtime(), and global_scale_factor().
00404 { 00405 // Please do _not_ rearrange this equation. It is carefully 00406 // designed and tested to avoid overflow on machines that don't have 00407 // native 64-bit ints. In particular, division can be a problem. 00408 // For more background on this, please see bugzilla #1024. 00409 nanoseconds = ACE_High_Res_Timer::elapsed_hrtime (this->end_, this->start_) 00410 * (1024000u / ACE_High_Res_Timer::global_scale_factor ()); 00411 // Caution - Borland has a problem with >>=, so resist the temptation. 00412 nanoseconds = nanoseconds >> 10; 00413 // Right shift is implemented for non native 64-bit ints 00414 // operator/ only for a 32 bit result ! 00415 } |
|
Set tv to the number of microseconds elapsed. Could overflow within hours on windows with emulated 64 bit int's and a fast counter. VC++ and Borland normaly use __int64 and so normaly don't have this problem. Definition at line 360 of file High_Res_Timer.cpp. References elapsed_hrtime(), and hrtime_to_tv(). Referenced by ACE_Profile_Timer::elapsed_time(), print_ave(), and print_total().
00361 { 00362 hrtime_to_tv (tv, 00363 ACE_High_Res_Timer::elapsed_hrtime (this->end_, this->start_)); 00364 } |
|
Set to the number of nanoseconds elapsed between all calls to start_incr and stop_incr. Definition at line 418 of file High_Res_Timer.cpp. References ACE_hrtime_t, global_scale_factor(), and total_.
00419 { 00420 // Same as above. 00421 nanoseconds = this->total_ 00422 * (1024000u / ACE_High_Res_Timer::global_scale_factor ()); 00423 // Caution - Borland has a problem with >>=, so resist the temptation. 00424 nanoseconds = nanoseconds >> 10; 00425 } |
|
Set tv to the number of microseconds elapsed between all calls to start_incr and stop_incr. Definition at line 397 of file High_Res_Timer.cpp. References hrtime_to_tv(), and total_.
00398 { 00399 hrtime_to_tv (tv, total_); 00400 } |
|
Sets the global_scale_factor to the value in the environment variable. Returns 0 on success, -1 on failure.
Definition at line 515 of file High_Res_Timer.cpp. References ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, ACE_OS::atoi(), ACE_OS::getenv(), and global_scale_factor().
00516 { 00517 #if !defined (ACE_HAS_WINCE) 00518 if (env != 0) 00519 { 00520 const char *env_value = ACE_OS::getenv (ACE_TEXT_ALWAYS_CHAR (env)); 00521 if (env_value != 0) 00522 { 00523 int const value = ACE_OS::atoi (env_value); 00524 if (value > 0) 00525 { 00526 ACE_High_Res_Timer::global_scale_factor (value); 00527 return 0; 00528 } 00529 } 00530 } 00531 #else 00532 ACE_UNUSED_ARG (env); 00533 #endif /* !ACE_HAS_WINCE */ 00534 return -1; 00535 } |
|
For internal use: gets the high-resolution time using <ACE_OS::gethrtime>. Except on platforms that require that the be set, such as ACE_WIN32, uses the low-resolution clock if the has not been set. Definition at line 76 of file High_Res_Timer.inl. References ACE_ONE_SECOND_IN_USECS, ACE_OS::gethrtime(), ACE_OS::gettimeofday(), global_scale_factor(), global_scale_factor_status_, ACE_Time_Value::sec(), and ACE_Time_Value::usec(). Referenced by start(), start_incr(), stop(), and stop_incr().
00077 { 00078 #if defined (ACE_WIN32) 00079 // Get the global scale factor if there isn't one yet. 00080 if (ACE_High_Res_Timer::global_scale_factor_status_ == 0) 00081 ACE_High_Res_Timer::global_scale_factor (); 00082 00083 // If there isn't a high-res timer, use gettimeofday (); 00084 if (ACE_High_Res_Timer::global_scale_factor_status_ == -1) 00085 { 00086 ACE_Time_Value tv = ACE_OS::gettimeofday (); 00087 // Return the time in microseconds because the global_scale_factor_ 00088 // is 1. 00089 return tv.sec () * ACE_ONE_SECOND_IN_USECS + tv.usec (); 00090 } 00091 #endif /* ACE_WIN32 */ 00092 00093 return ACE_OS::gethrtime (op); 00094 } |
|
Definition at line 43 of file High_Res_Timer.inl. References ACE_OS::gettimeofday(), global_scale_factor(), global_scale_factor_status_, and hrtime_to_tv(). Referenced by gettimeofday_hr().
00044 { 00045 #if defined (ACE_WIN32) 00046 // Get the global scale factor if there isn't one yet. 00047 if (ACE_High_Res_Timer::global_scale_factor_status_ == 0) 00048 ACE_High_Res_Timer::global_scale_factor (); 00049 00050 // If there isn't a high-res timer, use gettimeofday (); 00051 if (ACE_High_Res_Timer::global_scale_factor_status_ == -1) 00052 return ACE_OS::gettimeofday (); 00053 #endif /* ACE_WIN32 */ 00054 00055 ACE_Time_Value tv; 00056 ACE_High_Res_Timer::hrtime_to_tv (tv, 00057 ACE_OS::gethrtime (op)); 00058 return tv; 00059 } |
|
Get the current "time" as the high resolution counter at this time. This is intended to be useful for supplying to a ACE_Timer_Queue as the gettimeofday function, thereby basing the timer calculations on the high res timer rather than wall clock time. Definition at line 69 of file High_Res_Timer.inl. References gettimeofday().
00070 { 00071 return ACE_High_Res_Timer::gettimeofday (); 00072 } |
|
Returns the global_scale_factor.
Definition at line 193 of file High_Res_Timer.cpp. References ACE_GUARD_RETURN, ACE_HR_SCALE_CONVERSION, ACE_ONE_SECOND_IN_USECS, ACE_UINT64, calibrate(), global_scale_factor(), global_scale_factor_, and global_scale_factor_status_. Referenced by ACE_High_Res_Timer(), calibrate(), elapsed_microseconds(), elapsed_time(), elapsed_time_incr(), get_env_global_scale_factor(), gettime(), gettimeofday(), and hrtime_to_tv().
00194 { 00195 #if (defined (ACE_WIN32) || defined (ACE_HAS_POWERPC_TIMER) || \ 00196 defined (ACE_HAS_PENTIUM) || defined (ACE_HAS_ALPHA_TIMER)) && \ 00197 !defined (ACE_HAS_HI_RES_TIMER) && \ 00198 ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || \ 00199 defined (ghs) || defined (__GNUG__) || \ 00200 defined (__INTEL_COMPILER)) 00201 // Check if the global scale factor needs to be set, and do if so. 00202 if (ACE_High_Res_Timer::global_scale_factor_status_ == 0) 00203 { 00204 // Grab ACE's static object lock. This doesn't have anything to 00205 // do with static objects; it's just a convenient lock to use. 00206 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00207 *ACE_Static_Object_Lock::instance (), 0)); 00208 00209 // Double check 00210 if (ACE_High_Res_Timer::global_scale_factor_status_ == 0) 00211 { 00212 # if defined (ACE_WIN32) 00213 LARGE_INTEGER freq; 00214 if (::QueryPerformanceFrequency (&freq)) 00215 { 00216 // We have a high-res timer 00217 # if defined (ACE_LACKS_LONGLONG_T) 00218 ACE_UINT64 uint64_freq(freq.u.LowPart, (ACE_UINT32) freq.u.HighPart); 00219 ACE_High_Res_Timer::global_scale_factor 00220 (uint64_freq / (ACE_UINT32) ACE_ONE_SECOND_IN_USECS); 00221 # else 00222 ACE_High_Res_Timer::global_scale_factor 00223 (static_cast<unsigned int> (freq.QuadPart / ACE_HR_SCALE_CONVERSION)); 00224 # endif // (ACE_LACKS_LONGLONG_T) 00225 00226 ACE_High_Res_Timer::global_scale_factor_status_ = 1; 00227 } 00228 else 00229 // High-Res timers not supported 00230 ACE_High_Res_Timer::global_scale_factor_status_ = -1; 00231 00232 return ACE_High_Res_Timer::global_scale_factor_; 00233 00234 # elif defined (linux) 00235 ACE_High_Res_Timer::global_scale_factor (ACE_High_Res_Timer::get_cpuinfo ()); 00236 # endif /* ! ACE_WIN32 && ! (linux && __alpha__) */ 00237 00238 # if !defined (ACE_WIN32) 00239 if (ACE_High_Res_Timer::global_scale_factor_ == 1u) 00240 // Failed to retrieve CPU speed from system, so calculate it. 00241 ACE_High_Res_Timer::calibrate (); 00242 # endif // (ACE_WIN32) 00243 } 00244 } 00245 00246 ACE_High_Res_Timer::global_scale_factor_status_ = 1; 00247 #endif /* (ACE_WIN32 || ACE_HAS_POWERPC_TIMER || \ 00248 ACE_HAS_PENTIUM || ACE_HAS_ALPHA_TIMER) && \ 00249 ! ACE_HAS_HI_RES_TIMER && 00250 ((WIN32 && ! WINCE) || ghs || __GNUG__) */ 00251 00252 return ACE_High_Res_Timer::global_scale_factor_; 00253 } |
|
global_scale_factor_ is set to gsf. All High_Res_Timers use global_scale_factor_. This allows applications to set the scale factor just once for all High_Res_Timers. Check High_Res_Timer.cpp for the default global_scale_factors for several platforms. For many platforms (e.g., Solaris), the global_scale_factor_ is set to 1000 so that need not be set. Careful, a of 0 will cause division by zero exceptions. Depending on the platform its units are 1/microsecond or 1/millisecond. Use inside calculations instead a hardcoded value. Definition at line 149 of file High_Res_Timer.inl. References global_scale_factor_. Referenced by dump(), global_scale_factor(), and hrtime_to_tv().
00150 { 00151 global_scale_factor_ = gsf; 00152 } |
|
Converts an to tv using global_scale_factor_.
Definition at line 21 of file High_Res_Timer.inl. References ACE_HR_SCALE_CONVERSION, ACE_hrtime_t, global_scale_factor(), ACE_Time_Value::sec(), and ACE_Time_Value::usec(). Referenced by elapsed_time(), elapsed_time_incr(), and gettimeofday().
00023 { 00024 // The following are based on the units of global_scale_factor_ 00025 // being 1/microsecond. Therefore, dividing by it converts 00026 // clock ticks to microseconds. 00027 tv.sec ((long) (hrt / (ACE_UINT32) ACE_HR_SCALE_CONVERSION / 00028 global_scale_factor ())); 00029 00030 // Calculate usec in a manner that's compatible with ACE_U_LongLong. 00031 // hrt = (tv.sec * ACE_ONE_SECOND_IN_USECS + tv.usec) * global_scale_factor_ 00032 // tv.usec = hrt / global_scale_factor_ - tv.sec * ACE_ONE_SECOND_IN_USECS 00033 // That first term will be lossy, so factor out global_scale_factor_: 00034 // tv.usec = (hrt - tv.sec * ACE_ONE_SECOND_IN_USECS * global_scale_factor_)/ 00035 // global_scale_factor 00036 ACE_hrtime_t tmp = tv.sec (); 00037 tmp *= ((ACE_UINT32) ACE_HR_SCALE_CONVERSION * global_scale_factor ()); 00038 tv.usec ((long) ((hrt - tmp) / global_scale_factor ())); 00039 } |
|
Print average time.
Definition at line 429 of file High_Res_Timer.cpp. References ACE_hrtime_t, ACE_ONE_SECOND_IN_NSECS, ACE_TCHAR, ACE_TEXT, ACE_TRACE, elapsed_time(), ACE_OS::sprintf(), and ACE_OS::write().
00432 { 00433 ACE_TRACE ("ACE_High_Res_Timer::print_ave"); 00434 00435 // Get the total number of nanoseconds elapsed. 00436 ACE_hrtime_t total_nanoseconds; 00437 this->elapsed_time (total_nanoseconds); 00438 00439 // Separate to seconds and nanoseconds. 00440 u_long total_secs = 00441 static_cast<u_long> (total_nanoseconds / (ACE_UINT32) ACE_ONE_SECOND_IN_NSECS); 00442 ACE_UINT32 extra_nsecs = 00443 static_cast<ACE_UINT32> (total_nanoseconds % (ACE_UINT32) ACE_ONE_SECOND_IN_NSECS); 00444 00445 ACE_TCHAR buf[100]; 00446 if (count > 1) 00447 { 00448 ACE_hrtime_t avg_nsecs = total_nanoseconds / (ACE_UINT32) count; 00449 ACE_OS::sprintf (buf, 00450 ACE_TEXT (" count = %d, total (secs %lu, usecs %u), avg usecs = %lu\n"), 00451 count, 00452 total_secs, 00453 (extra_nsecs + 500u) / 1000u, 00454 (u_long) ((avg_nsecs + 500u) / 1000u)); 00455 } 00456 else 00457 ACE_OS::sprintf (buf, 00458 ACE_TEXT (" total %3lu.%06lu secs\n"), 00459 total_secs, 00460 (extra_nsecs + 500lu) / 1000lu); 00461 00462 ACE_OS::write (handle, 00463 str, 00464 ACE_OS::strlen (str)); 00465 ACE_OS::write (handle, 00466 buf, 00467 ACE_OS::strlen (buf)); 00468 } |
|
Print total time.
Definition at line 471 of file High_Res_Timer.cpp. References ACE_hrtime_t, ACE_ONE_SECOND_IN_NSECS, ACE_TCHAR, ACE_TEXT, ACE_TRACE, elapsed_time(), ACE_OS::sprintf(), total_, and ACE_OS::write().
00474 { 00475 ACE_TRACE ("ACE_High_Res_Timer::print_total"); 00476 00477 // Get the total number of nanoseconds elapsed. 00478 ACE_hrtime_t total_nanoseconds; 00479 this->elapsed_time (total_nanoseconds); 00480 00481 // Separate to seconds and nanoseconds. 00482 u_long total_secs = 00483 (u_long) (total_nanoseconds / (ACE_UINT32) ACE_ONE_SECOND_IN_NSECS); 00484 ACE_UINT32 extra_nsecs = 00485 (ACE_UINT32) (total_nanoseconds % (ACE_UINT32) ACE_ONE_SECOND_IN_NSECS); 00486 00487 ACE_TCHAR buf[100]; 00488 if (count > 1) 00489 { 00490 ACE_hrtime_t avg_nsecs = this->total_ / (ACE_UINT32) count; 00491 00492 ACE_OS::sprintf (buf, 00493 ACE_TEXT (" count = %d, total (secs %lu, usecs %u), avg usecs = %lu\n"), 00494 count, 00495 total_secs, 00496 (extra_nsecs + 500u) / 1000u, 00497 (u_long) ((avg_nsecs + 500u) / 1000u)); 00498 } 00499 else 00500 ACE_OS::sprintf (buf, 00501 ACE_TEXT (" total %3lu.%06u secs\n"), 00502 total_secs, 00503 (extra_nsecs + 500u) / 1000u); 00504 00505 ACE_OS::write (handle, 00506 str, 00507 ACE_OS::strlen (str)); 00508 ACE_OS::write (handle, 00509 buf, 00510 ACE_OS::strlen (buf)); 00511 } |
|
Reinitialize the timer.
Definition at line 349 of file High_Res_Timer.cpp. References ACE_TRACE, end_, start_incr_, and total_. Referenced by ACE_High_Res_Timer().
00350 { 00351 ACE_TRACE ("ACE_High_Res_Timer::reset"); 00352 00353 this->start_ = 0; 00354 this->end_ = 0; 00355 this->total_ = 0; 00356 this->start_incr_ = 0; 00357 } |
|
Start timing.
Definition at line 111 of file High_Res_Timer.inl. References ACE_TRACE, and gettime(). Referenced by ACE_Profile_Timer::start().
00112 { 00113 ACE_TRACE ("ACE_High_Res_Timer::start"); 00114 this->start_ = ACE_High_Res_Timer::gettime (op); 00115 } |
|
Start incremental timing.
Definition at line 125 of file High_Res_Timer.inl. References ACE_TRACE, gettime(), and start_incr_.
00126 { 00127 ACE_TRACE ("ACE_High_Res_Timer::start_incr"); 00128 this->start_incr_ = ACE_High_Res_Timer::gettime (op); 00129 } |
|
Stop timing.
Definition at line 118 of file High_Res_Timer.inl. References ACE_TRACE, end_, and gettime(). Referenced by ACE_Profile_Timer::stop().
00119 { 00120 ACE_TRACE ("ACE_High_Res_Timer::stop"); 00121 this->end_ = ACE_High_Res_Timer::gettime (op); 00122 } |
|
Stop incremental timing.
Definition at line 132 of file High_Res_Timer.inl. References ACE_TRACE, elapsed_hrtime(), gettime(), and total_.
00133 { 00134 ACE_TRACE ("ACE_High_Res_Timer::stop_incr"); 00135 this->total_ += 00136 ACE_High_Res_Timer::elapsed_hrtime (ACE_High_Res_Timer::gettime (op), 00137 this->start_incr_); 00138 } |
|
Declare the dynamic allocation hooks.
Definition at line 227 of file High_Res_Timer.h. |
|
Ending time.
Definition at line 287 of file High_Res_Timer.h. |
|
Converts ticks to microseconds. That is, ticks / global_scale_factor_ == microseconds. Definition at line 50 of file High_Res_Timer.cpp. Referenced by global_scale_factor(). |
|
Indicates the status of the global scale factor, 0 = hasn't been set 1 = been set -1 = HR timer not supported Definition at line 75 of file High_Res_Timer.cpp. Referenced by gettime(), gettimeofday(), and global_scale_factor(). |
|
Starting time.
Definition at line 284 of file High_Res_Timer.h. |
|
Start time of incremental timing.
Definition at line 293 of file High_Res_Timer.h. Referenced by dump(), reset(), and start_incr(). |
|
Total elapsed time.
Definition at line 290 of file High_Res_Timer.h. Referenced by dump(), elapsed_time_incr(), print_total(), reset(), and stop_incr(). |