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

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

Issue 988893003: Implement tracing interface for v8 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove trace-event-common.h and use DEPs instead, remove src/v8.h from trace-event.h, file a bug fo… Created 5 years, 1 month 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef SRC_TRACING_TRACE_EVENT_H_
6 #define SRC_TRACING_TRACE_EVENT_H_
7
8 #include "include/v8-platform.h"
9 #include "src/base/atomicops.h"
10 #include "src/tracing/common/trace_event_common.h"
11
12 // This header file defines implementation details of how the trace macros in
13 // trace_event_common.h collect and store trace events. Anything not
14 // implementation-specific should go in trace_macros_common.h instead of here.
15
16
17 // The pointer returned from GetCategoryGroupEnabled() points to a
18 // value with zero or more of the following bits. Used in this class only.
19 // The TRACE_EVENT macros should only use the value as a bool.
20 // These values must be in sync with macro values in trace_log.h in
21 // chromium.
22 enum CategoryGroupEnabledFlags {
23 // Category group enabled for the recording mode.
24 kEnabledForRecording_CategoryGroupEnabledFlags = 1 << 0,
25 // Category group enabled for the monitoring mode.
26 kEnabledForMonitoring_CategoryGroupEnabledFlags = 1 << 1,
27 // Category group enabled by SetEventCallbackEnabled().
28 kEnabledForEventCallback_CategoryGroupEnabledFlags = 1 << 2,
29 // Category group enabled to export events to ETW.
30 kEnabledForETWExport_CategoryGroupEnabledFlags = 1 << 3,
31 };
32
33 // By default, const char* asrgument values are assumed to have long-lived scope
34 // and will not be copied. Use this macro to force a const char* to be copied.
35 #define TRACE_STR_COPY(str) v8::internal::tracing::TraceStringWithCopy(str)
36
37 // 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 #define TRACE_ID_MANGLE(id) v8::internal::tracing::TraceID::ForceMangle(id)
40
41 // By default, pointers are mangled with the Process ID in TRACE_EVENT_ASYNC
42 // macros. Use this macro to prevent Process ID mangling.
43 #define TRACE_ID_DONT_MANGLE(id) v8::internal::tracing::TraceID::DontMangle(id)
44
45 // 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.
47 // Implementation note: we store category and name together because we don't
48 // want the inconsistency/expense of storing two pointers.
49 // |thread_bucket| is [0..2] and is used to statically isolate samples in one
50 // thread from others.
51 #define TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(bucket_number, category, \
52 name) \
53 v8::internal::tracing::TraceEventSamplingStateScope<bucket_number>::Set( \
54 category "\0" name)
55
56 // Returns a current sampling state of the given bucket.
57 #define TRACE_EVENT_GET_SAMPLING_STATE_FOR_BUCKET(bucket_number) \
58 v8::internal::tracing::TraceEventSamplingStateScope<bucket_number>::Current()
59
60 // Creates a scope of a sampling state of the given bucket.
61 //
62 // { // The sampling state is set within this scope.
63 // TRACE_EVENT_SAMPLING_STATE_SCOPE_FOR_BUCKET(0, "category", "name");
64 // ...;
65 // }
66 #define TRACE_EVENT_SCOPED_SAMPLING_STATE_FOR_BUCKET(bucket_number, category, \
67 name) \
68 v8::internal::TraceEventSamplingStateScope<bucket_number> \
69 traceEventSamplingScope(category "\0" name);
70
71
72 #define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE() \
73 *INTERNAL_TRACE_EVENT_UID(category_group_enabled) & \
74 (kEnabledForRecording_CategoryGroupEnabledFlags | \
75 kEnabledForEventCallback_CategoryGroupEnabledFlags)
76
77 // The following macro has no implementation, but it needs to exist since
78 // it gets called from scoped trace events. It cannot call UNIMPLEMENTED()
79 // since an empty implementation is a valid one.
80 #define INTERNAL_TRACE_MEMORY(category, name)
81
82 ////////////////////////////////////////////////////////////////////////////////
83 // Implementation specific tracing API definitions.
84
85 // Get a pointer to the enabled state of the given trace category. Only
86 // long-lived literal strings should be given as the category group. The
87 // returned pointer can be held permanently in a local static for example. If
88 // the unsigned char is non-zero, tracing is enabled. If tracing is enabled,
89 // TRACE_EVENT_API_ADD_TRACE_EVENT can be called. It's OK if tracing is disabled
90 // between the load of the tracing state and the call to
91 // TRACE_EVENT_API_ADD_TRACE_EVENT, because this flag only provides an early out
92 // for best performance when tracing is disabled.
93 // const uint8_t*
94 // TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
95 #define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
96 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
97 ->GetCategoryGroupEnabled
98
99 // Get the number of times traces have been recorded. This is used to implement
100 // the TRACE_EVENT_IS_NEW_TRACE facility.
101 // unsigned int TRACE_EVENT_API_GET_NUM_TRACES_RECORDED()
102 #define TRACE_EVENT_API_GET_NUM_TRACES_RECORDED \
103 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
104 ->getNumTracesRecorded
105
106 // Add a trace event to the platform tracing system.
107 // uint64_t TRACE_EVENT_API_ADD_TRACE_EVENT(
108 // char phase,
109 // const uint8_t* category_group_enabled,
110 // const char* name,
111 // uint64_t id,
112 // uint64_t bind_id,
113 // int num_args,
114 // const char** arg_names,
115 // const uint8_t* arg_types,
116 // const uint64_t* arg_values,
117 // unsigned int flags)
118 #define TRACE_EVENT_API_ADD_TRACE_EVENT \
119 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform()->AddTraceEvent
120
121 // Set the duration field of a COMPLETE trace event.
122 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
123 // const uint8_t* category_group_enabled,
124 // const char* name,
125 // uint64_t id)
126 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
127 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \
128 ->UpdateTraceEventDuration
129
130 // Defines atomic operations used internally by the tracing system.
131 #define TRACE_EVENT_API_ATOMIC_WORD v8::base::AtomicWord
132 #define TRACE_EVENT_API_ATOMIC_LOAD(var) v8::base::NoBarrier_Load(&(var))
133 #define TRACE_EVENT_API_ATOMIC_STORE(var, value) \
134 v8::base::NoBarrier_Store(&(var), (value))
135
136 // The thread buckets for the sampling profiler.
137 extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
138
139 #define TRACE_EVENT_API_THREAD_BUCKET(thread_bucket) \
140 g_trace_state[thread_bucket]
141
142 ////////////////////////////////////////////////////////////////////////////////
143
144 // Implementation detail: trace event macros create temporary variables
145 // to keep instrumentation overhead low. These macros give each temporary
146 // variable a unique name based on the line number to prevent name collisions.
147 #define INTERNAL_TRACE_EVENT_UID3(a, b) trace_event_unique_##a##b
148 #define INTERNAL_TRACE_EVENT_UID2(a, b) INTERNAL_TRACE_EVENT_UID3(a, b)
149 #define INTERNAL_TRACE_EVENT_UID(name_prefix) \
150 INTERNAL_TRACE_EVENT_UID2(name_prefix, __LINE__)
151
152 // Implementation detail: internal macro to create static category.
153 // No barriers are needed, because this code is designed to operate safely
154 // even when the unsigned char* points to garbage data (which may be the case
155 // on processors without cache coherency).
156 // TODO(fmeawad): This implementation contradicts that we can have a different
157 // configuration for each isolate,
158 // https://code.google.com/p/v8/issues/detail?id=4563
159 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
160 category_group, atomic, category_group_enabled) \
161 category_group_enabled = \
162 reinterpret_cast<const uint8_t*>(TRACE_EVENT_API_ATOMIC_LOAD(atomic)); \
163 if (!category_group_enabled) { \
164 category_group_enabled = \
165 TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); \
166 TRACE_EVENT_API_ATOMIC_STORE( \
167 atomic, reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>( \
168 category_group_enabled)); \
169 }
170
171 #define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group) \
172 static TRACE_EVENT_API_ATOMIC_WORD INTERNAL_TRACE_EVENT_UID(atomic) = 0; \
173 const uint8_t* INTERNAL_TRACE_EVENT_UID(category_group_enabled); \
174 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( \
175 category_group, INTERNAL_TRACE_EVENT_UID(atomic), \
176 INTERNAL_TRACE_EVENT_UID(category_group_enabled));
177
178 // Implementation detail: internal macro to create static category and add
179 // event if the category is enabled.
180 #define INTERNAL_TRACE_EVENT_ADD(phase, category_group, name, flags, ...) \
181 do { \
182 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
183 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
184 v8::internal::tracing::AddTraceEvent( \
185 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
186 v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, flags, \
187 ##__VA_ARGS__); \
188 } \
189 } while (0)
190
191 // Implementation detail: internal macro to create static category and add begin
192 // event if the category is enabled. Also adds the end event when the scope
193 // ends.
194 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
195 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
196 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
197 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
198 uint64_t h = v8::internal::tracing::AddTraceEvent( \
199 TRACE_EVENT_PHASE_COMPLETE, \
200 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
201 v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, \
202 TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
203 INTERNAL_TRACE_EVENT_UID(tracer) \
204 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
205 h); \
206 }
207
208 #define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \
209 bind_id, flow_flags, ...) \
210 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
211 v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
212 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
213 unsigned int trace_event_flags = flow_flags; \
214 v8::internal::tracing::TraceID trace_event_bind_id(bind_id, \
215 &trace_event_flags); \
216 uint64_t h = v8::internal::tracing::AddTraceEvent( \
217 TRACE_EVENT_PHASE_COMPLETE, \
218 INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
219 v8::internal::tracing::kNoId, trace_event_bind_id.data(), \
220 trace_event_flags, ##__VA_ARGS__); \
221 INTERNAL_TRACE_EVENT_UID(tracer) \
222 .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
223 h); \
224 }
225
226 // Implementation detail: internal macro to create static category and add
227 // event if the category is enabled.
228 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID(phase, category_group, name, id, \
229 flags, ...) \
230 do { \
231 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
232 if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
233 unsigned int trace_event_flags = flags | TRACE_EVENT_FLAG_HAS_ID; \
234 v8::internal::tracing::TraceID trace_event_trace_id(id, \
235 &trace_event_flags); \
236 v8::internal::tracing::AddTraceEvent( \
237 phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
238 trace_event_trace_id.data(), v8::internal::tracing::kNoId, \
239 trace_event_flags, ##__VA_ARGS__); \
240 } \
241 } while (0)
242
243 // Adds a trace event with a given timestamp. Not Implemented.
244 #define INTERNAL_TRACE_EVENT_ADD_WITH_TIMESTAMP(phase, category_group, name, \
245 timestamp, flags, ...) \
246 UNIMPLEMENTED()
247
248 // Adds a trace event with a given id and timestamp. Not Implemented.
249 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_AND_TIMESTAMP( \
250 phase, category_group, name, id, timestamp, flags, ...) \
251 UNIMPLEMENTED()
252
253 // Adds a trace event with a given id, thread_id, and timestamp. Not
254 // Implemented.
255 #define INTERNAL_TRACE_EVENT_ADD_WITH_ID_TID_AND_TIMESTAMP( \
256 phase, category_group, name, id, thread_id, timestamp, flags, ...) \
257 UNIMPLEMENTED()
258
259 namespace v8 {
260 namespace internal {
261 namespace tracing {
262
263 // Specify these values when the corresponding argument of AddTraceEvent is not
264 // used.
265 const int kZeroNumArgs = 0;
266 const uint64_t kNoId = 0;
267
268 class TraceEventHelper {
269 public:
270 static v8::Platform* GetCurrentPlatform();
271 };
272
273 // TraceID encapsulates an ID that can either be an integer or pointer. Pointers
274 // are by default mangled with the Process ID so that they are unlikely to
275 // collide when the same pointer is used on different processes.
276 class TraceID {
Yang 2015/11/19 09:30:32 Is this ID used to represent the isolate? If yes,
fmeawad 2015/11/20 22:22:20 DontMangle is used by the TRACE_EVENT_OBJECT_* mac
277 public:
278 class DontMangle {
279 public:
280 explicit DontMangle(const void* id)
281 : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {}
282 explicit DontMangle(uint64_t id) : data_(id) {}
283 explicit DontMangle(unsigned int id) : data_(id) {}
284 explicit DontMangle(uint16_t id) : data_(id) {}
285 explicit DontMangle(unsigned char id) : data_(id) {}
286 explicit DontMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {}
287 explicit DontMangle(int id) : data_(static_cast<uint64_t>(id)) {}
288 explicit DontMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {}
289 explicit DontMangle(signed char id) : data_(static_cast<uint64_t>(id)) {}
290 uint64_t data() const { return data_; }
291
292 private:
293 uint64_t data_;
294 };
295
296 class ForceMangle {
297 public:
298 explicit ForceMangle(uint64_t id) : data_(id) {}
299 explicit ForceMangle(unsigned int id) : data_(id) {}
300 explicit ForceMangle(uint16_t id) : data_(id) {}
301 explicit ForceMangle(unsigned char id) : data_(id) {}
302 explicit ForceMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {}
303 explicit ForceMangle(int id) : data_(static_cast<uint64_t>(id)) {}
304 explicit ForceMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {}
305 explicit ForceMangle(signed char id) : data_(static_cast<uint64_t>(id)) {}
306 uint64_t data() const { return data_; }
307
308 private:
309 uint64_t data_;
310 };
311
312 TraceID(const void* id, unsigned int* flags)
313 : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {
314 *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
315 }
316 TraceID(ForceMangle id, unsigned int* flags) : data_(id.data()) {
317 *flags |= TRACE_EVENT_FLAG_MANGLE_ID;
318 }
319 TraceID(DontMangle id, unsigned int* flags) : data_(id.data()) {}
320 TraceID(uint64_t id, unsigned int* flags) : data_(id) { (void)flags; }
321 TraceID(unsigned int id, unsigned int* flags) : data_(id) { (void)flags; }
322 TraceID(uint16_t id, unsigned int* flags) : data_(id) { (void)flags; }
323 TraceID(unsigned char id, unsigned int* flags) : data_(id) { (void)flags; }
324 TraceID(int64_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
325 (void)flags;
326 }
327 TraceID(int id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
328 (void)flags;
329 }
330 TraceID(int16_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
331 (void)flags;
332 }
333 TraceID(signed char id, unsigned int* flags)
334 : data_(static_cast<uint64_t>(id)) {
335 (void)flags;
336 }
337
338 uint64_t data() const { return data_; }
339
340 private:
341 uint64_t data_;
342 };
343
344 // Simple union to store various types as uint64_t.
345 union TraceValueUnion {
346 bool as_bool;
347 uint64_t as_uint;
348 int64_t as_int;
349 double as_double;
350 const void* as_pointer;
351 const char* as_string;
352 };
353
354 // Simple container for const char* that should be copied instead of retained.
355 class TraceStringWithCopy {
356 public:
357 explicit TraceStringWithCopy(const char* str) : str_(str) {}
358 operator const char*() const { return str_; }
359
360 private:
361 const char* str_;
362 };
363
364 // Define SetTraceValue for each allowed type. It stores the type and
365 // value in the return arguments. This allows this API to avoid declaring any
366 // structures so that it is portable to third_party libraries.
367 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \
368 value_type_id) \
369 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \
370 uint64_t* value) { \
371 TraceValueUnion type_value; \
372 type_value.union_member = arg; \
373 *type = value_type_id; \
374 *value = type_value.as_uint; \
375 }
376 // Simpler form for int types that can be safely casted.
377 #define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \
378 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \
379 uint64_t* value) { \
380 *type = value_type_id; \
381 *value = static_cast<uint64_t>(arg); \
382 }
383
384 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint64_t, TRACE_VALUE_TYPE_UINT)
385 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT)
386 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(uint16_t, TRACE_VALUE_TYPE_UINT)
387 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT)
388 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int64_t, TRACE_VALUE_TYPE_INT)
389 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT)
390 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int16_t, TRACE_VALUE_TYPE_INT)
391 INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT)
392 INTERNAL_DECLARE_SET_TRACE_VALUE(bool, as_bool, TRACE_VALUE_TYPE_BOOL)
393 INTERNAL_DECLARE_SET_TRACE_VALUE(double, as_double, TRACE_VALUE_TYPE_DOUBLE)
394 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer,
395 TRACE_VALUE_TYPE_POINTER)
396 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string,
397 TRACE_VALUE_TYPE_STRING)
398 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string,
399 TRACE_VALUE_TYPE_COPY_STRING)
400
401 #undef INTERNAL_DECLARE_SET_TRACE_VALUE
402 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT
403
404 // These AddTraceEvent template
405 // function is defined here instead of in the macro, because the arg_values
406 // could be temporary objects, such as std::string. In order to store
407 // pointers to the internal c_str and pass through to the tracing API,
408 // the arg_values must live throughout these procedures.
409
410 static V8_INLINE uint64_t AddTraceEvent(char phase,
411 const uint8_t* category_group_enabled,
412 const char* name, uint64_t id,
413 uint64_t bind_id, unsigned int flags) {
414 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
415 id, bind_id, kZeroNumArgs, NULL, NULL,
416 NULL, flags);
417 }
418
419 template <class ARG1_TYPE>
420 static V8_INLINE uint64_t AddTraceEvent(char phase,
421 const uint8_t* category_group_enabled,
422 const char* name, uint64_t id,
423 uint64_t bind_id, unsigned int flags,
424 const char* arg1_name,
425 const ARG1_TYPE& arg1_val) {
426 const int num_args = 1;
427 uint8_t arg_types[1];
428 uint64_t arg_values[1];
429 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
430 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
431 id, bind_id, num_args, &arg1_name,
432 arg_types, arg_values, flags);
433 }
434
435 template <class ARG1_TYPE, class ARG2_TYPE>
436 static V8_INLINE uint64_t AddTraceEvent(
437 char phase, const uint8_t* category_group_enabled, const char* name,
438 uint64_t id, uint64_t bind_id, unsigned int flags, const char* arg1_name,
439 const ARG1_TYPE& arg1_val, const char* arg2_name,
440 const ARG2_TYPE& arg2_val) {
441 const int num_args = 2;
442 const char* arg_names[2] = {arg1_name, arg2_name};
443 unsigned char arg_types[2];
444 uint64_t arg_values[2];
445 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
446 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
447 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
448 id, bind_id, num_args, arg_names,
449 arg_types, arg_values, flags);
450 }
451
452 // Used by TRACE_EVENTx macros. Do not use directly.
453 class ScopedTracer {
454 public:
455 // Note: members of data_ intentionally left uninitialized. See Initialize.
456 ScopedTracer() : p_data_(NULL) {}
457
458 ~ScopedTracer() {
459 if (p_data_ && *data_.category_group_enabled)
460 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(
461 data_.category_group_enabled, data_.name, data_.event_handle);
462 }
463
464 void Initialize(const uint8_t* category_group_enabled, const char* name,
465 uint64_t event_handle) {
466 data_.category_group_enabled = category_group_enabled;
467 data_.name = name;
468 data_.event_handle = event_handle;
469 p_data_ = &data_;
470 }
471
472 private:
473 // This Data struct workaround is to avoid initializing all the members
474 // in Data during construction of this object, since this object is always
475 // constructed, even when tracing is disabled. If the members of Data were
476 // members of this class instead, compiler warnings occur about potential
477 // uninitialized accesses.
478 struct Data {
479 const uint8_t* category_group_enabled;
480 const char* name;
481 uint64_t event_handle;
482 };
483 Data* p_data_;
484 Data data_;
485 };
486
487 // Used by TRACE_EVENT_BINARY_EFFICIENTx macro. Do not use directly.
488 class ScopedTraceBinaryEfficient {
489 public:
490 ScopedTraceBinaryEfficient(const char* category_group, const char* name);
491 ~ScopedTraceBinaryEfficient();
492
493 private:
494 const uint8_t* category_group_enabled_;
495 const char* name_;
496 uint64_t event_handle_;
497 };
498
499 // TraceEventSamplingStateScope records the current sampling state
500 // and sets a new sampling state. When the scope exists, it restores
501 // the sampling state having recorded.
502 template <size_t BucketNumber>
503 class TraceEventSamplingStateScope {
504 public:
505 explicit TraceEventSamplingStateScope(const char* category_and_name) {
506 previous_state_ = TraceEventSamplingStateScope<BucketNumber>::Current();
507 TraceEventSamplingStateScope<BucketNumber>::Set(category_and_name);
508 }
509
510 ~TraceEventSamplingStateScope() {
511 TraceEventSamplingStateScope<BucketNumber>::Set(previous_state_);
512 }
513
514 static V8_INLINE const char* Current() {
515 return reinterpret_cast<const char*>(
516 TRACE_EVENT_API_ATOMIC_LOAD(g_trace_state[BucketNumber]));
517 }
518
519 static V8_INLINE void Set(const char* category_and_name) {
520 TRACE_EVENT_API_ATOMIC_STORE(g_trace_state[BucketNumber],
521 reinterpret_cast<TRACE_EVENT_API_ATOMIC_WORD>(
522 const_cast<char*>(category_and_name)));
523 }
524
525 private:
526 const char* previous_state_;
527 };
528
529 } // namespace tracing
530 } // namespace internal
531 } // namespace v8
532
533 #endif // SRC_TRACING_TRACE_EVENT_H_
OLDNEW
« include/v8-platform.h ('K') | « src/log-inl.h ('k') | src/tracing/trace-event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698