diff options
author | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-05-25 18:18:05 +0000 |
---|---|---|
committer | irfan <irfan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-05-25 18:18:05 +0000 |
commit | a6d71a3d9cc64176ae6199c70fe1e991e274a643 (patch) | |
tree | a16d658010f0d97db04e87ad6f6d171fe7231355 /ace/Timeprobe.cpp | |
parent | f948b190934fb38d8fee99b392d6c90fa66a97c2 (diff) | |
download | ATCD-a6d71a3d9cc64176ae6199c70fe1e991e274a643.tar.gz |
*** empty log message ***
Diffstat (limited to 'ace/Timeprobe.cpp')
-rw-r--r-- | ace/Timeprobe.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/ace/Timeprobe.cpp b/ace/Timeprobe.cpp new file mode 100644 index 00000000000..6f6d451b9bc --- /dev/null +++ b/ace/Timeprobe.cpp @@ -0,0 +1,142 @@ +// $Id$ + +#if !defined (ACE_TIMEPROBE_C) +#define ACE_TIMEPROBE_C + +#include "ace/Timeprobe.h" + +#if defined (ACE_ENABLE_TIMEPROBES) + +#if !defined (__ACE_INLINE__) +#include "ace/Timeprobe.i" +#endif /* __ACE_INLINE__ */ + +#include "ace/High_Res_Timer.h" + +template <class ACE_LOCK> +ACE_Timeprobe<ACE_LOCK>::ACE_Timeprobe (u_long size, + ACE_Allocator *alloc) + : allocator_ (alloc != 0 ? alloc : ACE_Allocator::instance ()), + timeprobes_ (0), + lock_ (), + max_size_ (size), + current_size_ (0) +{ + void *space = this->allocator_->malloc ((sizeof timeprobe_t) * this->max_size_); + this->timeprobes_ = new ((timeprobe_t *) space) timeprobe_t[this->max_size_]; +} + +template <class ACE_LOCK> +ACE_Timeprobe<ACE_LOCK>::~ACE_Timeprobe (void) +{ + for (int i = 0; i < this->max_size_; i++) + this->timeprobes_[i].timeprobe_t::~timeprobe_t (); + + this->allocator_->free (this->timeprobes_); +} + +template <class ACE_LOCK> void +ACE_Timeprobe<ACE_LOCK>::timeprobe (u_long event) +{ + ACE_GUARD (ACE_LOCK, ace_mon, this->lock_); + + ACE_ASSERT (this->current_size_ < this->max_size_); + + this->timeprobes_[this->current_size_].event_.event_number_ = event; + this->timeprobes_[this->current_size_].event_type_ = timeprobe_t::NUMBER; + this->timeprobes_[this->current_size_].time_ = ACE_OS::gethrtime (); + this->timeprobes_[this->current_size_].thread_ = ACE_OS::thr_self (); + + this->current_size_++; +} + +template <class ACE_LOCK> void +ACE_Timeprobe<ACE_LOCK>::timeprobe (const char *event) +{ + ACE_GUARD (ACE_LOCK, ace_mon, this->lock_); + + ACE_ASSERT (this->current_size_ < this->max_size_); + + this->timeprobes_[this->current_size_].event_.event_description_ = event; + this->timeprobes_[this->current_size_].event_type_ = timeprobe_t::STRING; + this->timeprobes_[this->current_size_].time_ = ACE_OS::gethrtime (); + this->timeprobes_[this->current_size_].thread_ = ACE_OS::thr_self (); + + this->current_size_++; +} + +template <class ACE_LOCK> void +ACE_Timeprobe<ACE_LOCK>::reset (void) +{ + ACE_GUARD (ACE_LOCK, ace_mon, this->lock_); + + this->current_size_ = 0; +} + +template <class ACE_LOCK> void +ACE_Timeprobe<ACE_LOCK>::print_times (const char *event_descriptions[]) const +{ + ACE_DEBUG ((LM_DEBUG, + "\nACE_Timeprobe; %d timestamps were recorded:\n", + this->current_size_)); + + if (this->current_size_ == 0) + return; + + ACE_DEBUG ((LM_DEBUG, + "\n%-50.50s %8.8s %13.13s\n\n", + "Event", + "thread", + "usec")); + + const char *description = 0; + if (this->timeprobes_[0].event_type_ == timeprobe_t::STRING) + description = this->timeprobes_[0].event_.event_description_; + else + description = event_descriptions[this->timeprobes_[0].event_.event_number_]; + + ACE_DEBUG ((LM_DEBUG, + "%-50.50s %8.8x %13.13s\n", + description, + this->timeprobes_[0].thread_, + "START")); + + for (u_int i = 1; i < this->current_size_; i++) + { + ACE_hrtime_t time_difference = + this->timeprobes_[i].time_ - this->timeprobes_[i-1].time_; + + float elapsed_time_in_micro_seconds = + (float) time_difference / ACE_High_Res_Timer::global_scale_factor (); + + if (this->timeprobes_[i].event_type_ == timeprobe_t::STRING) + description = this->timeprobes_[i].event_.event_description_; + else + description = event_descriptions[this->timeprobes_[i].event_.event_number_]; + + ACE_DEBUG ((LM_DEBUG, + "%-50.50s %8.8x %13.3f\n", + description, + this->timeprobes_[i].thread_, + elapsed_time_in_micro_seconds)); + } +} + +template <class Timeprobe> +ACE_Function_Timeprobe<Timeprobe>::ACE_Function_Timeprobe (Timeprobe &timeprobe, + u_long event) + : timeprobe_ (timeprobe), + event_ (event) +{ + this->timeprobe_.timeprobe (this->event_); +} + +template <class Timeprobe> +ACE_Function_Timeprobe<Timeprobe>::~ACE_Function_Timeprobe (void) +{ + this->timeprobe_.timeprobe (this->event_ + 1); +} + +#endif /* ACE_ENABLE_TIMEPROBES */ + +#endif /* ACE_TIMEPROBE_C */ |