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

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

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