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

ACE_Timeprobe Class Template Reference

This class is used to instrument code. This is accomplished by inserting time probes at different location in the code. ACE_Timeprobe then measures the time difference between two time probes. More...

#include <Timeprobe_T.h>

Collaboration diagram for ACE_Timeprobe:

Collaboration graph
[legend]
List of all members.

Public Types

typedef ACE_Timeprobe< ACE_LOCK > SELF
 Self. More...

typedef ACE_Unbounded_Set<
ACE_Event_Descriptions
EVENT_DESCRIPTIONS
 We can hold multiple event description tables. More...


Public Methods

 ACE_Timeprobe (u_long size=ACE_DEFAULT_TIMEPROBE_TABLE_SIZE)
 Create Timeprobes with <size> slots. More...

 ~ACE_Timeprobe (void)
 Destructor. More...

void timeprobe (u_long event)
 Record a time. <event> is used to describe this time probe. More...

void timeprobe (const char *id)
 Record a time. <id> is used to describe this time probe. More...

int event_descriptions (const char **descriptions, u_long minimum_id)
 Record event descriptions. More...

void print_times (void)
 Print the time probes. More...

void print_absolute_times (void)
 Print the time probes. More...

void reset (void)
 Reset the slots. All old time probes will be lost. More...

 ACE_Timeprobe (const ACE_Timeprobe< ACE_LOCK > &)
 Not implemented (stupid MSVC won't let it be protected). More...

ACE_Unbounded_Set< ACE_Event_Descriptions > & event_descriptions (void)
 Event Descriptions. More...

ACE_Unbounded_Set< ACE_Event_Descriptions > & sorted_event_descriptions (void)
 Sorted Event Descriptions. More...

u_int * current_slot_vme_address (void)
 VME slot address. More...

const char * find_description_i (u_long i)
 Find description of event <i>. More...

void sort_event_descriptions_i (void)
 Sort event descriptions. More...

ACE_timeprobe_ttimeprobes (void)
 Time probe slots. More...

ACE_LOCK & lock (void)
 Synchronization variable. More...

u_long max_size (void)
 Max size of timestamp table. More...

u_long current_size (void)
 Current size of timestamp table. More...


Protected Attributes

EVENT_DESCRIPTIONS event_descriptions_
 Event Descriptions. More...

EVENT_DESCRIPTIONS sorted_event_descriptions_
 Sorted Event Descriptions. More...

u_int * current_slot_vme_address_
 Added sections below here to make compatible with the VMETRO board test. More...

ACE_timeprobe_ttimeprobes_
 Time probe slots. More...

ACE_LOCK lock_
 Synchronization variable. More...

u_long max_size_
 Max size of timestamp table. More...

u_long current_size_
 Current size of timestamp table. More...


Detailed Description

template<class ACE_LOCK>
class ACE_Timeprobe< ACE_LOCK >

This class is used to instrument code. This is accomplished by inserting time probes at different location in the code. ACE_Timeprobe then measures the time difference between two time probes.

This class provides a lightweight implementation for measuring the time required to execute code between two time probes. When a time probe executes, it records the time, the id of the calling thread, and an event description. The event description can either be an unsigned long or a string (char *). If string are used, care must be taken cause only pointer copies are done and the string data is *not* copied. The recorded time probes can then be printed by calling <print_times>. If you have used unsigned longs as event descriptions in any of your time probes, you must have provided an event description table that maps the unsigned longs to readable strings. This map is a simple array of strings, and the event number is used as the index into the array when looking for the event description. If you have only used strings for the event description, this map is not necessary. Multiple maps can also be used to chunk up the time probes. Each one can be added by calling <event_descriptions>. Different tables are used internally by consulting the minimum_id for each table. It is up to the user to make sure that multiple tables do not share the same event id range.

Definition at line 59 of file Timeprobe_T.h.


Member Typedef Documentation

template<class ACE_LOCK>
typedef ACE_Unbounded_Set<ACE_Event_Descriptions> ACE_Timeprobe::EVENT_DESCRIPTIONS
 

We can hold multiple event description tables.

Definition at line 69 of file Timeprobe_T.h.

template<class ACE_LOCK>
typedef ACE_Timeprobe<ACE_LOCK> ACE_Timeprobe::SELF
 

Self.

Definition at line 65 of file Timeprobe_T.h.


Constructor & Destructor Documentation

template<class ACE_LOCK>
ACE_Timeprobe< ACE_LOCK >::ACE_Timeprobe u_long    size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE
 

Create Timeprobes with <size> slots.

Definition at line 20 of file Timeprobe_T.cpp.

References ACE_NEW, and current_slot_vme_address_.

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 }

