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

Timeprobe_T.cpp

Go to the documentation of this file.
00001 // $Id: Timeprobe_T.cpp,v 1.1.1.3 2001/12/04 14:33:10 chad Exp $
00002 
00003 #ifndef ACE_TIMEPROBE_T_C
00004 #define ACE_TIMEPROBE_T_C
00005 
00006 #include "ace/OS.h"
00007 
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif /* ACE_LACKS_PRAGMA_ONCE */
00011 
00012 ACE_RCSID(ace, Timeprobe_T, "$Id: Timeprobe_T.cpp,v 1.1.1.3 2001/12/04 14:33:10 chad Exp $")
00013 
00014 #if defined (ACE_COMPILE_TIMEPROBES)
00015 
00016 #include "ace/Timeprobe.h"
00017 #include "ace/High_Res_Timer.h"
00018 
00019 template <class ACE_LOCK>
00020 ACE_Timeprobe<ACE_LOCK>::ACE_Timeprobe (u_long size)
00021   : timeprobes_ (0),
00022     lock_ (),
00023     max_size_ (size),
00024     current_size_ (0)
00025 {
00026   ACE_NEW (this->timeprobes_,
00027            ACE_timeprobe_t[this->max_size_]);
00028 
00029 #if defined (VXWORKS)
00030   if (sysProcNumGet () == 0)
00031     this->current_slot_vme_address_ = (u_int *) 0xDa010000;
00032   else
00033     this->current_slot_vme_address_ = (u_int *) 0xD8010000;
00034 #endif /* VXWORKS */
00035 }
00036 
00037 template <class ACE_LOCK>
00038 ACE_Timeprobe<ACE_LOCK>::ACE_Timeprobe (const ACE_Timeprobe<ACE_LOCK> &)
00039 {
00040   //
00041   // Stupid MSVC is forcing me to define this; please don't use it.
00042   //
00043 
00044   ACE_ERROR ((LM_ERROR,
00045               ACE_LIB_TEXT ("ACE_NOTSUP: %s, line %d\n"), __FILE__, __LINE__));
00046   errno = ENOTSUP;
00047 }
00048 
00049 template <class ACE_LOCK>
00050 ACE_Timeprobe<ACE_LOCK>::~ACE_Timeprobe (void)
00051 {
00052   delete [] this->timeprobes_;
00053 }
00054 
00055 template <class ACE_LOCK> void
00056 ACE_Timeprobe<ACE_LOCK>::timeprobe (u_long event)
00057 {
00058   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00059 
00060   ACE_ASSERT (this->current_size_ < this->max_size_);
00061 
00062   this->timeprobes_[this->current_size_].event_.event_number_ = event;
00063   this->timeprobes_[this->current_size_].event_type_ = ACE_timeprobe_t::NUMBER;
00064   this->timeprobes_[this->current_size_].time_ = ACE_OS::gethrtime ();
00065   this->timeprobes_[this->current_size_].thread_ = ACE_OS::thr_self ();
00066 
00067   this->current_size_++;
00068 
00069 #if defined (VMETRO_TIME_TEST) && (VXWORKS)
00070   // If we are using the VMETRO board to get time samples, then write
00071   // to the other boards VME address.
00072   *this->current_slot_vme_address_ = event;
00073 #endif /* VMETRO_TIME_TEST && VXWORKS */
00074 }
00075 
00076 template <class ACE_LOCK> void
00077 ACE_Timeprobe<ACE_LOCK>::timeprobe (const char *event)
00078 {
00079   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00080 
00081   ACE_ASSERT (this->current_size_ < this->max_size_);
00082 
00083   this->timeprobes_[this->current_size_].event_.event_description_ = event;
00084   this->timeprobes_[this->current_size_].event_type_ = ACE_timeprobe_t::STRING;
00085   this->timeprobes_[this->current_size_].time_ = ACE_OS::gethrtime ();
00086   this->timeprobes_[this->current_size_].thread_ = ACE_OS::thr_self ();
00087 
00088   this->current_size_++;
00089 }
00090 
00091 template <class ACE_LOCK> void
00092 ACE_Timeprobe<ACE_LOCK>::reset (void)
00093 {
00094   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00095 
00096   this->current_size_ = 0;
00097 }
00098 
00099 template <class ACE_LOCK> ACE_Unbounded_Set<ACE_Event_Descriptions> &
00100 ACE_Timeprobe<ACE_LOCK>::event_descriptions (void)
00101 {
00102   return this->event_descriptions_;
00103 }
00104 
00105 template <class ACE_LOCK> ACE_Unbounded_Set<ACE_Event_Descriptions> &
00106 ACE_Timeprobe<ACE_LOCK>::sorted_event_descriptions (void)
00107 {
00108   return this->sorted_event_descriptions_;
00109 }
00110 
00111 template <class ACE_LOCK> u_int *
00112 ACE_Timeprobe<ACE_LOCK>::current_slot_vme_address (void)
00113 {
00114   return this->current_slot_vme_address_;
00115 }
00116 
00117 template <class ACE_LOCK> ACE_timeprobe_t *
00118 ACE_Timeprobe<ACE_LOCK>::timeprobes (void)
00119 {
00120   return this->timeprobes_;
00121 }
00122 
00123 template <class ACE_LOCK> ACE_LOCK &
00124 ACE_Timeprobe<ACE_LOCK>::lock (void)
00125 {
00126   return this->lock_;
00127 }
00128 
00129 template <class ACE_LOCK> u_long
00130 ACE_Timeprobe<ACE_LOCK>::max_size (void)
00131 {
00132   return this->max_size_;
00133 }
00134 
00135 template <class ACE_LOCK> u_long
00136 ACE_Timeprobe<ACE_LOCK>::current_size (void)
00137 {
00138   return this->current_size_;
00139 }
00140 
00141 template <class ACE_LOCK> int
00142 ACE_Timeprobe<ACE_LOCK>::event_descriptions (const char **descriptions,
00143                                              u_long minimum_id)
00144 {
00145   ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
00146 
00147   ACE_Event_Descriptions events;
00148   events.descriptions_ = descriptions;
00149   events.minimum_id_ = minimum_id;
00150 
00151   this->event_descriptions_.insert (events);
00152 
00153   return 0;
00154 }
00155 
00156 template <class ACE_LOCK> void
00157 ACE_Timeprobe<ACE_LOCK>::print_times (void)
00158 {
00159   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00160 
00161   // Sort the event descriptions
00162   this->sort_event_descriptions_i ();
00163 
00164   ACE_DEBUG ((LM_DEBUG,
00165               "\nACE_Timeprobe; %d timestamps were recorded:\n",
00166               this->current_size_));
00167 
00168   if (this->current_size_ == 0)
00169     return;
00170 
00171   ACE_DEBUG ((LM_DEBUG,
00172               "\n%-50.50s %8.8s %13.13s\n\n",
00173               "Event",
00174               "thread",
00175               "usec"));
00176 
00177   ACE_DEBUG ((LM_DEBUG,
00178               "%-50.50s %8.8x %13.13s\n",
00179               this->find_description_i (0),
00180               this->timeprobes_[0].thread_,
00181               "START"));
00182 
00183   ACE_UINT32 gsf = ACE_High_Res_Timer::global_scale_factor ();
00184   for (u_long i = 1; i < this->current_size_; i++)
00185     {
00186       ACE_hrtime_t time_difference =
00187         this->timeprobes_[i].time_ - this->timeprobes_[i-1].time_;
00188 
00189       ACE_UINT32 elapsed_time_in_micro_seconds =
00190         (ACE_UINT32) (time_difference / gsf);
00191       ACE_UINT32 remainder =
00192         (ACE_UINT32) (time_difference % gsf);
00193       // Convert to the fractional part in microseconds, with 3 digits
00194       // of precision (hence the 1000).
00195       ACE_UINT32 fractional = remainder * 1000 / gsf;
00196 
00197       ACE_DEBUG ((LM_DEBUG,
00198                   "%-50.50s %8.8x %10u.%03.3u\n",
00199                   this->find_description_i (i),
00200                   this->timeprobes_[i].thread_,
00201                   (unsigned int) elapsed_time_in_micro_seconds,
00202                   (unsigned int) fractional));
00203     }
00204 }
00205 
00206 template <class ACE_LOCK> void
00207 ACE_Timeprobe<ACE_LOCK>::print_absolute_times (void)
00208 {
00209   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00210 
00211   // Sort the event descriptions
00212   this->sort_event_descriptions_i ();
00213 
00214   ACE_DEBUG ((LM_DEBUG,
00215               "\nACE_Timeprobe; %d timestamps were recorded:\n",
00216               this->current_size_));
00217 
00218   if (this->current_size_ == 0)
00219     return;
00220 
00221   ACE_DEBUG ((LM_DEBUG,
00222               "\n%-50.50s %8.8s %13.13s\n\n",
00223               "Event",
00224               "thread",
00225               "stamp"));
00226 
00227   for (u_long i = 0; i < this->current_size_; i++)
00228     {
00229       char buf[64];
00230       ACE_OS::sprintf (buf, "%llu", this->timeprobes_[i].time_);
00231       ACE_DEBUG ((LM_DEBUG,
00232                   "%-50.50s %8.8x %13.13s\n",
00233                   this->find_description_i (i),
00234                   this->timeprobes_[i].thread_,
00235                   buf));
00236     }
00237 }
00238 
00239 template <class ACE_LOCK> const char *
00240 ACE_Timeprobe<ACE_LOCK>::find_description_i (u_long i)
00241 {
00242   if (this->timeprobes_[i].event_type_ == ACE_timeprobe_t::STRING)
00243     return this->timeprobes_[i].event_.event_description_;
00244   else
00245     {
00246       EVENT_DESCRIPTIONS::iterator iterator = this->sorted_event_descriptions_.begin ();
00247       for (u_long j = 0;
00248            j < this->sorted_event_descriptions_.size () - 1;
00249            iterator++, j++)
00250         {
00251           EVENT_DESCRIPTIONS::iterator next_event_descriptions = iterator;
00252           next_event_descriptions++;
00253 
00254           if (this->timeprobes_[i].event_.event_number_ < (*next_event_descriptions).minimum_id_)
00255             break;
00256         }
00257       return (*iterator).descriptions_[this->timeprobes_[i].event_.event_number_ - (*iterator).minimum_id_];
00258     }
00259 }
00260 
00261 template <class ACE_LOCK> void
00262 ACE_Timeprobe<ACE_LOCK>::sort_event_descriptions_i (void)
00263 {
00264   size_t total_elements = this->event_descriptions_.size ();
00265 
00266   for (size_t i = 0;
00267        i < total_elements;
00268        i++)
00269     {
00270       EVENT_DESCRIPTIONS::iterator iterator = this->event_descriptions_.begin ();
00271       ACE_Event_Descriptions min_entry = *iterator;
00272 
00273       for (;
00274            iterator != this->event_descriptions_.end ();
00275            iterator++)
00276         if ((*iterator).minimum_id_ < min_entry.minimum_id_)
00277           min_entry = *iterator;
00278 
00279       this->sorted_event_descriptions_.insert (min_entry);
00280       this->event_descriptions_.remove (min_entry);
00281     }
00282 }
00283 
00284 template <class Timeprobe>
00285 ACE_Function_Timeprobe<Timeprobe>::ACE_Function_Timeprobe (Timeprobe &timeprobe,
00286                                                            u_long event)
00287   : timeprobe_ (timeprobe),
00288     event_ (event)
00289 {
00290   this->timeprobe_.timeprobe (this->event_);
00291 }
00292 
00293 template <class Timeprobe>
00294 ACE_Function_Timeprobe<Timeprobe>::~ACE_Function_Timeprobe (void)
00295 {
00296   this->timeprobe_.timeprobe (this->event_ + 1);
00297 }
00298 
00299 #endif /* ACE_COMPILE_TIMEPROBES */
00300 #endif /* ACE_TIMEPROBE_T_C */

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