3 //=============================================================================
7 * @author Irfan Pyarali
9 //=============================================================================
12 #ifndef ACE_TIMEPROBE_T_H
13 #define ACE_TIMEPROBE_T_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/config-all.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #if defined (ACE_COMPILE_TIMEPROBES)
24 #include "ace/Unbounded_Set.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 * @class ACE_Timeprobe_Ex
31 * @brief This class is used to instrument code. This is accomplished
32 * by inserting time probes at different location in the code.
33 * ACE_Timeprobe then measures the time difference between two
36 * This class provides a lightweight implementation for
37 * measuring the time required to execute code between two time
38 * probes. When a time probe executes, it records the time, the
39 * id of the calling thread, and an event description. The
40 * event description can either be an unsigned long or a string
41 * (char *). If string are used, care must be taken cause only
42 * pointer copies are done and the string data is *not* copied.
43 * The recorded time probes can then be printed by calling
44 * <print_times>. If you have used unsigned longs as event
45 * descriptions in any of your time probes, you must have
46 * provided an event description table that maps the unsigned
47 * longs to readable strings. This map is a simple array of
48 * strings, and the event number is used as the index into the
49 * array when looking for the event description. If you have
50 * only used strings for the event description, this map is not
52 * Multiple maps can also be used to chunk up the time probes.
53 * Each one can be added by calling <event_descriptions>.
54 * Different tables are used internally by consulting the
55 * minimum_id for each table. It is up to the user to make sure
56 * that multiple tables do not share the same event id range.
58 template <class ACE_LOCK
, class ALLOCATOR
>
59 class ACE_Timeprobe_Ex
63 typedef ACE_Timeprobe_Ex
<ACE_LOCK
, ALLOCATOR
>
69 typedef ACE_Timeprobe_Ex
<ACE_LOCK
, ACE_Allocator
> ACE_Timeprobe
;
72 /// We can hold multiple event description tables.
73 typedef ACE_Unbounded_Set
<ACE_Event_Descriptions
>
76 /// Create Timeprobes with @a size slots
77 ACE_Timeprobe_Ex (u_long size
= ACE_DEFAULT_TIMEPROBE_TABLE_SIZE
);
79 /// Create Timeprobes with @a size slots
80 ACE_Timeprobe_Ex (ALLOCATOR
*allocator
,
81 u_long size
= ACE_DEFAULT_TIMEPROBE_TABLE_SIZE
);
85 /// Record a time. @a event is used to describe this time probe.
86 void timeprobe (u_long event
);
88 /// Record a time. @a id is used to describe this time probe.
89 void timeprobe (const char *id
);
91 /// Record event descriptions.
92 int event_descriptions (const char **descriptions
,
95 /// Print the time probes.
98 /// Print the time probes.
99 void print_absolute_times ();
101 /// Reset the slots. All old time probes will be lost.
104 void increase_size (u_long size
);
106 /// Not implemented (stupid MSVC won't let it be protected).
107 ACE_Timeprobe_Ex (const ACE_Timeprobe_Ex
<ACE_LOCK
, ALLOCATOR
> &);
109 // = (Somewhat private) Accessors
111 /// Event Descriptions
112 ACE_Unbounded_Set
<ACE_Event_Descriptions
> &event_descriptions ();
114 /// Sorted Event Descriptions.
115 ACE_Unbounded_Set
<ACE_Event_Descriptions
> &sorted_event_descriptions ();
117 /// Find description of event @a i
118 const char *find_description_i (u_long i
);
120 /// Sort event descriptions
121 void sort_event_descriptions_i ();
124 ACE_timeprobe_t
*timeprobes ();
126 /// Synchronization variable.
129 /// Max size of timestamp table
132 /// Current size of timestamp table
133 u_long
current_size ();
136 /// Obtain an allocator pointer. If there is no allocator stored in
137 /// the instance, the singleton allocator in the current process is used.
138 ALLOCATOR
* allocator ();
140 /// Event Descriptions
141 EVENT_DESCRIPTIONS event_descriptions_
;
143 /// Sorted Event Descriptions.
144 EVENT_DESCRIPTIONS sorted_event_descriptions_
;
147 ACE_timeprobe_t
*timeprobes_
;
149 /// Synchronization variable.
152 /// Max size of timestamp table
155 /// Current size of timestamp table
156 u_long current_size_
;
158 /// Flag indicating the report buffer has filled up, and is now
159 /// acting as a ring-buffer using modulus arithmetic: this saves the
160 /// max_size_ most recent time stamps and loses earlier ones until
162 u_short report_buffer_full_
;
165 ALLOCATOR
* allocator_
;
168 // template <class ACE_LOCK>
169 // class ACE_Timeprobe : public ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator>
172 // // Initialize a ACE_Timeprobe with default size
173 // ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance());
175 // /// Create Timeprobes with @a size slots
176 // ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance(),
177 // u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
181 * @class ACE_Function_Timeprobe
183 * @brief Auto pointer like time probes. It will record <event> on
184 * construction and <event + 1> on destruction.
186 template <class Timeprobe
>
187 class ACE_Function_Timeprobe
191 ACE_Function_Timeprobe (Timeprobe
&timeprobe
, u_long event
);
194 ~ACE_Function_Timeprobe ();
197 /// Reference to timeprobe.
198 Timeprobe
&timeprobe_
;
204 ACE_END_VERSIONED_NAMESPACE_DECL
206 #include "ace/Timeprobe_T.cpp"
208 #endif /* ACE_COMPILE_TIMEPROBES */
209 #include /**/ "ace/post.h"
210 #endif /* ACE_TIMEPROBE_T_H */