template<class ACE_LOCK>
ACE_Timeprobe< ACE_LOCK >::~ACE_Timeprobe void   
 

Destructor.

Definition at line 50 of file Timeprobe_T.cpp.

References timeprobes_.

00051 {
00052   delete [] this->timeprobes_;
00053 }

template<class ACE_LOCK>
ACE_Timeprobe< ACE_LOCK >::ACE_Timeprobe const ACE_Timeprobe< ACE_LOCK > &   
 

Not implemented (stupid MSVC won't let it be protected).

Definition at line 38 of file Timeprobe_T.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ENOTSUP, and LM_ERROR.

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 }


Member Function Documentation

template<class ACE_LOCK>
u_long ACE_Timeprobe< ACE_LOCK >::current_size void   
 

Current size of timestamp table.

Definition at line 136 of file Timeprobe_T.cpp.

References current_size_.

00137 {
00138   return this->current_size_;
00139 }

template<class ACE_LOCK>
u_int * ACE_Timeprobe< ACE_LOCK >::current_slot_vme_address void   
 

VME slot address.

Definition at line 112 of file Timeprobe_T.cpp.

References current_slot_vme_address_.

00113 {
00114   return this->current_slot_vme_address_;
00115 }

template<class ACE_LOCK>
ACE_Unbounded_Set< ACE_Event_Descriptions > & ACE_Timeprobe< ACE_LOCK >::event_descriptions void   
 

Event Descriptions.

Definition at line 100 of file Timeprobe_T.cpp.

References event_descriptions_.

00101 {
00102   return this->event_descriptions_;
00103 }

template<class ACE_LOCK>
int ACE_Timeprobe< ACE_LOCK >::event_descriptions const char **    descriptions,
u_long    minimum_id
 

Record event descriptions.

Definition at line 142 of file Timeprobe_T.cpp.

References ACE_GUARD_RETURN, ACE_Event_Descriptions::descriptions_, event_descriptions_, ACE_Unbounded_Set< ACE_Event_Descriptions >::insert, and ACE_Event_Descriptions::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 }

template<class ACE_LOCK>
const char * ACE_Timeprobe< ACE_LOCK >::find_description_i u_long    i
 

Find description of event <i>.

Definition at line 240 of file Timeprobe_T.cpp.

References ACE_Unbounded_Set< ACE_Event_Descriptions >::begin, ACE_timeprobe_t::event_, ACE_timeprobe_t::event_type_, ACE_Unbounded_Set< ACE_Event_Descriptions >::size, sorted_event_descriptions_, ACE_timeprobe_t::STRING, and timeprobes_.

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 }

template<class ACE_LOCK>
ACE_LOCK & ACE_Timeprobe< ACE_LOCK >::lock void   
 

Synchronization variable.

Definition at line 124 of file Timeprobe_T.cpp.

References lock_.

00125 {
00126   return this->lock_;
00127 }

template<class ACE_LOCK>
u_long ACE_Timeprobe< ACE_LOCK >::max_size void   
 

Max size of timestamp table.

Definition at line 130 of file Timeprobe_T.cpp.

References max_size_.

