3
//=============================================================================
7
* Timeprobe_T.h,v 4.24 2003/11/01 11:15:18 dhinton Exp
9
* @author Irfan Pyarali
11
//=============================================================================
14
#ifndef ACE_TIMEPROBE_T_H
15
#define ACE_TIMEPROBE_T_H
16
#include /**/ "ace/pre.h"
18
#include "ace/config-all.h"
20
#if !defined (ACE_LACKS_PRAGMA_ONCE)
22
#endif /* ACE_LACKS_PRAGMA_ONCE */
24
#if defined (ACE_COMPILE_TIMEPROBES)
26
#include "ace/Unbounded_Set.h"
29
* @class ACE_Timeprobe
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
64
typedef ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR>
70
typedef ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator> ACE_Timeprobe;
73
/// We can hold multiple event description tables.
74
typedef ACE_Unbounded_Set<ACE_Event_Descriptions>
77
/// Create Timeprobes with <size> slots
78
ACE_Timeprobe_Ex (u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
80
/// Create Timeprobes with <size> slots
81
ACE_Timeprobe_Ex (ALLOCATOR *allocator,
82
u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
84
~ACE_Timeprobe_Ex (void);
86
/// Record a time. <event> is used to describe this time probe.
87
void timeprobe (u_long event);
89
/// Record a time. <id> is used to describe this time probe.
90
void timeprobe (const char *id);
92
/// Record event descriptions.
93
int event_descriptions (const char **descriptions,
96
/// Print the time probes.
97
void print_times (void);
99
/// Print the time probes.
100
void print_absolute_times (void);
102
/// Reset the slots. All old time probes will be lost.
105
void increase_size (u_long size);
107
/// Not implemented (stupid MSVC won't let it be protected).
108
ACE_Timeprobe_Ex (const ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> &);
110
// = (Somewhat private) Accessors
112
/// Event Descriptions
113
ACE_Unbounded_Set<ACE_Event_Descriptions> &event_descriptions (void);
115
/// Sorted Event Descriptions.
116
ACE_Unbounded_Set<ACE_Event_Descriptions> &sorted_event_descriptions (void);
118
/// Find description of event \<i\>
119
const char *find_description_i (u_long i);
121
/// Sort event descriptions
122
void sort_event_descriptions_i (void);
125
ACE_timeprobe_t *timeprobes (void);
127
/// Synchronization variable.
128
ACE_LOCK &lock (void);
130
/// Max size of timestamp table
131
u_long max_size (void);
133
/// Current size of timestamp table
134
u_long current_size (void);
138
/// Obtain an allocator pointer. If there is no allocator stored in
139
/// the instance, the singleton allocator in the current process is used.
140
ALLOCATOR * allocator (void);
142
/// Event Descriptions
143
EVENT_DESCRIPTIONS event_descriptions_;
145
/// Sorted Event Descriptions.
146
EVENT_DESCRIPTIONS sorted_event_descriptions_;
149
ACE_timeprobe_t *timeprobes_;
151
/// Synchronization variable.
154
/// Max size of timestamp table
157
/// Current size of timestamp table
158
u_long current_size_;
160
/// flag indicating the report buffer has filled up, and is now
161
/// acting as a ring-buffer using modulus arithmetic: this saves the
162
/// max_size_ most recent time stamps and loses earlier ones until
164
u_short report_buffer_full_;
168
ALLOCATOR * allocator_;
171
// template <class ACE_LOCK>
172
// class ACE_Timeprobe : public ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator>
175
// // Initialize a ACE_Timeprobe with default size
176
// ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance());
178
// /// Create Timeprobes with <size> slots
179
// ACE_Timeprobe (ACE_Allocator *allocator = ACE_Allocator::instance(),
180
// u_long size = ACE_DEFAULT_TIMEPROBE_TABLE_SIZE);
184
* @class ACE_Function_Timeprobe
186
* @brief Auto pointer like time probes. It will record <event> on
187
* construction and <event + 1> on destruction.
189
template <class Timeprobe>
190
class ACE_Function_Timeprobe
194
ACE_Function_Timeprobe (Timeprobe &timeprobe,
198
~ACE_Function_Timeprobe (void);
201
/// Reference to timeprobe.
202
Timeprobe &timeprobe_;
208
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
209
#include "ace/Timeprobe_T.cpp"
210
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
212
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
213
#pragma implementation ("Timeprobe_T.cpp")
214
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
216
#endif /* ACE_COMPILE_TIMEPROBES */
217
#include /**/ "ace/post.h"
218
#endif /* ACE_TIMEPROBE_T_H */