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

Timeprobe_T.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Timeprobe_T.h
00006  *
00007  *  $Id: Timeprobe_T.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Irfan Pyarali
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef ACE_TIMEPROBE_T_H
00015 #define ACE_TIMEPROBE_T_H
00016 #include "ace/pre.h"
00017 
00018 #include "ace/OS.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if defined (ACE_COMPILE_TIMEPROBES)
00025 
00026 #include "ace/Unbounded_Set.h"
00027 
00028 /**
00029  * @class ACE_Timeprobe
00030  *
00031  * @brief This class is used to instrument code.  This is accomplished
00032  * by inserting time probes at different location in the code.
00033  * ACE_Timeprobe then measures the time difference between two
00034  * time probes.
00035  *
00036  * This class provides a lightweight implementation for
00037  * measuring the time required to execute code between two time
00038  * probes.  When a time probe executes, it records the time, the
00039  * id of the calling thread, and an event description.  The
00040  * event description can either be an unsigned long or a string
00041  * (char *). If string are used, care must be taken cause only
00042  * pointer copies are done and the string data is *not* copied.
00043  * The recorded time probes can then be printed by calling
00044  * <print_times>.  If you have used unsigned longs as event
00045  * descriptions in any of your time probes, you must have
00046  * provided an event description table that maps the unsigned
00047  * longs to readable strings.  This map is a simple array of
00048  * strings, and the event number is used as the index into the
00049  * array when looking for the event description.  If you have
00050  * only used strings for the event description, this map is not
00051  * necessary.
00052  * Multiple maps can also be used to chunk up the time probes.
00053  * Each one can be added by calling <event_descriptions>.
00054  * Different tables are used internally by consulting the
00055  * minimum_id for each table.  It is up to the user to make sure
00056  * that multiple tables do not share the same event id range.
00057  */
00058 template <class ACE_LOCK>
00059 class ACE_Timeprobe
00060 {
00061 public:
00062 
00063   /// Self
00064   typedef ACE_Timeprobe<ACE_LOCK>
00065           SELF;
00066 
00067   /// We can hold multiple event description tables.
00068   typedef ACE_Unbounded_Set<ACE_Event_Descriptions>
00069           EVENT_DESCRIPTIONS;
00070 
00071   /// Create Timeprobes with <size> slots
00072   ACE_Timeprobe (u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
00073 
00074   /// Destructor.
00075   ~ACE_Timeprobe (void);
00076 
00077   /// Record a time. <event> is used to describe this time probe.
00078   void timeprobe (u_long event);
00079 
00080   /// Record a time. <id> is used to describe this time probe.
00081   void timeprobe (const char *id);
00082 
00083   /// Record event descriptions.
00084   int event_descriptions (const char **descriptions,
00085                           u_long minimum_id);
00086 
00087   /// Print the time probes.
00088   void print_times (void);
00089 
00090   /// Print the time probes.
00091   void print_absolute_times (void);
00092 
00093   /// Reset the slots.  All old time probes will be lost.
00094   void reset (void);
00095 
00096   /// Not implemented (stupid MSVC won't let it be protected).
00097   ACE_Timeprobe (const ACE_Timeprobe<ACE_LOCK> &);
00098 
00099   // = (Somewhat private) Accessors
00100 
00101   /// Event Descriptions
00102   ACE_Unbounded_Set<ACE_Event_Descriptions> &event_descriptions (void);
00103 
00104   /// Sorted Event Descriptions.
00105   ACE_Unbounded_Set<ACE_Event_Descriptions> &sorted_event_descriptions (void);
00106 
00107   /// VME slot address.
00108   u_int *current_slot_vme_address (void);
00109 
00110   /// Find description of event <i>
00111   const char *find_description_i (u_long i);
00112 
00113   /// Sort event descriptions
00114   void sort_event_descriptions_i (void);
00115 
00116   /// Time probe slots
00117   ACE_timeprobe_t *timeprobes (void);
00118 
00119   /// Synchronization variable.
00120   ACE_LOCK &lock (void);
00121 
00122   /// Max size of timestamp table
00123   u_long max_size (void);
00124 
00125   /// Current size of timestamp table
00126   u_long current_size (void);
00127 
00128 protected:
00129 
00130   /// Event Descriptions
00131   EVENT_DESCRIPTIONS event_descriptions_;
00132 
00133   /// Sorted Event Descriptions.
00134   EVENT_DESCRIPTIONS sorted_event_descriptions_;
00135 
00136   /// Added sections below here to make compatible with the VMETRO
00137   /// board test.
00138   u_int *current_slot_vme_address_;
00139 
00140   /// Time probe slots
00141   ACE_timeprobe_t *timeprobes_;
00142 
00143   /// Synchronization variable.
00144   ACE_LOCK lock_;
00145 
00146   /// Max size of timestamp table
00147   u_long max_size_;
00148 
00149   /// Current size of timestamp table
00150   u_long current_size_;
00151 };
00152 
00153 /**
00154  * @class ACE_Function_Timeprobe
00155  *
00156  * @brief Auto pointer like time probes. It will record <event> on
00157  * construction and <event + 1> on destruction.
00158  */
00159 template <class Timeprobe>
00160 class ACE_Function_Timeprobe
00161 {
00162 public:
00163   /// Constructor.
00164   ACE_Function_Timeprobe (Timeprobe &timeprobe,
00165                           u_long event);
00166 
00167   /// Destructor.
00168   ~ACE_Function_Timeprobe (void);
00169 
00170 protected:
00171   /// Reference to timeprobe.
00172   Timeprobe &timeprobe_;
00173 
00174   /// Event.
00175   u_long event_;
00176 };
00177 
00178 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00179 #include "ace/Timeprobe_T.cpp"
00180 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00181 
00182 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00183 #pragma implementation ("Timeprobe_T.cpp")
00184 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00185 
00186 #endif /* ACE_COMPILE_TIMEPROBES */
00187 #include "ace/post.h"
00188 #endif /* ACE_TIMEPROBE_T_H */

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