Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1317)

Side by Side Diff: base/debug/trace_event.h

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

Powered by Google App Engine
This is Rietveld 408576698