Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Timeprobe_T.h
blob883c9e19e0dcf255f52688784c2b7dd41197df78
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Timeprobe_T.h
7 * @author Irfan Pyarali
8 */
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)
19 # 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
28 /**
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
34 * time probes.
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
51 * necessary.
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
61 public:
62 /// Self
63 typedef ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR>
64 SELF;
66 /**
67 * ACE_Timeprobe
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>
74 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);
82 /// Destructor.
83 ~ACE_Timeprobe_Ex ();
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,
93 u_long minimum_id);
95 /// Print the time probes.
96 void print_times ();
98 /// Print the time probes.
99 void print_absolute_times ();
101 /// Reset the slots. All old time probes will be lost.
102 void reset ();
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 ();
123 /// Time probe slots
124 ACE_timeprobe_t *timeprobes ();
126 /// Synchronization variable.
127 ACE_LOCK &lock ();
129 /// Max size of timestamp table
130 u_long max_size ();
132 /// Current size of timestamp table
133 u_long current_size ();
135 protected:
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_;
146 /// Time probe slots
147 ACE_timeprobe_t *timeprobes_;
149 /// Synchronization variable.
150 ACE_LOCK lock_;
152 /// Max size of timestamp table
153 u_long max_size_;
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
161 /// drained.
162 u_short report_buffer_full_;
164 private:
165 ALLOCATOR * allocator_;
168 // template <class ACE_LOCK>
169 // class ACE_Timeprobe : public ACE_Timeprobe_Ex <ACE_LOCK, ACE_Allocator>
170 // {
171 // public:
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);
178 // };
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
189 public:
190 /// Constructor.
191 ACE_Function_Timeprobe (Timeprobe &timeprobe, u_long event);
193 /// Destructor.
194 ~ACE_Function_Timeprobe ();
196 protected:
197 /// Reference to timeprobe.
198 Timeprobe &timeprobe_;
200 /// Event.
201 u_long event_;
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 */