OLD | NEW |
---|---|
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 #include <memory> | |
9 | 10 |
10 #include "base/trace_event/common/trace_event_common.h" | 11 #include "base/trace_event/common/trace_event_common.h" |
11 #include "include/v8-platform.h" | 12 #include "include/v8-platform.h" |
12 #include "src/base/atomicops.h" | 13 #include "src/base/atomicops.h" |
13 #include "src/base/macros.h" | 14 #include "src/base/macros.h" |
14 | 15 |
15 // This header file defines implementation details of how the trace macros in | 16 // This header file defines implementation details of how the trace macros in |
16 // trace_event_common.h collect and store trace events. Anything not | 17 // trace_event_common.h collect and store trace events. Anything not |
17 // implementation-specific should go in trace_macros_common.h instead of here. | 18 // implementation-specific should go in trace_macros_common.h instead of here. |
18 | 19 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 // const uint8_t* category_group_enabled, | 114 // const uint8_t* category_group_enabled, |
114 // const char* name, | 115 // const char* name, |
115 // const char* scope, | 116 // const char* scope, |
116 // uint64_t id, | 117 // uint64_t id, |
117 // uint64_t bind_id, | 118 // uint64_t bind_id, |
118 // int num_args, | 119 // int num_args, |
119 // const char** arg_names, | 120 // const char** arg_names, |
120 // const uint8_t* arg_types, | 121 // const uint8_t* arg_types, |
121 // const uint64_t* arg_values, | 122 // const uint64_t* arg_values, |
122 // unsigned int flags) | 123 // unsigned int flags) |
123 #define TRACE_EVENT_API_ADD_TRACE_EVENT \ | 124 #define TRACE_EVENT_API_ADD_TRACE_EVENT v8::internal::tracing::AddTraceEventImpl |
124 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform()->AddTraceEvent | |
125 | 125 |
126 // Set the duration field of a COMPLETE trace event. | 126 // Set the duration field of a COMPLETE trace event. |
127 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( | 127 // void TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION( |
128 // const uint8_t* category_group_enabled, | 128 // const uint8_t* category_group_enabled, |
129 // const char* name, | 129 // const char* name, |
130 // uint64_t id) | 130 // uint64_t id) |
131 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ | 131 #define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \ |
132 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \ | 132 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform() \ |
133 ->UpdateTraceEventDuration | 133 ->UpdateTraceEventDuration |
134 | 134 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 // Simple container for const char* that should be copied instead of retained. | 447 // Simple container for const char* that should be copied instead of retained. |
448 class TraceStringWithCopy { | 448 class TraceStringWithCopy { |
449 public: | 449 public: |
450 explicit TraceStringWithCopy(const char* str) : str_(str) {} | 450 explicit TraceStringWithCopy(const char* str) : str_(str) {} |
451 operator const char*() const { return str_; } | 451 operator const char*() const { return str_; } |
452 | 452 |
453 private: | 453 private: |
454 const char* str_; | 454 const char* str_; |
455 }; | 455 }; |
456 | 456 |
457 static V8_INLINE uint64_t AddTraceEventImpl( | |
458 char phase, const uint8_t* category_group_enabled, const char* name, | |
459 const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, | |
460 const char** arg_names, const uint8_t* arg_types, | |
461 const uint64_t* arg_values, unsigned int flags) { | |
462 std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2]; | |
463 if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) { | |
464 arg_convertables[0].reset(reinterpret_cast<ConvertableToTraceFormat*>( | |
465 static_cast<intptr_t>(arg_values[0]))); | |
466 } | |
467 if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) { | |
468 arg_convertables[1].reset(reinterpret_cast<ConvertableToTraceFormat*>( | |
469 static_cast<intptr_t>(arg_values[1]))); | |
470 } | |
471 DCHECK(num_args <= 2); | |
472 v8::Platform* platform = | |
473 v8::internal::tracing::TraceEventHelper::GetCurrentPlatform(); | |
474 uint64_t handle = platform->AddTraceEvent( | |
475 phase, category_group_enabled, name, scope, id, bind_id, num_args, | |
476 arg_names, arg_types, arg_values, arg_convertables, flags); | |
477 if (handle) return handle; | |
478 // TODO(alph): Remove legacy AddTraceEvent call. | |
479 return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id, | |
caseq
2016/09/23 23:48:34
just drop this one and let the default implementat
alph
2016/09/24 00:24:06
Done.
| |
480 bind_id, num_args, arg_names, arg_types, | |
481 arg_values, flags); | |
482 } | |
483 | |
457 // Define SetTraceValue for each allowed type. It stores the type and | 484 // Define SetTraceValue for each allowed type. It stores the type and |
458 // value in the return arguments. This allows this API to avoid declaring any | 485 // value in the return arguments. This allows this API to avoid declaring any |
459 // structures so that it is portable to third_party libraries. | 486 // structures so that it is portable to third_party libraries. |
460 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \ | 487 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \ |
461 value_type_id) \ | 488 value_type_id) \ |
462 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \ | 489 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \ |
463 uint64_t* value) { \ | 490 uint64_t* value) { \ |
464 TraceValueUnion type_value; \ | 491 TraceValueUnion type_value; \ |
465 type_value.union_member = arg; \ | 492 type_value.union_member = arg; \ |
466 *type = value_type_id; \ | 493 *type = value_type_id; \ |
(...skipping 20 matching lines...) Expand all Loading... | |
487 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | 514 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, |
488 TRACE_VALUE_TYPE_POINTER) | 515 TRACE_VALUE_TYPE_POINTER) |
489 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | 516 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, |
490 TRACE_VALUE_TYPE_STRING) | 517 TRACE_VALUE_TYPE_STRING) |
491 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | 518 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, |
492 TRACE_VALUE_TYPE_COPY_STRING) | 519 TRACE_VALUE_TYPE_COPY_STRING) |
493 | 520 |
494 #undef INTERNAL_DECLARE_SET_TRACE_VALUE | 521 #undef INTERNAL_DECLARE_SET_TRACE_VALUE |
495 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT | 522 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT |
496 | 523 |
524 static V8_INLINE void SetTraceValue(ConvertableToTraceFormat* convertable_value, | |
525 unsigned char* type, uint64_t* value) { | |
526 *type = TRACE_VALUE_TYPE_CONVERTABLE; | |
527 *value = static_cast<uint64_t>(reinterpret_cast<intptr_t>(convertable_value)); | |
528 } | |
529 | |
530 template <class T> | |
531 static V8_INLINE void SetTraceValue(std::unique_ptr<T> ptr, unsigned char* type, | |
caseq
2016/09/23 23:48:34
nit: consider std::enable_if<std::is_convertible<T
alph
2016/09/24 00:24:06
Done.
| |
532 uint64_t* value) { | |
533 SetTraceValue(static_cast<ConvertableToTraceFormat*>(ptr.release()), type, | |
534 value); | |
535 } | |
536 | |
497 // These AddTraceEvent template | 537 // These AddTraceEvent template |
498 // function is defined here instead of in the macro, because the arg_values | 538 // function is defined here instead of in the macro, because the arg_values |
499 // could be temporary objects, such as std::string. In order to store | 539 // could be temporary objects, such as std::string. In order to store |
500 // pointers to the internal c_str and pass through to the tracing API, | 540 // pointers to the internal c_str and pass through to the tracing API, |
501 // the arg_values must live throughout these procedures. | 541 // the arg_values must live throughout these procedures. |
502 | 542 |
503 static V8_INLINE uint64_t AddTraceEvent(char phase, | 543 static V8_INLINE uint64_t AddTraceEvent(char phase, |
504 const uint8_t* category_group_enabled, | 544 const uint8_t* category_group_enabled, |
505 const char* name, const char* scope, | 545 const char* name, const char* scope, |
506 uint64_t id, uint64_t bind_id, | 546 uint64_t id, uint64_t bind_id, |
507 unsigned int flags) { | 547 unsigned int flags) { |
508 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, | 548 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, |
509 scope, id, bind_id, kZeroNumArgs, NULL, | 549 scope, id, bind_id, kZeroNumArgs, |
510 NULL, NULL, flags); | 550 nullptr, nullptr, nullptr, flags); |
511 } | 551 } |
512 | 552 |
513 template <class ARG1_TYPE> | 553 template <class ARG1_TYPE> |
514 static V8_INLINE uint64_t AddTraceEvent( | 554 static V8_INLINE uint64_t AddTraceEvent( |
515 char phase, const uint8_t* category_group_enabled, const char* name, | 555 char phase, const uint8_t* category_group_enabled, const char* name, |
516 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, | 556 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, |
517 const char* arg1_name, const ARG1_TYPE& arg1_val) { | 557 const char* arg1_name, ARG1_TYPE&& arg1_val) { |
518 const int num_args = 1; | 558 const int num_args = 1; |
519 uint8_t arg_types[1]; | 559 uint8_t arg_type; |
520 uint64_t arg_values[1]; | 560 uint64_t arg_value; |
521 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 561 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value); |
522 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 562 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
523 phase, category_group_enabled, name, scope, id, bind_id, num_args, | 563 phase, category_group_enabled, name, scope, id, bind_id, num_args, |
524 &arg1_name, arg_types, arg_values, flags); | 564 &arg1_name, &arg_type, &arg_value, flags); |
525 } | 565 } |
526 | 566 |
527 template <class ARG1_TYPE, class ARG2_TYPE> | 567 template <class ARG1_TYPE, class ARG2_TYPE> |
528 static V8_INLINE uint64_t AddTraceEvent( | 568 static V8_INLINE uint64_t AddTraceEvent( |
529 char phase, const uint8_t* category_group_enabled, const char* name, | 569 char phase, const uint8_t* category_group_enabled, const char* name, |
530 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, | 570 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, |
531 const char* arg1_name, const ARG1_TYPE& arg1_val, const char* arg2_name, | 571 const char* arg1_name, ARG1_TYPE&& arg1_val, const char* arg2_name, |
532 const ARG2_TYPE& arg2_val) { | 572 ARG2_TYPE&& arg2_val) { |
533 const int num_args = 2; | 573 const int num_args = 2; |
534 const char* arg_names[2] = {arg1_name, arg2_name}; | 574 const char* arg_names[2] = {arg1_name, arg2_name}; |
535 unsigned char arg_types[2]; | 575 unsigned char arg_types[2]; |
536 uint64_t arg_values[2]; | 576 uint64_t arg_values[2]; |
537 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 577 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0], |
538 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 578 &arg_values[0]); |
579 SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1], | |
580 &arg_values[1]); | |
539 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 581 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
540 phase, category_group_enabled, name, scope, id, bind_id, num_args, | 582 phase, category_group_enabled, name, scope, id, bind_id, num_args, |
541 arg_names, arg_types, arg_values, flags); | 583 arg_names, arg_types, arg_values, flags); |
542 } | 584 } |
543 | 585 |
544 // Used by TRACE_EVENTx macros. Do not use directly. | 586 // Used by TRACE_EVENTx macros. Do not use directly. |
545 class ScopedTracer { | 587 class ScopedTracer { |
546 public: | 588 public: |
547 // Note: members of data_ intentionally left uninitialized. See Initialize. | 589 // Note: members of data_ intentionally left uninitialized. See Initialize. |
548 ScopedTracer() : p_data_(NULL) {} | 590 ScopedTracer() : p_data_(NULL) {} |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 bool has_parent_scope_; | 683 bool has_parent_scope_; |
642 Data* p_data_; | 684 Data* p_data_; |
643 Data data_; | 685 Data data_; |
644 }; | 686 }; |
645 | 687 |
646 } // namespace tracing | 688 } // namespace tracing |
647 } // namespace internal | 689 } // namespace internal |
648 } // namespace v8 | 690 } // namespace v8 |
649 | 691 |
650 #endif // SRC_TRACING_TRACE_EVENT_H_ | 692 #endif // SRC_TRACING_TRACE_EVENT_H_ |
OLD | NEW |