OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Trace events are for tracking application performance and resource usage. | 5 // Trace events are for tracking application performance and resource usage. |
6 // Macros are provided to track: | 6 // Macros are provided to track: |
7 // Begin and end of function calls | 7 // Begin and end of function calls |
8 // Counters | 8 // Counters |
9 // | 9 // |
10 // Events are issued against categories. Whereas LOG's | 10 // Events are issued against categories. Whereas LOG's |
(...skipping 16 matching lines...) Expand all Loading... | |
27 // Additional parameters can be associated with an event: | 27 // Additional parameters can be associated with an event: |
28 // void doSomethingCostly2(int howMuch) { | 28 // void doSomethingCostly2(int howMuch) { |
29 // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", | 29 // TRACE_EVENT1("MY_SUBSYSTEM", "doSomethingCostly", |
30 // "howMuch", howMuch); | 30 // "howMuch", howMuch); |
31 // ... | 31 // ... |
32 // } | 32 // } |
33 // | 33 // |
34 // The trace system will automatically add to this information the | 34 // The trace system will automatically add to this information the |
35 // current process id, thread id, and a timestamp in microseconds. | 35 // current process id, thread id, and a timestamp in microseconds. |
36 // | 36 // |
37 // BEGIN and END events should typically be used in the same scope. To trace | |
nduca
2011/12/01 02:55:26
typically->clearly state the nesting requirement.
jbates
2011/12/01 23:07:50
Done.
| |
38 // an asynchronous procedure such as IPC send/receive, use START and FINISH: | |
39 // void* ipc_send(...) { | |
40 // static int send_count = 0; | |
41 // ++send_count; | |
42 // TRACE_EVENT_START0("ipc", "message", send_count); | |
43 // } | |
44 // void ipc_recv(...) { | |
45 // static int recv_count = 0; | |
jar (doing other things)
2011/12/01 01:47:49
This is not multi-thread safe. At first, I though
nduca
2011/12/01 02:55:26
+1, even though its docs, it should be "legitimate
jbates
2011/12/01 23:07:50
Done.
| |
46 // ++recv_count; | |
47 // TRACE_EVENT_FINISH0("ipc", "message", send_count); | |
48 // } | |
49 // The third parameter is a unique ID to match START/FINISH pairs. | |
50 // START and FINISH can occur on any thread of any traced process. Pointers can | |
51 // be used for the ID parameter, and they will be mangled internally so that | |
52 // the same pointer on two different processes will not match. For example: | |
53 // void* trace_malloc(size) { | |
54 // void* ptr = malloc(size); | |
55 // TRACE_EVENT_START0("memory", "malloc", ptr); | |
56 // } | |
57 // void trace_free(ptr) { | |
58 // free(ptr); | |
59 // TRACE_EVENT_FINISH0("memory", "malloc", ptr); | |
jar (doing other things)
2011/12/01 01:47:49
FYI: If you put the free after the event, then you
nduca
2011/12/01 02:55:26
I suggest using an example closer to that ReadTran
jbates
2011/12/01 23:07:50
Done.
| |
60 // } | |
61 // | |
37 // Trace event also supports counters, which is a way to track a quantity | 62 // Trace event also supports counters, which is a way to track a quantity |
38 // as it varies over time. Counters are created with the following macro: | 63 // as it varies over time. Counters are created with the following macro: |
39 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue); | 64 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter", g_myCounterValue); |
40 // | 65 // |
41 // Counters are process-specific. The macro itself can be issued from any | 66 // Counters are process-specific. The macro itself can be issued from any |
42 // thread, however. | 67 // thread, however. |
43 // | 68 // |
44 // Sometimes, you want to track two counters at once. You can do this with two | 69 // Sometimes, you want to track two counters at once. You can do this with two |
45 // counter macros: | 70 // counter macros: |
46 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]); | 71 // TRACE_COUNTER1("MY_SUBSYSTEM", "myCounter0", g_myCounterValue[0]); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 #include "base/timer.h" | 155 #include "base/timer.h" |
131 | 156 |
132 // By default, const char* argument values are assumed to have long-lived scope | 157 // By default, const char* argument values are assumed to have long-lived scope |
133 // and will not be copied. Use this macro to force a const char* to be copied. | 158 // and will not be copied. Use this macro to force a const char* to be copied. |
134 #define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) | 159 #define TRACE_STR_COPY(str) base::debug::TraceValue::StringWithCopy(str) |
135 | 160 |
136 // Older style trace macros with explicit id and extra data | 161 // Older style trace macros with explicit id and extra data |
137 // Only these macros result in publishing data to ETW as currently implemented. | 162 // Only these macros result in publishing data to ETW as currently implemented. |
138 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ | 163 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ |
139 base::debug::TraceLog::AddTraceEventEtw( \ | 164 base::debug::TraceLog::AddTraceEventEtw( \ |
140 base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 165 TRACE_EVENT_PHASE_BEGIN, \ |
141 name, reinterpret_cast<const void*>(id), extra) | 166 name, reinterpret_cast<const void*>(id), extra) |
142 | 167 |
143 #define TRACE_EVENT_END_ETW(name, id, extra) \ | 168 #define TRACE_EVENT_END_ETW(name, id, extra) \ |
144 base::debug::TraceLog::AddTraceEventEtw( \ | 169 base::debug::TraceLog::AddTraceEventEtw( \ |
145 base::debug::TRACE_EVENT_PHASE_END, \ | 170 TRACE_EVENT_PHASE_END, \ |
146 name, reinterpret_cast<const void*>(id), extra) | 171 name, reinterpret_cast<const void*>(id), extra) |
147 | 172 |
148 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ | 173 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ |
149 base::debug::TraceLog::AddTraceEventEtw( \ | 174 base::debug::TraceLog::AddTraceEventEtw( \ |
150 base::debug::TRACE_EVENT_PHASE_INSTANT, \ | 175 TRACE_EVENT_PHASE_INSTANT, \ |
151 name, reinterpret_cast<const void*>(id), extra) | 176 name, reinterpret_cast<const void*>(id), extra) |
152 | 177 |
153 // Records a pair of begin and end events called "name" for the current | 178 // Records a pair of begin and end events called "name" for the current |
154 // scope, with 0, 1 or 2 associated arguments. If the category is not | 179 // scope, with 0, 1 or 2 associated arguments. If the category is not |
155 // enabled, then this does nothing. | 180 // enabled, then this does nothing. |
156 // - category and name strings must have application lifetime (statics or | 181 // - category and name strings must have application lifetime (statics or |
157 // literals). They may not include " chars. | 182 // literals). They may not include " chars. |
158 #define TRACE_EVENT0(category, name) \ | 183 #define TRACE_EVENT0(category, name) \ |
159 TRACE_EVENT1(category, name, NULL, 0) | 184 TRACE_EVENT1(category, name, NULL, 0) |
160 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ | 185 #define TRACE_EVENT1(category, name, arg1_name, arg1_val) \ |
(...skipping 22 matching lines...) Expand all Loading... | |
183 // associated arguments. If the category is not enabled, then this | 208 // associated arguments. If the category is not enabled, then this |
184 // does nothing. | 209 // does nothing. |
185 // - category and name strings must have application lifetime (statics or | 210 // - category and name strings must have application lifetime (statics or |
186 // literals). They may not include " chars. | 211 // literals). They may not include " chars. |
187 #define TRACE_EVENT_INSTANT0(category, name) \ | 212 #define TRACE_EVENT_INSTANT0(category, name) \ |
188 TRACE_EVENT_INSTANT1(category, name, NULL, 0) | 213 TRACE_EVENT_INSTANT1(category, name, NULL, 0) |
189 #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ | 214 #define TRACE_EVENT_INSTANT1(category, name, arg1_name, arg1_val) \ |
190 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) | 215 TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) |
191 #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ | 216 #define TRACE_EVENT_INSTANT2(category, name, arg1_name, arg1_val, \ |
192 arg2_name, arg2_val) \ | 217 arg2_name, arg2_val) \ |
193 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_INSTANT, \ | 218 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
194 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 219 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
195 base::debug::TraceLog::EVENT_FLAG_NONE) | 220 TRACE_EVENT_FLAG_NONE) |
196 #define TRACE_EVENT_COPY_INSTANT0(category, name) \ | 221 #define TRACE_EVENT_COPY_INSTANT0(category, name) \ |
197 TRACE_EVENT_COPY_INSTANT1(category, name, NULL, 0) | 222 TRACE_EVENT_COPY_INSTANT1(category, name, NULL, 0) |
198 #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ | 223 #define TRACE_EVENT_COPY_INSTANT1(category, name, arg1_name, arg1_val) \ |
199 TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) | 224 TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, NULL, 0) |
200 #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ | 225 #define TRACE_EVENT_COPY_INSTANT2(category, name, arg1_name, arg1_val, \ |
201 arg2_name, arg2_val) \ | 226 arg2_name, arg2_val) \ |
202 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_INSTANT, \ | 227 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_INSTANT, \ |
203 category, name, \ | 228 category, name, \ |
204 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 229 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
205 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | 230 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
206 base::debug::TraceLog::EVENT_FLAG_COPY) | 231 TRACE_EVENT_FLAG_COPY) |
207 | 232 |
208 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 | 233 // Records a single BEGIN event called "name" immediately, with 0, 1 or 2 |
209 // associated arguments. If the category is not enabled, then this | 234 // associated arguments. If the category is not enabled, then this |
210 // does nothing. | 235 // does nothing. |
211 // - category and name strings must have application lifetime (statics or | 236 // - category and name strings must have application lifetime (statics or |
212 // literals). They may not include " chars. | 237 // literals). They may not include " chars. |
213 #define TRACE_EVENT_BEGIN0(category, name) \ | 238 #define TRACE_EVENT_BEGIN0(category, name) \ |
214 TRACE_EVENT_BEGIN1(category, name, NULL, 0) | 239 TRACE_EVENT_BEGIN1(category, name, NULL, 0) |
215 #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ | 240 #define TRACE_EVENT_BEGIN1(category, name, arg1_name, arg1_val) \ |
216 TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) | 241 TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) |
217 #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ | 242 #define TRACE_EVENT_BEGIN2(category, name, arg1_name, arg1_val, \ |
218 arg2_name, arg2_val) \ | 243 arg2_name, arg2_val) \ |
219 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 244 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
220 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 245 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
221 base::debug::TraceLog::EVENT_FLAG_NONE) | 246 TRACE_EVENT_FLAG_NONE) |
222 #define TRACE_EVENT_COPY_BEGIN0(category, name) \ | 247 #define TRACE_EVENT_COPY_BEGIN0(category, name) \ |
223 TRACE_EVENT_COPY_BEGIN1(category, name, NULL, 0) | 248 TRACE_EVENT_COPY_BEGIN1(category, name, NULL, 0) |
224 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ | 249 #define TRACE_EVENT_COPY_BEGIN1(category, name, arg1_name, arg1_val) \ |
225 TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) | 250 TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, NULL, 0) |
226 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ | 251 #define TRACE_EVENT_COPY_BEGIN2(category, name, arg1_name, arg1_val, \ |
227 arg2_name, arg2_val) \ | 252 arg2_name, arg2_val) \ |
228 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 253 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_BEGIN, \ |
229 category, name, \ | 254 category, name, \ |
230 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 255 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
231 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | 256 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
232 base::debug::TraceLog::EVENT_FLAG_COPY) | 257 TRACE_EVENT_FLAG_COPY) |
233 | 258 |
234 // Records a single END event for "name" immediately. If the category | 259 // Records a single END event for "name" immediately. If the category |
235 // is not enabled, then this does nothing. | 260 // is not enabled, then this does nothing. |
236 // - category and name strings must have application lifetime (statics or | 261 // - category and name strings must have application lifetime (statics or |
237 // literals). They may not include " chars. | 262 // literals). They may not include " chars. |
238 #define TRACE_EVENT_END0(category, name) \ | 263 #define TRACE_EVENT_END0(category, name) \ |
239 TRACE_EVENT_END1(category, name, NULL, 0) | 264 TRACE_EVENT_END1(category, name, NULL, 0) |
240 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ | 265 #define TRACE_EVENT_END1(category, name, arg1_name, arg1_val) \ |
241 TRACE_EVENT_END2(category, name, arg1_name, arg1_val, NULL, 0) | 266 TRACE_EVENT_END2(category, name, arg1_name, arg1_val, NULL, 0) |
242 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ | 267 #define TRACE_EVENT_END2(category, name, arg1_name, arg1_val, \ |
243 arg2_name, arg2_val) \ | 268 arg2_name, arg2_val) \ |
244 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_END, \ | 269 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
245 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ | 270 category, name, arg1_name, arg1_val, arg2_name, arg2_val, \ |
246 base::debug::TraceLog::EVENT_FLAG_NONE) | 271 TRACE_EVENT_FLAG_NONE) |
247 #define TRACE_EVENT_COPY_END0(category, name) \ | 272 #define TRACE_EVENT_COPY_END0(category, name) \ |
248 TRACE_EVENT_COPY_END1(category, name, NULL, 0) | 273 TRACE_EVENT_COPY_END1(category, name, NULL, 0) |
249 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ | 274 #define TRACE_EVENT_COPY_END1(category, name, arg1_name, arg1_val) \ |
250 TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, NULL, 0) | 275 TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, NULL, 0) |
251 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ | 276 #define TRACE_EVENT_COPY_END2(category, name, arg1_name, arg1_val, \ |
252 arg2_name, arg2_val) \ | 277 arg2_name, arg2_val) \ |
253 INTERNAL_TRACE_EVENT_ADD(base::debug::TRACE_EVENT_PHASE_END, \ | 278 INTERNAL_TRACE_EVENT_ADD(TRACE_EVENT_PHASE_END, \ |
254 category, name, \ | 279 category, name, \ |
255 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | 280 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ |
256 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | 281 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ |
257 base::debug::TraceLog::EVENT_FLAG_COPY) | 282 TRACE_EVENT_FLAG_COPY) |
258 | 283 |
259 // Time threshold event: | 284 // Time threshold event: |
260 // Only record the event if the duration is greater than the specified | 285 // Only record the event if the duration is greater than the specified |
261 // threshold_us (time in microseconds). | 286 // threshold_us (time in microseconds). |
262 // Records a pair of begin and end events called "name" for the current | 287 // Records a pair of begin and end events called "name" for the current |
263 // scope, with 0, 1 or 2 associated arguments. If the category is not | 288 // scope, with 0, 1 or 2 associated arguments. If the category is not |
264 // enabled, then this does nothing. | 289 // enabled, then this does nothing. |
265 // - category and name strings must have application lifetime (statics or | 290 // - category and name strings must have application lifetime (statics or |
266 // literals). They may not include " chars. | 291 // literals). They may not include " chars. |
267 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ | 292 #define TRACE_EVENT_IF_LONGER_THAN0(threshold_us, category, name) \ |
(...skipping 18 matching lines...) Expand all Loading... | |
286 | 311 |
287 // Records the values of a multi-parted counter called "name" immediately. | 312 // Records the values of a multi-parted counter called "name" immediately. |
288 // The UI will treat value1 and value2 as parts of a whole, displaying their | 313 // The UI will treat value1 and value2 as parts of a whole, displaying their |
289 // values as a stacked-bar chart. | 314 // values as a stacked-bar chart. |
290 // - category and name strings must have application lifetime (statics or | 315 // - category and name strings must have application lifetime (statics or |
291 // literals). They may not include " chars. | 316 // literals). They may not include " chars. |
292 #define TRACE_COUNTER2(category, name, value1_name, value1_val, \ | 317 #define TRACE_COUNTER2(category, name, value1_name, value1_val, \ |
293 value2_name, value2_val) \ | 318 value2_name, value2_val) \ |
294 INTERNAL_TRACE_EVENT_ADD_COUNTER( \ | 319 INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
295 category, name, value1_name, value1_val, value2_name, value2_val, \ | 320 category, name, value1_name, value1_val, value2_name, value2_val, \ |
296 base::debug::TraceLog::EVENT_FLAG_NONE) | 321 TRACE_EVENT_FLAG_NONE) |
297 #define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ | 322 #define TRACE_COPY_COUNTER2(category, name, value1_name, value1_val, \ |
298 value2_name, value2_val) \ | 323 value2_name, value2_val) \ |
299 INTERNAL_TRACE_EVENT_ADD_COUNTER( \ | 324 INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
300 category, name, \ | 325 category, name, \ |
301 value1_name, value1_val, \ | 326 value1_name, value1_val, \ |
302 value2_name, value2_val, \ | 327 value2_name, value2_val, \ |
303 base::debug::TraceLog::EVENT_FLAG_COPY) | 328 TRACE_EVENT_FLAG_COPY) |
329 | |
330 | |
331 // Records a single START event called "name" immediately, with 0, 1 or 2 | |
332 // associated arguments. If the category is not enabled, then this | |
333 // does nothing. | |
334 // - category and name strings must have application lifetime (statics or | |
335 // literals). They may not include " chars. | |
336 // - |id| is used to match the START event with the FINISH event. It must either | |
337 // be a pointer or an integer value up to 64 bits. If it's a pointer, the bits | |
338 // will be xored with a hash of the process ID so that the same pointer on | |
339 // two different processes will not collide. | |
340 #define TRACE_EVENT_START0(category, name, id) \ | |
341 TRACE_EVENT_START1(category, name, id, NULL, 0) | |
342 #define TRACE_EVENT_START1(category, name, id, arg1_name, arg1_val) \ | |
343 TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, NULL, 0) | |
344 #define TRACE_EVENT_START2(category, name, id, arg1_name, arg1_val, \ | |
345 arg2_name, arg2_val) \ | |
346 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ | |
347 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ | |
348 TRACE_EVENT_FLAG_HAS_ID) | |
349 #define TRACE_EVENT_COPY_START0(category, name, id) \ | |
350 TRACE_EVENT_COPY_START1(category, name, id, NULL, 0) | |
351 #define TRACE_EVENT_COPY_START1(category, name, id, arg1_name, arg1_val) \ | |
352 TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, NULL, 0) | |
353 #define TRACE_EVENT_COPY_START2(category, name, id, arg1_name, arg1_val, \ | |
354 arg2_name, arg2_val) \ | |
355 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_START, \ | |
356 category, name, id, \ | |
357 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | |
358 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
359 TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
360 | |
361 // Records a single FINISH event for "name" immediately. If the category | |
362 // is not enabled, then this does nothing. | |
363 #define TRACE_EVENT_FINISH0(category, name, id) \ | |
364 TRACE_EVENT_FINISH1(category, name, id, NULL, 0) | |
365 #define TRACE_EVENT_FINISH1(category, name, id, arg1_name, arg1_val) \ | |
366 TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) | |
367 #define TRACE_EVENT_FINISH2(category, name, id, arg1_name, arg1_val, \ | |
368 arg2_name, arg2_val) \ | |
369 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ | |
370 category, name, id, arg1_name, arg1_val, arg2_name, arg2_val, \ | |
371 TRACE_EVENT_FLAG_HAS_ID) | |
372 #define TRACE_EVENT_COPY_FINISH0(category, name, id) \ | |
373 TRACE_EVENT_COPY_FINISH1(category, name, id, NULL, 0) | |
374 #define TRACE_EVENT_COPY_FINISH1(category, name, id, arg1_name, arg1_val) \ | |
375 TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, NULL, 0) | |
376 #define TRACE_EVENT_COPY_FINISH2(category, name, id, arg1_name, arg1_val, \ | |
377 arg2_name, arg2_val) \ | |
378 INTERNAL_TRACE_EVENT_ADD_WITH_ID(TRACE_EVENT_PHASE_FINISH, \ | |
379 category, name, id, \ | |
380 arg1_name, base::debug::TraceValue::ForceCopy(arg1_val), \ | |
381 arg2_name, base::debug::TraceValue::ForceCopy(arg2_val), \ | |
382 TRACE_EVENT_FLAG_HAS_ID | TRACE_EVENT_FLAG_COPY) | |
304 | 383 |
305 | 384 |
306 // Implementation detail: trace event macros create temporary variables | 385 // Implementation detail: trace event macros create temporary variables |
307 // to keep instrumentation overhead low. These macros give each temporary | 386 // to keep instrumentation overhead low. These macros give each temporary |
308 // variable a unique name based on the line number to prevent name collissions. | 387 // variable a unique name based on the line number to prevent name collissions. |
309 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ | 388 #define INTERNAL_TRACE_EVENT_UID3(a,b) \ |
310 trace_event_unique_##a##b | 389 trace_event_unique_##a##b |
311 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ | 390 #define INTERNAL_TRACE_EVENT_UID2(a,b) \ |
312 INTERNAL_TRACE_EVENT_UID3(a,b) | 391 INTERNAL_TRACE_EVENT_UID3(a,b) |
313 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ | 392 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \ |
314 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) | 393 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__) |
315 | 394 |
316 // Implementation detail: internal macro to create static category. | 395 // Implementation detail: internal macro to create static category. |
317 // - ANNOTATE_BENIGN_RACE, see Thread Safety above. | 396 // - ANNOTATE_BENIGN_RACE, see Thread Safety above. |
318 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ | 397 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category) \ |
319 static const base::debug::TraceCategory* \ | 398 static const base::debug::TraceCategory* \ |
320 INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ | 399 INTERNAL_TRACE_EVENT_UID(catstatic) = NULL; \ |
321 ANNOTATE_BENIGN_RACE(&INTERNAL_TRACE_EVENT_UID(catstatic), \ | 400 ANNOTATE_BENIGN_RACE(&INTERNAL_TRACE_EVENT_UID(catstatic), \ |
322 "trace_event category"); \ | 401 "trace_event category"); \ |
323 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) \ | 402 if (!INTERNAL_TRACE_EVENT_UID(catstatic)) \ |
324 INTERNAL_TRACE_EVENT_UID(catstatic) = \ | 403 INTERNAL_TRACE_EVENT_UID(catstatic) = \ |
325 base::debug::TraceLog::GetCategory(category); | 404 base::debug::TraceLog::GetCategory(category); |
326 | 405 |
327 // Implementation detail: internal macro to create static category and add begin | 406 // Implementation detail: internal macro to create static category and add |
328 // event if the category is enabled. | 407 // event if the category is enabled. |
329 #define INTERNAL_TRACE_EVENT_ADD( \ | 408 #define INTERNAL_TRACE_EVENT_ADD( \ |
330 phase, category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | 409 phase, category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
331 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 410 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
332 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 411 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
333 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 412 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
334 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | 413 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ |
335 name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ | 414 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ |
336 } | 415 } |
337 | 416 |
338 // Implementation detail: internal macro to create static category and | 417 // Implementation detail: internal macro to create static category and |
339 // add the counter event if it is enabled. | 418 // add the counter event if it is enabled. |
340 #define INTERNAL_TRACE_EVENT_ADD_COUNTER( \ | 419 #define INTERNAL_TRACE_EVENT_ADD_COUNTER( \ |
341 category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | 420 category, name, arg1_name, arg1_val, arg2_name, arg2_val, flags) \ |
342 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 421 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
343 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 422 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
344 base::debug::TraceLog::GetInstance()->AddCounterEvent( \ | 423 base::debug::TraceLog::GetInstance()->AddCounterEvent( \ |
345 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 424 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
346 name, arg1_name, arg1_val, arg2_name, arg2_val, flags); \ | 425 name, arg1_name, arg1_val, arg2_name, arg2_val, flags); \ |
347 } | 426 } |
348 | 427 |
349 // Implementation detail: internal macro to create static category and add begin | 428 // Implementation detail: internal macro to create static category and add begin |
350 // event if the category is enabled. Also adds the end event when the scope | 429 // event if the category is enabled. Also adds the end event when the scope |
351 // ends. | 430 // ends. |
352 #define INTERNAL_TRACE_EVENT_ADD_SCOPED( \ | 431 #define INTERNAL_TRACE_EVENT_ADD_SCOPED( \ |
353 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | 432 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
354 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 433 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
355 base::debug::internal::TraceEndOnScopeClose \ | 434 base::debug::internal::TraceEndOnScopeClose \ |
356 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 435 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
357 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 436 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
358 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 437 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
359 base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 438 TRACE_EVENT_PHASE_BEGIN, \ |
360 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 439 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
361 name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ | 440 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ |
362 base::debug::TraceLog::EVENT_FLAG_NONE); \ | 441 TRACE_EVENT_FLAG_NONE); \ |
363 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ | 442 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
364 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ | 443 INTERNAL_TRACE_EVENT_UID(catstatic), name); \ |
365 } | 444 } |
366 | 445 |
367 // Implementation detail: internal macro to create static category and add begin | 446 // Implementation detail: internal macro to create static category and add begin |
368 // event if the category is enabled. Also adds the end event when the scope | 447 // event if the category is enabled. Also adds the end event when the scope |
369 // ends. If the elapsed time is < threshold time, the begin/end pair is erased. | 448 // ends. If the elapsed time is < threshold time, the begin/end pair is erased. |
370 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ | 449 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_IF_LONGER_THAN(threshold, \ |
371 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ | 450 category, name, arg1_name, arg1_val, arg2_name, arg2_val) \ |
372 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | 451 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ |
373 base::debug::internal::TraceEndOnScopeCloseThreshold \ | 452 base::debug::internal::TraceEndOnScopeCloseThreshold \ |
374 INTERNAL_TRACE_EVENT_UID(profileScope); \ | 453 INTERNAL_TRACE_EVENT_UID(profileScope); \ |
375 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | 454 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ |
376 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ | 455 int INTERNAL_TRACE_EVENT_UID(begin_event_id) = \ |
377 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | 456 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ |
378 base::debug::TRACE_EVENT_PHASE_BEGIN, \ | 457 TRACE_EVENT_PHASE_BEGIN, \ |
379 INTERNAL_TRACE_EVENT_UID(catstatic), \ | 458 INTERNAL_TRACE_EVENT_UID(catstatic), \ |
380 name, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ | 459 name, 0, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, \ |
381 base::debug::TraceLog::EVENT_FLAG_NONE); \ | 460 TRACE_EVENT_FLAG_NONE); \ |
382 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ | 461 INTERNAL_TRACE_EVENT_UID(profileScope).Initialize( \ |
383 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ | 462 INTERNAL_TRACE_EVENT_UID(catstatic), name, \ |
384 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ | 463 INTERNAL_TRACE_EVENT_UID(begin_event_id), threshold); \ |
385 } | 464 } |
386 | 465 |
466 // Implementation detail: internal macro to create static category and add | |
467 // event if the category is enabled. | |
468 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category, name, id, \ | |
469 arg1_name, arg1_val, arg2_name, arg2_val, flags) \ | |
470 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category); \ | |
471 if (INTERNAL_TRACE_EVENT_UID(catstatic)->enabled) { \ | |
472 base::debug::TraceLog::GetInstance()->AddTraceEvent( \ | |
473 phase, INTERNAL_TRACE_EVENT_UID(catstatic), \ | |
474 name, id, arg1_name, arg1_val, arg2_name, arg2_val, -1, 0, flags); \ | |
475 } | |
476 | |
387 template <typename Type> | 477 template <typename Type> |
388 struct StaticMemorySingletonTraits; | 478 struct StaticMemorySingletonTraits; |
389 | 479 |
390 namespace base { | 480 namespace base { |
391 | 481 |
392 class RefCountedString; | 482 class RefCountedString; |
393 | 483 |
394 namespace debug { | 484 namespace debug { |
395 | 485 |
396 // Categories allow enabling/disabling of streams of trace events | 486 // Categories allow enabling/disabling of streams of trace events |
397 struct TraceCategory { | 487 struct TraceCategory { |
398 const char* name; | 488 const char* name; |
399 volatile bool enabled; | 489 volatile bool enabled; |
400 }; | 490 }; |
401 | 491 |
402 const size_t kTraceMaxNumArgs = 2; | 492 const size_t kTraceMaxNumArgs = 2; |
403 | 493 |
404 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. | 494 // Phase indicates the nature of an event entry. E.g. part of a begin/end pair. |
405 enum TraceEventPhase { | 495 typedef char TraceEventPhase; |
406 TRACE_EVENT_PHASE_BEGIN, | 496 #define TRACE_EVENT_PHASE_BEGIN (base::debug::TraceEventPhase('B')) |
407 TRACE_EVENT_PHASE_END, | 497 #define TRACE_EVENT_PHASE_END (base::debug::TraceEventPhase('E')) |
408 TRACE_EVENT_PHASE_INSTANT, | 498 #define TRACE_EVENT_PHASE_INSTANT (base::debug::TraceEventPhase('I')) |
409 TRACE_EVENT_PHASE_METADATA, | 499 #define TRACE_EVENT_PHASE_START (base::debug::TraceEventPhase('S')) |
410 TRACE_EVENT_PHASE_COUNTER | 500 #define TRACE_EVENT_PHASE_FINISH (base::debug::TraceEventPhase('F')) |
411 }; | 501 #define TRACE_EVENT_PHASE_METADATA (base::debug::TraceEventPhase('M')) |
502 #define TRACE_EVENT_PHASE_COUNTER (base::debug::TraceEventPhase('C')) | |
503 | |
504 typedef uint8 TraceEventFlags; | |
505 #define TRACE_EVENT_FLAG_NONE (base::debug::TraceEventFlags(0)) | |
506 #define TRACE_EVENT_FLAG_COPY (base::debug::TraceEventFlags(1<<0)) | |
507 #define TRACE_EVENT_FLAG_HAS_ID (base::debug::TraceEventFlags(1<<1)) | |
412 | 508 |
nduca
2011/12/01 02:55:26
<3
| |
413 // Simple union of values. This is much lighter weight than base::Value, which | 509 // Simple union of values. This is much lighter weight than base::Value, which |
414 // requires dynamic allocation and a vtable. To keep the trace runtime overhead | 510 // requires dynamic allocation and a vtable. To keep the trace runtime overhead |
415 // low, we want constant size storage here. | 511 // low, we want constant size storage here. |
416 class BASE_EXPORT TraceValue { | 512 class BASE_EXPORT TraceValue { |
417 public: | 513 public: |
418 enum Type { | 514 enum Type { |
419 TRACE_TYPE_UNDEFINED, | 515 TRACE_TYPE_UNDEFINED, |
420 TRACE_TYPE_BOOL, | 516 TRACE_TYPE_BOOL, |
421 TRACE_TYPE_UINT, | 517 TRACE_TYPE_UINT, |
422 TRACE_TYPE_INT, | 518 TRACE_TYPE_INT, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 int64 as_int; | 624 int64 as_int; |
529 double as_double; | 625 double as_double; |
530 const void* as_pointer; | 626 const void* as_pointer; |
531 const char* as_string; | 627 const char* as_string; |
532 }; | 628 }; |
533 | 629 |
534 Type type_; | 630 Type type_; |
535 Value value_; | 631 Value value_; |
536 }; | 632 }; |
537 | 633 |
634 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers | |
635 // are mangled with the Process ID so that they are unlikely to collide when the | |
636 // same pointer is used on different processes. | |
637 class BASE_EXPORT TraceID { | |
638 public: | |
639 TraceID() : data_(NULL) {} | |
640 TraceID(void* rhs); | |
641 TraceID(unsigned long long rhs) : data_(static_cast<uint64>(rhs)) {} | |
642 TraceID(unsigned long rhs) : data_(static_cast<uint64>(rhs)) {} | |
643 TraceID(unsigned int rhs) : data_(static_cast<uint64>(rhs)) {} | |
644 TraceID(long long rhs) : data_(static_cast<uint64>(rhs)) {} | |
645 TraceID(long rhs) : data_(static_cast<uint64>(rhs)) {} | |
646 TraceID(int rhs) : data_(static_cast<uint64>(rhs)) {} | |
647 | |
648 uint64 data() const { return data_; } | |
649 | |
650 private: | |
651 uint64 data_; | |
652 }; | |
653 | |
538 // Output records are "Events" and can be obtained via the | 654 // Output records are "Events" and can be obtained via the |
539 // OutputCallback whenever the tracing system decides to flush. This | 655 // OutputCallback whenever the tracing system decides to flush. This |
540 // can happen at any time, on any thread, or you can programatically | 656 // can happen at any time, on any thread, or you can programatically |
541 // force it to happen. | 657 // force it to happen. |
542 class BASE_EXPORT TraceEvent { | 658 class BASE_EXPORT TraceEvent { |
543 public: | 659 public: |
544 TraceEvent(); | 660 TraceEvent(); |
545 TraceEvent(unsigned long process_id, | 661 TraceEvent(int thread_id, |
546 unsigned long thread_id, | |
547 TimeTicks timestamp, | 662 TimeTicks timestamp, |
548 TraceEventPhase phase, | 663 TraceEventPhase phase, |
549 const TraceCategory* category, | 664 const TraceCategory* category, |
550 const char* name, | 665 const char* name, |
666 TraceID id, | |
551 const char* arg1_name, const TraceValue& arg1_val, | 667 const char* arg1_name, const TraceValue& arg1_val, |
552 const char* arg2_name, const TraceValue& arg2_val, | 668 const char* arg2_name, const TraceValue& arg2_val, |
553 bool copy); | 669 TraceEventFlags flags); |
554 ~TraceEvent(); | 670 ~TraceEvent(); |
555 | 671 |
556 static const char* GetPhaseString(TraceEventPhase phase); | 672 static char GetPhaseChar(TraceEventPhase phase) { |
557 static TraceEventPhase GetPhase(const char* phase); | 673 return static_cast<char>(phase); |
674 } | |
675 | |
676 static TraceEventPhase GetPhase(const char* phase) { | |
677 return static_cast<TraceEventPhase>(*phase); | |
678 } | |
558 | 679 |
559 // Serialize event data to JSON | 680 // Serialize event data to JSON |
560 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, | 681 static void AppendEventsAsJSON(const std::vector<TraceEvent>& events, |
561 size_t start, | 682 size_t start, |
562 size_t count, | 683 size_t count, |
563 std::string* out); | 684 std::string* out); |
564 void AppendAsJSON(std::string* out) const; | 685 void AppendAsJSON(std::string* out) const; |
565 | 686 |
566 TimeTicks timestamp() const { return timestamp_; } | 687 TimeTicks timestamp() const { return timestamp_; } |
567 | 688 |
568 // Exposed for unittesting: | 689 // Exposed for unittesting: |
569 | 690 |
570 const base::RefCountedString* parameter_copy_storage() const { | 691 const base::RefCountedString* parameter_copy_storage() const { |
571 return parameter_copy_storage_.get(); | 692 return parameter_copy_storage_.get(); |
572 } | 693 } |
573 | 694 |
574 const char* name() const { return name_; } | 695 const char* name() const { return name_; } |
575 | 696 |
576 private: | 697 private: |
577 unsigned long process_id_; | 698 // Note: these are ordered by size (largest first) for optimal packing. |
578 unsigned long thread_id_; | |
579 TimeTicks timestamp_; | 699 TimeTicks timestamp_; |
580 TraceEventPhase phase_; | 700 // id_ can be used to store phase-specific data. |
701 TraceID id_; | |
702 TraceValue arg_values_[kTraceMaxNumArgs]; | |
703 const char* arg_names_[kTraceMaxNumArgs]; | |
581 const TraceCategory* category_; | 704 const TraceCategory* category_; |
582 const char* name_; | 705 const char* name_; |
583 const char* arg_names_[kTraceMaxNumArgs]; | |
584 TraceValue arg_values_[kTraceMaxNumArgs]; | |
585 scoped_refptr<base::RefCountedString> parameter_copy_storage_; | 706 scoped_refptr<base::RefCountedString> parameter_copy_storage_; |
707 int thread_id_; | |
708 TraceEventPhase phase_; | |
709 TraceEventFlags flags_; | |
586 }; | 710 }; |
587 | 711 |
588 | 712 |
589 // TraceResultBuffer collects and converts trace fragments returned by TraceLog | 713 // TraceResultBuffer collects and converts trace fragments returned by TraceLog |
590 // to JSON output. | 714 // to JSON output. |
591 class BASE_EXPORT TraceResultBuffer { | 715 class BASE_EXPORT TraceResultBuffer { |
592 public: | 716 public: |
593 typedef base::Callback<void(const std::string&)> OutputCallback; | 717 typedef base::Callback<void(const std::string&)> OutputCallback; |
594 | 718 |
595 // If you don't need to stream JSON chunks out efficiently, and just want to | 719 // If you don't need to stream JSON chunks out efficiently, and just want to |
(...skipping 29 matching lines...) Expand all Loading... | |
625 void Finish(); | 749 void Finish(); |
626 | 750 |
627 private: | 751 private: |
628 OutputCallback output_callback_; | 752 OutputCallback output_callback_; |
629 bool append_comma_; | 753 bool append_comma_; |
630 }; | 754 }; |
631 | 755 |
632 | 756 |
633 class BASE_EXPORT TraceLog { | 757 class BASE_EXPORT TraceLog { |
634 public: | 758 public: |
635 // Flags for passing to AddTraceEvent. | |
636 enum EventFlags { | |
637 EVENT_FLAG_NONE = 0, | |
638 EVENT_FLAG_COPY = 1<<0 | |
639 }; | |
640 | |
641 static TraceLog* GetInstance(); | 759 static TraceLog* GetInstance(); |
642 | 760 |
643 // Get set of known categories. This can change as new code paths are reached. | 761 // Get set of known categories. This can change as new code paths are reached. |
644 // The known categories are inserted into |categories|. | 762 // The known categories are inserted into |categories|. |
645 void GetKnownCategories(std::vector<std::string>* categories); | 763 void GetKnownCategories(std::vector<std::string>* categories); |
646 | 764 |
647 // Enable tracing for provided list of categories. If tracing is already | 765 // Enable tracing for provided list of categories. If tracing is already |
648 // enabled, this method does nothing -- changing categories during trace is | 766 // enabled, this method does nothing -- changing categories during trace is |
649 // not supported. | 767 // not supported. |
650 // If both included_categories and excluded_categories are empty, | 768 // If both included_categories and excluded_categories are empty, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 // Returns the index in the internal vector of the event if it was added, or | 821 // Returns the index in the internal vector of the event if it was added, or |
704 // -1 if the event was not added. | 822 // -1 if the event was not added. |
705 // On end events, the return value of the begin event can be specified along | 823 // On end events, the return value of the begin event can be specified along |
706 // with a threshold in microseconds. If the elapsed time between begin and end | 824 // with a threshold in microseconds. If the elapsed time between begin and end |
707 // is less than the threshold, the begin/end event pair is dropped. | 825 // is less than the threshold, the begin/end event pair is dropped. |
708 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied | 826 // If |copy| is set, |name|, |arg_name1| and |arg_name2| will be deep copied |
709 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. | 827 // into the event; see "Memory scoping note" and TRACE_EVENT_COPY_XXX above. |
710 int AddTraceEvent(TraceEventPhase phase, | 828 int AddTraceEvent(TraceEventPhase phase, |
711 const TraceCategory* category, | 829 const TraceCategory* category, |
712 const char* name, | 830 const char* name, |
831 TraceID id, | |
713 const char* arg1_name, TraceValue arg1_val, | 832 const char* arg1_name, TraceValue arg1_val, |
714 const char* arg2_name, TraceValue arg2_val, | 833 const char* arg2_name, TraceValue arg2_val, |
715 int threshold_begin_id, | 834 int threshold_begin_id, |
716 int64 threshold, | 835 int64 threshold, |
717 EventFlags flags); | 836 TraceEventFlags flags); |
718 static void AddTraceEventEtw(TraceEventPhase phase, | 837 static void AddTraceEventEtw(TraceEventPhase phase, |
719 const char* name, | 838 const char* name, |
720 const void* id, | 839 const void* id, |
721 const char* extra); | 840 const char* extra); |
722 static void AddTraceEventEtw(TraceEventPhase phase, | 841 static void AddTraceEventEtw(TraceEventPhase phase, |
723 const char* name, | 842 const char* name, |
724 const void* id, | 843 const void* id, |
725 const std::string& extra); | 844 const std::string& extra); |
726 | 845 |
727 // A wrapper around AddTraceEvent used by TRACE_COUNTERx macros | 846 // A wrapper around AddTraceEvent used by TRACE_COUNTERx macros |
728 // that allows only integer values for the counters. | 847 // that allows only integer values for the counters. |
729 int AddCounterEvent(const TraceCategory* category, | 848 int AddCounterEvent(const TraceCategory* category, |
730 const char* name, | 849 const char* name, |
731 const char* arg1_name, int32 arg1_val, | 850 const char* arg1_name, int32 arg1_val, |
732 const char* arg2_name, int32 arg2_val, | 851 const char* arg2_name, int32 arg2_val, |
733 EventFlags flags); | 852 TraceEventFlags flags); |
853 | |
854 // Mangle |id| with a hash based on the process ID so that if |id| occurs on | |
855 // more than one process, it will not collide. | |
856 uint64 GetIntraProcessID(uint64 id) const { return id ^ process_id_hash_; } | |
nduca
2011/12/01 02:55:26
Why this versus just tracking id and a bool flag s
jbates
2011/12/01 23:07:50
Sounds good, but sadly I think I would have to dou
| |
857 | |
858 int process_id() const { return process_id_; } | |
734 | 859 |
735 // Exposed for unittesting: | 860 // Exposed for unittesting: |
736 | 861 |
737 // Allows deleting our singleton instance. | 862 // Allows deleting our singleton instance. |
738 static void DeleteForTesting(); | 863 static void DeleteForTesting(); |
739 | 864 |
740 // Allows resurrecting our singleton instance post-AtExit processing. | 865 // Allows resurrecting our singleton instance post-AtExit processing. |
741 static void Resurrect(); | 866 static void Resurrect(); |
742 | 867 |
743 // Allow tests to inspect TraceEvents. | 868 // Allow tests to inspect TraceEvents. |
744 size_t GetEventsSize() const { return logged_events_.size(); } | 869 size_t GetEventsSize() const { return logged_events_.size(); } |
745 const TraceEvent& GetEventAt(size_t index) const { | 870 const TraceEvent& GetEventAt(size_t index) const { |
746 DCHECK(index < logged_events_.size()); | 871 DCHECK(index < logged_events_.size()); |
747 return logged_events_[index]; | 872 return logged_events_[index]; |
748 } | 873 } |
749 | 874 |
875 void SetProcessID(int process_id); | |
876 | |
750 private: | 877 private: |
751 // This allows constructor and destructor to be private and usable only | 878 // This allows constructor and destructor to be private and usable only |
752 // by the Singleton class. | 879 // by the Singleton class. |
753 friend struct StaticMemorySingletonTraits<TraceLog>; | 880 friend struct StaticMemorySingletonTraits<TraceLog>; |
754 | 881 |
755 TraceLog(); | 882 TraceLog(); |
756 ~TraceLog(); | 883 ~TraceLog(); |
757 const TraceCategory* GetCategoryInternal(const char* name); | 884 const TraceCategory* GetCategoryInternal(const char* name); |
758 void AddCurrentMetadataEvents(); | 885 void AddCurrentMetadataEvents(); |
759 | 886 |
760 // TODO(nduca): switch to per-thread trace buffers to reduce thread | 887 // TODO(nduca): switch to per-thread trace buffers to reduce thread |
761 // synchronization. | 888 // synchronization. |
762 Lock lock_; | 889 Lock lock_; |
763 bool enabled_; | 890 bool enabled_; |
764 OutputCallback output_callback_; | 891 OutputCallback output_callback_; |
765 BufferFullCallback buffer_full_callback_; | 892 BufferFullCallback buffer_full_callback_; |
766 std::vector<TraceEvent> logged_events_; | 893 std::vector<TraceEvent> logged_events_; |
767 std::vector<std::string> included_categories_; | 894 std::vector<std::string> included_categories_; |
768 std::vector<std::string> excluded_categories_; | 895 std::vector<std::string> excluded_categories_; |
769 | 896 |
770 base::hash_map<PlatformThreadId, std::string> thread_names_; | 897 base::hash_map<int, std::string> thread_names_; |
898 | |
899 // XORed with TraceID to make it unlikely to collide with other processes. | |
900 uint64 process_id_hash_; | |
901 | |
902 int process_id_; | |
771 | 903 |
772 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 904 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
773 }; | 905 }; |
774 | 906 |
775 namespace internal { | 907 namespace internal { |
776 | 908 |
777 // Used by TRACE_EVENTx macro. Do not use directly. | 909 // Used by TRACE_EVENTx macro. Do not use directly. |
778 class BASE_EXPORT TraceEndOnScopeClose { | 910 class BASE_EXPORT TraceEndOnScopeClose { |
779 public: | 911 public: |
780 // Note: members of data_ intentionally left uninitialized. See Initialize. | 912 // Note: members of data_ intentionally left uninitialized. See Initialize. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 Data* p_data_; | 971 Data* p_data_; |
840 Data data_; | 972 Data data_; |
841 }; | 973 }; |
842 | 974 |
843 } // namespace internal | 975 } // namespace internal |
844 | 976 |
845 } // namespace debug | 977 } // namespace debug |
846 } // namespace base | 978 } // namespace base |
847 | 979 |
848 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 980 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
OLD | NEW |