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

Side by Side Diff: src/tracing/trace-event.h

Issue 1686233002: Add Scoped Context Info (Isolate) to V8 Traces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Simplify the test Created 4 years, 10 months 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
« no previous file with comments | « src/log-inl.h ('k') | test/cctest/test-trace-event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project 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 #ifndef SRC_TRACING_TRACE_EVENT_H_ 5 #ifndef SRC_TRACING_TRACE_EVENT_H_
6 #define SRC_TRACING_TRACE_EVENT_H_ 6 #define SRC_TRACING_TRACE_EVENT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/trace_event/common/trace_event_common.h" 10 #include "base/trace_event/common/trace_event_common.h"
11 #include "include/v8-platform.h" 11 #include "include/v8-platform.h"
12 #include "src/base/atomicops.h" 12 #include "src/base/atomicops.h"
13 #include "src/base/macros.h"
13 14
14 // This header file defines implementation details of how the trace macros in 15 // This header file defines implementation details of how the trace macros in
15 // trace_event_common.h collect and store trace events. Anything not 16 // trace_event_common.h collect and store trace events. Anything not
16 // implementation-specific should go in trace_macros_common.h instead of here. 17 // implementation-specific should go in trace_macros_common.h instead of here.
17 18
18 19
19 // The pointer returned from GetCategoryGroupEnabled() points to a 20 // The pointer returned from GetCategoryGroupEnabled() points to a
20 // value with zero or more of the following bits. Used in this class only. 21 // value with zero or more of the following bits. Used in this class only.
21 // The TRACE_EVENT macros should only use the value as a bool. 22 // The TRACE_EVENT macros should only use the value as a bool.
22 // These values must be in sync with macro values in trace_log.h in 23 // These values must be in sync with macro values in trace_log.h in
(...skipping 12 matching lines...) Expand all
35 #define TRACE_STR_COPY(str) v8::internal::tracing::TraceStringWithCopy(str) 36 #define TRACE_STR_COPY(str) v8::internal::tracing::TraceStringWithCopy(str)
36 37
37 // By default, uint64 ID argument values are not mangled with the Process ID in 38 // By default, uint64 ID argument values are not mangled with the Process ID in
38 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling. 39 // TRACE_EVENT_ASYNC macros. Use this macro to force Process ID mangling.
39 #define TRACE_ID_MANGLE(id) v8::internal::tracing::TraceID::ForceMangle(id) 40 #define TRACE_ID_MANGLE(id) v8::internal::tracing::TraceID::ForceMangle(id)
40 41
41 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC 42 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC
42 // macros. Use this macro to prevent Process ID mangling. 43 // macros. Use this macro to prevent Process ID mangling.
43 #define TRACE_ID_DONT_MANGLE(id) v8::internal::tracing::TraceID::DontMangle(id) 44 #define TRACE_ID_DONT_MANGLE(id) v8::internal::tracing::TraceID::DontMangle(id)
44 45
46 // By default, trace IDs are eventually converted to a single 64-bit number. Use
47 // this macro to add a scope string.
48 #define TRACE_ID_WITH_SCOPE(scope, id) \
49 trace_event_internal::TraceID::WithScope(scope, id)
50
45 // Sets the current sample state to the given category and name (both must be 51 // Sets the current sample state to the given category and name (both must be
46 // constant strings). These states are intended for a sampling profiler. 52 // constant strings). These states are intended for a sampling profiler.
47 // Implementation note: we store category and name together because we don't 53 // Implementation note: we store category and name together because we don't
48 // want the inconsistency/expense of storing two pointers. 54 // want the inconsistency/expense of storing two pointers.
49 // |thread_bucket| is [0..2] and is used to statically isolate samples in one 55 // |thread_bucket| is [0..2] and is used to statically isolate samples in one
50 // thread from others. 56 // thread from others.
51 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(bucket_number, category, \ 57 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(bucket_number, category, \
52 name) \ 58 name) \
53 v8::internal::tracing::TraceEventSamplingStateScope<bucket_number>::Set( \ 59 v8::internal::tracing::TraceEventSamplingStateScope<bucket_number>::Set( \
54 category "\0" name) 60 category "\0" name)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // Get the number of times traces have been recorded. This is used to implement 105 // Get the number of times traces have been recorded. This is used to implement
100 // the TRACE_EVENT_IS_NEW_TRACE facility. 106 // the TRACE_EVENT_IS_NEW_TRACE facility.
101 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED() 107 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED()
102 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED UNIMPLEMENTED() 108 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED UNIMPLEMENTED()
103 109
104 // Add a trace event to the platform tracing system. 110 // Add a trace event to the platform tracing system.
105 // uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT( 111 // uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT(
106 // char phase, 112 // char phase,
107 // const uint8_t* category_group_enabled, 113 // const uint8_t* category_group_enabled,
108 // const char* name, 114 // const char* name,
115 // const char* scope,
109 // uint64_t id, 116 // uint64_t id,
110 // uint64_t bind_id, 117 // uint64_t bind_id,
111 // int num_args, 118 // int num_args,
112 // const char** arg_names, 119 // const char** arg_names,
113 // const uint8_t* arg_types, 120 // const uint8_t* arg_types,
114 // const uint64_t* arg_values, 121 // const uint64_t* arg_values,
115 // unsigned int flags) 122 // unsigned int flags)
116 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ 123 #define TRACE_EVENT_API_ADD_TRACE_EVENT \
117 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform()->AddTraceEvent 124 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform()->AddTraceEvent
118 125
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 INTERNAL_TRACE_EVENT_UID(category_group_enabled)); 181 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
175 182
176 // Implementation detail: internal macro to create static category and add 183 // Implementation detail: internal macro to create static category and add
177 // event if the category is enabled. 184 // event if the category is enabled.
178 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \ 185 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
179 do { \ 186 do { \
180 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 187 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
181 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 188 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
182 v8::internal::tracing::AddTraceEvent( \ 189 v8::internal::tracing::AddTraceEvent( \
183 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 190 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
184 v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, flags, \ 191 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
185 ##__VA_ARGS__); \ 192 v8::internal::tracing::kNoId, flags, ##__VA_ARGS__); \
186 } \ 193 } \
187 } while (0) 194 } while (0)
188 195
189 // Implementation detail: internal macro to create static category and add begin 196 // Implementation detail: internal macro to create static category and add begin
190 // event if the category is enabled. Also adds the end event when the scope 197 // event if the category is enabled. Also adds the end event when the scope
191 // ends. 198 // ends.
192 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \ 199 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
193 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 200 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
194 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 201 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
195 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 202 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
196 uint64_t h = v8::internal::tracing::AddTraceEvent( \ 203 uint64_t h = v8::internal::tracing::AddTraceEvent( \
197 TRACE_EVENT_PHASE_COMPLETE, \ 204 TRACE_EVENT_PHASE_COMPLETE, \
198 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 205 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
199 v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, \ 206 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
200 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \ 207 v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
201 INTERNAL_TRACE_EVENT_UID(tracer) \ 208 INTERNAL_TRACE_EVENT_UID(tracer) \
202 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 209 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
203 h); \ 210 h); \
204 } 211 }
205 212
206 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \ 213 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \
207 bind_id, flow_flags, ...) \ 214 bind_id, flow_flags, ...) \
208 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 215 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
209 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \ 216 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
210 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 217 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
211 unsigned int trace_event_flags = flow_flags; \ 218 unsigned int trace_event_flags = flow_flags; \
212 v8::internal::tracing::TraceID trace_event_bind_id(bind_id, \ 219 v8::internal::tracing::TraceID trace_event_bind_id(bind_id, \
213 &trace_event_flags); \ 220 &trace_event_flags); \
214 uint64_t h = v8::internal::tracing::AddTraceEvent( \ 221 uint64_t h = v8::internal::tracing::AddTraceEvent( \
215 TRACE_EVENT_PHASE_COMPLETE, \ 222 TRACE_EVENT_PHASE_COMPLETE, \
216 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 223 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
217 v8::internal::tracing::kNoId, trace_event_bind_id.data(), \ 224 v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
218 trace_event_flags, ##__VA_ARGS__); \ 225 trace_event_bind_id.raw_id(), trace_event_flags, ##__VA_ARGS__); \
219 INTERNAL_TRACE_EVENT_UID(tracer) \ 226 INTERNAL_TRACE_EVENT_UID(tracer) \
220 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 227 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
221 h); \ 228 h); \
222 } 229 }
223 230
224 // Implementation detail: internal macro to create static category and add 231 // Implementation detail: internal macro to create static category and add
225 // event if the category is enabled. 232 // event if the category is enabled.
226 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \ 233 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
227 flags, ...) \ 234 flags, ...) \
228 do { \ 235 do { \
229 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \ 236 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
230 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \ 237 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
231 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \ 238 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
232 v8::internal::tracing::TraceID trace_event_trace_id(id, \ 239 v8::internal::tracing::TraceID trace_event_trace_id(id, \
233 &trace_event_flags); \ 240 &trace_event_flags); \
234 v8::internal::tracing::AddTraceEvent( \ 241 v8::internal::tracing::AddTraceEvent( \
235 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \ 242 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
236 trace_event_trace_id.data(), v8::internal::tracing::kNoId, \ 243 trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \
237 trace_event_flags, ##__VA_ARGS__); \ 244 v8::internal::tracing::kNoId, trace_event_flags, ##__VA_ARGS__); \
238 } \ 245 } \
239 } while (0) 246 } while (0)
240 247
241 // Adds a trace event with a given timestamp. Not Implemented. 248 // Adds a trace event with a given timestamp. Not Implemented.
242 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \ 249 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \
243 timestamp, flags, ...) \ 250 timestamp, flags, ...) \
244 UNIMPLEMENTED() 251 UNIMPLEMENTED()
245 252
246 // Adds a trace event with a given id and timestamp. Not Implemented. 253 // Adds a trace event with a given id and timestamp. Not Implemented.
247 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \ 254 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
248 phase, category_group, name, id, timestamp, flags, ...) \ 255 phase, category_group, name, id, timestamp, flags, ...) \
249 UNIMPLEMENTED() 256 UNIMPLEMENTED()
250 257
251 // Adds a trace event with a given id, thread_id, and timestamp. Not 258 // Adds a trace event with a given id, thread_id, and timestamp. Not
252 // Implemented. 259 // Implemented.
253 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \ 260 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
254 phase, category_group, name, id, thread_id, timestamp, flags, ...) \ 261 phase, category_group, name, id, thread_id, timestamp, flags, ...) \
255 UNIMPLEMENTED() 262 UNIMPLEMENTED()
256 263
264 // Enter and leave a context based on the current scope.
265 #define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
266 struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \
267 public: \
268 INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \
269 TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \
270 } \
271 ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \
272 TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \
273 } \
274 \
275 private: \
276 /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \
277 INTERNAL_TRACE_EVENT_UID(ScopedContext) \
278 (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \
279 void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \
280 uint64_t cid_; \
281 }; \
282 INTERNAL_TRACE_EVENT_UID(ScopedContext) \
283 INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id());
284
257 namespace v8 { 285 namespace v8 {
258 namespace internal { 286 namespace internal {
259 namespace tracing { 287 namespace tracing {
260 288
261 // Specify these values when the corresponding argument of AddTraceEvent is not 289 // Specify these values when the corresponding argument of AddTraceEvent is not
262 // used. 290 // used.
263 const int kZeroNumArgs = 0; 291 const int kZeroNumArgs = 0;
292 const decltype(nullptr) kGlobalScope = nullptr;
264 const uint64_t kNoId = 0; 293 const uint64_t kNoId = 0;
265 294
266 class TraceEventHelper { 295 class TraceEventHelper {
267 public: 296 public:
268 static v8::Platform* GetCurrentPlatform(); 297 static v8::Platform* GetCurrentPlatform();
269 }; 298 };
270 299
271 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers 300 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers
272 // are by default mangled with the Process ID so that they are unlikely to 301 // are by default mangled with the Process ID so that they are unlikely to
273 // collide when the same pointer is used on different processes. 302 // collide when the same pointer is used on different processes.
274 class TraceID { 303 class TraceID {
275 public: 304 public:
305 class WithScope {
306 public:
307 WithScope(const char* scope, uint64_t raw_id)
308 : scope_(scope), raw_id_(raw_id) {}
309 uint64_t raw_id() const { return raw_id_; }
310 const char* scope() const { return scope_; }
311
312 private:
313 const char* scope_ = nullptr;
314 uint64_t raw_id_;
315 };
316
276 class DontMangle { 317 class DontMangle {
277 public: 318 public:
278 explicit DontMangle(const void* id) 319 explicit DontMangle(const void* raw_id)
279 : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {} 320 : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {}
280 explicit DontMangle(uint64_t id) : data_(id) {} 321 explicit DontMangle(uint64_t raw_id) : raw_id_(raw_id) {}
281 explicit DontMangle(unsigned int id) : data_(id) {} 322 explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {}
282 explicit DontMangle(uint16_t id) : data_(id) {} 323 explicit DontMangle(uint16_t raw_id) : raw_id_(raw_id) {}
283 explicit DontMangle(unsigned char id) : data_(id) {} 324 explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {}
284 explicit DontMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {} 325 explicit DontMangle(int64_t raw_id)
285 explicit DontMangle(int id) : data_(static_cast<uint64_t>(id)) {} 326 : raw_id_(static_cast<uint64_t>(raw_id)) {}
286 explicit DontMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {} 327 explicit DontMangle(int raw_id) : raw_id_(static_cast<uint64_t>(raw_id)) {}
287 explicit DontMangle(signed char id) : data_(static_cast<uint64_t>(id)) {} 328 explicit DontMangle(int16_t raw_id)
288 uint64_t data() const { return data_; } 329 : raw_id_(static_cast<uint64_t>(raw_id)) {}
330 explicit DontMangle(signed char raw_id)
331 : raw_id_(static_cast<uint64_t>(raw_id)) {}
332 explicit DontMangle(WithScope scoped_id)
333 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {}
334 const char* scope() const { return scope_; }
335 uint64_t raw_id() const { return raw_id_; }
289 336
290 private: 337 private:
291 uint64_t data_; 338 const char* scope_ = nullptr;
339 uint64_t raw_id_;
292 }; 340 };
293 341
294 class ForceMangle { 342 class ForceMangle {
295 public: 343 public:
296 explicit ForceMangle(uint64_t id) : data_(id) {} 344 explicit ForceMangle(uint64_t raw_id) : raw_id_(raw_id) {}
297 explicit ForceMangle(unsigned int id) : data_(id) {} 345 explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {}
298 explicit ForceMangle(uint16_t id) : data_(id) {} 346 explicit ForceMangle(uint16_t raw_id) : raw_id_(raw_id) {}
299 explicit ForceMangle(unsigned char id) : data_(id) {} 347 explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {}
300 explicit ForceMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {} 348 explicit ForceMangle(int64_t raw_id)
301 explicit ForceMangle(int id) : data_(static_cast<uint64_t>(id)) {} 349 : raw_id_(static_cast<uint64_t>(raw_id)) {}
302 explicit ForceMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {} 350 explicit ForceMangle(int raw_id) : raw_id_(static_cast<uint64_t>(raw_id)) {}
303 explicit ForceMangle(signed char id) : data_(static_cast<uint64_t>(id)) {} 351 explicit ForceMangle(int16_t raw_id)
304 uint64_t data() const { return data_; } 352 : raw_id_(static_cast<uint64_t>(raw_id)) {}
353 explicit ForceMangle(signed char raw_id)
354 : raw_id_(static_cast<uint64_t>(raw_id)) {}
355 uint64_t raw_id() const { return raw_id_; }
305 356
306 private: 357 private:
307 uint64_t data_; 358 uint64_t raw_id_;
308 }; 359 };
309 360
310 TraceID(const void* id, unsigned int* flags) 361 TraceID(const void* raw_id, unsigned int* flags)
311 : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) { 362 : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {
312 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; 363 *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
313 } 364 }
314 TraceID(ForceMangle id, unsigned int* flags) : data_(id.data()) { 365 TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) {
315 *flags |= TRACE_EVENT_FLAG_MANGLE_ID; 366 *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
316 } 367 }
317 TraceID(DontMangle id, unsigned int* flags) : data_(id.data()) {} 368 TraceID(DontMangle maybe_scoped_id, unsigned int* flags)
318 TraceID(uint64_t id, unsigned int* flags) : data_(id) { (void)flags; } 369 : scope_(maybe_scoped_id.scope()), raw_id_(maybe_scoped_id.raw_id()) {}
319 TraceID(unsigned int id, unsigned int* flags) : data_(id) { (void)flags; } 370 TraceID(uint64_t raw_id, unsigned int* flags) : raw_id_(raw_id) {
320 TraceID(uint16_t id, unsigned int* flags) : data_(id) { (void)flags; }
321 TraceID(unsigned char id, unsigned int* flags) : data_(id) { (void)flags; }
322 TraceID(int64_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
323 (void)flags; 371 (void)flags;
324 } 372 }
325 TraceID(int id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) { 373 TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) {
326 (void)flags; 374 (void)flags;
327 } 375 }
328 TraceID(int16_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) { 376 TraceID(uint16_t raw_id, unsigned int* flags) : raw_id_(raw_id) {
329 (void)flags; 377 (void)flags;
330 } 378 }
331 TraceID(signed char id, unsigned int* flags) 379 TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) {
332 : data_(static_cast<uint64_t>(id)) {
333 (void)flags; 380 (void)flags;
334 } 381 }
382 TraceID(int64_t raw_id, unsigned int* flags)
383 : raw_id_(static_cast<uint64_t>(raw_id)) {
384 (void)flags;
385 }
386 TraceID(int raw_id, unsigned int* flags)
387 : raw_id_(static_cast<uint64_t>(raw_id)) {
388 (void)flags;
389 }
390 TraceID(int16_t raw_id, unsigned int* flags)
391 : raw_id_(static_cast<uint64_t>(raw_id)) {
392 (void)flags;
393 }
394 TraceID(signed char raw_id, unsigned int* flags)
395 : raw_id_(static_cast<uint64_t>(raw_id)) {
396 (void)flags;
397 }
398 TraceID(WithScope scoped_id, unsigned int* flags)
399 : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {}
335 400
336 uint64_t data() const { return data_; } 401 uint64_t raw_id() const { return raw_id_; }
402 const char* scope() const { return scope_; }
337 403
338 private: 404 private:
339 uint64_t data_; 405 const char* scope_ = nullptr;
406 uint64_t raw_id_;
340 }; 407 };
341 408
342 // Simple union to store various types as uint64_t. 409 // Simple union to store various types as uint64_t.
343 union TraceValueUnion { 410 union TraceValueUnion {
344 bool as_bool; 411 bool as_bool;
345 uint64_t as_uint; 412 uint64_t as_uint;
346 int64_t as_int; 413 int64_t as_int;
347 double as_double; 414 double as_double;
348 const void* as_pointer; 415 const void* as_pointer;
349 const char* as_string; 416 const char* as_string;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT 467 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT
401 468
402 // These AddTraceEvent template 469 // These AddTraceEvent template
403 // function is defined here instead of in the macro, because the arg_values 470 // function is defined here instead of in the macro, because the arg_values
404 // could be temporary objects, such as std::string. In order to store 471 // could be temporary objects, such as std::string. In order to store
405 // pointers to the internal c_str and pass through to the tracing API, 472 // pointers to the internal c_str and pass through to the tracing API,
406 // the arg_values must live throughout these procedures. 473 // the arg_values must live throughout these procedures.
407 474
408 static V8_INLINE uint64_t AddTraceEvent(char phase, 475 static V8_INLINE uint64_t AddTraceEvent(char phase,
409 const uint8_t* category_group_enabled, 476 const uint8_t* category_group_enabled,
410 const char* name, uint64_t id, 477 const char* name, const char* scope,
411 uint64_t bind_id, unsigned int flags) { 478 uint64_t id, uint64_t bind_id,
479 unsigned int flags) {
412 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, 480 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
413 id, bind_id, kZeroNumArgs, NULL, NULL, 481 scope, id, bind_id, kZeroNumArgs, NULL,
414 NULL, flags); 482 NULL, NULL, flags);
415 } 483 }
416 484
417 template <class ARG1_TYPE> 485 template <class ARG1_TYPE>
418 static V8_INLINE uint64_t AddTraceEvent(char phase, 486 static V8_INLINE uint64_t AddTraceEvent(
419 const uint8_t* category_group_enabled, 487 char phase, const uint8_t* category_group_enabled, const char* name,
420 const char* name, uint64_t id, 488 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
421 uint64_t bind_id, unsigned int flags, 489 const char* arg1_name, const ARG1_TYPE& arg1_val) {
422 const char* arg1_name,
423 const ARG1_TYPE& arg1_val) {
424 const int num_args = 1; 490 const int num_args = 1;
425 uint8_t arg_types[1]; 491 uint8_t arg_types[1];
426 uint64_t arg_values[1]; 492 uint64_t arg_values[1];
427 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 493 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
428 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, 494 return TRACE_EVENT_API_ADD_TRACE_EVENT(
429 id, bind_id, num_args, &arg1_name, 495 phase, category_group_enabled, name, scope, id, bind_id, num_args,
430 arg_types, arg_values, flags); 496 &arg1_name, arg_types, arg_values, flags);
431 } 497 }
432 498
433 template <class ARG1_TYPE, class ARG2_TYPE> 499 template <class ARG1_TYPE, class ARG2_TYPE>
434 static V8_INLINE uint64_t AddTraceEvent( 500 static V8_INLINE uint64_t AddTraceEvent(
435 char phase, const uint8_t* category_group_enabled, const char* name, 501 char phase, const uint8_t* category_group_enabled, const char* name,
436 uint64_t id, uint64_t bind_id, unsigned int flags, const char* arg1_name, 502 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
437 const ARG1_TYPE& arg1_val, const char* arg2_name, 503 const char* arg1_name, const ARG1_TYPE& arg1_val, const char* arg2_name,
438 const ARG2_TYPE& arg2_val) { 504 const ARG2_TYPE& arg2_val) {
439 const int num_args = 2; 505 const int num_args = 2;
440 const char* arg_names[2] = {arg1_name, arg2_name}; 506 const char* arg_names[2] = {arg1_name, arg2_name};
441 unsigned char arg_types[2]; 507 unsigned char arg_types[2];
442 uint64_t arg_values[2]; 508 uint64_t arg_values[2];
443 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 509 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
444 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 510 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
445 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, 511 return TRACE_EVENT_API_ADD_TRACE_EVENT(
446 id, bind_id, num_args, arg_names, 512 phase, category_group_enabled, name, scope, id, bind_id, num_args,
447 arg_types, arg_values, flags); 513 arg_names, arg_types, arg_values, flags);
448 } 514 }
449 515
450 // Used by TRACE_EVENTx macros. Do not use directly. 516 // Used by TRACE_EVENTx macros. Do not use directly.
451 class ScopedTracer { 517 class ScopedTracer {
452 public: 518 public:
453 // Note: members of data_ intentionally left uninitialized. See Initialize. 519 // Note: members of data_ intentionally left uninitialized. See Initialize.
454 ScopedTracer() : p_data_(NULL) {} 520 ScopedTracer() : p_data_(NULL) {}
455 521
456 ~ScopedTracer() { 522 ~ScopedTracer() {
457 if (p_data_ && *data_.category_group_enabled) 523 if (p_data_ && *data_.category_group_enabled)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 588
523 private: 589 private:
524 const char* previous_state_; 590 const char* previous_state_;
525 }; 591 };
526 592
527 } // namespace tracing 593 } // namespace tracing
528 } // namespace internal 594 } // namespace internal
529 } // namespace v8 595 } // namespace v8
530 596
531 #endif // SRC_TRACING_TRACE_EVENT_H_ 597 #endif // SRC_TRACING_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « src/log-inl.h ('k') | test/cctest/test-trace-event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698