00131 {
00132   return this->max_size_;
00133 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::print_absolute_times void   
 

Print the time probes.

Definition at line 207 of file Timeprobe_T.cpp.

References ACE_DEBUG, ACE_GUARD, current_size_, LM_DEBUG, sort_event_descriptions_i, ACE_OS::sprintf, ACE_timeprobe_t::thread_, and timeprobes_.

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 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::print_times void   
 

Print the time probes.

Definition at line 157 of file Timeprobe_T.cpp.

References ACE_DEBUG, ACE_GUARD, ACE_hrtime_t, current_size_, ACE_High_Res_Timer::global_scale_factor, LM_DEBUG, sort_event_descriptions_i, ACE_timeprobe_t::thread_, ACE_timeprobe_t::time_, and timeprobes_.

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 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::reset void   
 

Reset the slots. All old time probes will be lost.

Definition at line 92 of file Timeprobe_T.cpp.

References ACE_GUARD, and current_size_.

00093 {
00094   ACE_GUARD (ACE_LOCK, ace_mon, this->lock_);
00095 
00096   this->current_size_ = 0;
00097 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::sort_event_descriptions_i void   
 

Sort event descriptions.

Definition at line 262 of file Timeprobe_T.cpp.

References ACE_Unbounded_Set< ACE_Event_Descriptions >::begin, ACE_Unbounded_Set< ACE_Event_Descriptions >::end, event_descriptions_, ACE_Unbounded_Set< ACE_Event_Descriptions >::insert, ACE_Event_Descriptions::minimum_id_, ACE_Unbounded_Set< ACE_Event_Descriptions >::remove, ACE_Unbounded_Set< ACE_Event_Descriptions >::size, and sorted_event_descriptions_.

Referenced by print_absolute_times, and print_times.

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 }

template<class ACE_LOCK>
ACE_Unbounded_Set< ACE_Event_Descriptions > & ACE_Timeprobe< ACE_LOCK >::sorted_event_descriptions void   
 

Sorted Event Descriptions.

Definition at line 106 of file Timeprobe_T.cpp.

References sorted_event_descriptions_.

00107 {
00108   return this->sorted_event_descriptions_;
00109 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::timeprobe const char *    id
 

Record a time. <id> is used to describe this time probe.

Definition at line 77 of file Timeprobe_T.cpp.

References ACE_ASSERT, ACE_GUARD, current_size_, ACE_OS::gethrtime, ACE_timeprobe_t::STRING, ACE_OS::thr_self, and timeprobes_.

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 }

template<class ACE_LOCK>
void ACE_Timeprobe< ACE_LOCK >::timeprobe u_long    event
 

Record a time. <event> is used to describe this time probe.

Definition at line 56 of file Timeprobe_T.cpp.

References ACE_ASSERT, ACE_GUARD, current_size_, current_slot_vme_address_, ACE_OS::gethrtime, ACE_timeprobe_t::NUMBER, ACE_OS::thr_self, and timeprobes_.

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 }

template<class ACE_LOCK>
ACE_timeprobe_t * ACE_Timeprobe< ACE_LOCK >::timeprobes void   
 

Time probe slots.

Definition at line 118 of file Timeprobe_T.cpp.

References timeprobes_.

00119 {
00120   return this->timeprobes_;
00121 }


Member Data Documentation

template<class ACE_LOCK>
u_long ACE_Timeprobe::current_size_ [protected]
 

Current size of timestamp table.

Definition at line 150 of file Timeprobe_T.h.

Referenced by current_size, print_absolute_times, print_times, reset, and timeprobe.

template<class ACE_LOCK>
u_int* ACE_Timeprobe::current_slot_vme_address_ [protected]
 

Added sections below here to make compatible with the VMETRO board test.

Definition at line 138 of file Timeprobe_T.h.

Referenced by ACE_Timeprobe, current_slot_vme_address, and timeprobe.

template<class ACE_LOCK>
EVENT_DESCRIPTIONS ACE_Timeprobe::event_descriptions_ [protected]
 

Event Descriptions.

Definition at line 131 of file Timeprobe_T.h.

Referenced by event_descriptions, and sort_event_descriptions_i.

template<class ACE_LOCK>
ACE_LOCK ACE_Timeprobe::lock_ [protected]
 

Synchronization variable.

Definition at line 144 of file Timeprobe_T.h.

Referenced by lock.

template<class ACE_LOCK>
u_long ACE_Timeprobe::max_size_ [protected]
 

Max size of timestamp table.

Definition at line 147 of file Timeprobe_T.h.

Referenced by max_size.

template<class ACE_LOCK>
EVENT_DESCRIPTIONS ACE_Timeprobe::sorted_event_descriptions_ [protected]
 

Sorted Event Descriptions.

Definition at line 134 of file Timeprobe_T.h.

Referenced by find_description_i, sort_event_descriptions_i, and sorted_event_descriptions.

template<class ACE_LOCK>
ACE_timeprobe_t* ACE_Timeprobe::timeprobes_ [protected]
 

Time probe slots.

Definition at line 141 of file Timeprobe_T.h.

Referenced by find_description_i, print_absolute_times, print_times, timeprobe, timeprobes, and ~ACE_Timeprobe.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:57:52 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002