| 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 return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id, |
| 475 bind_id, num_args, arg_names, arg_types, |
| 476 arg_values, arg_convertables, flags); |
| 477 } |
| 478 |
| 457 // Define SetTraceValue for each allowed type. It stores the type and | 479 // 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 | 480 // value in the return arguments. This allows this API to avoid declaring any |
| 459 // structures so that it is portable to third_party libraries. | 481 // structures so that it is portable to third_party libraries. |
| 460 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \ | 482 #define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, \ |
| 461 value_type_id) \ | 483 value_type_id) \ |
| 462 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \ | 484 static V8_INLINE void SetTraceValue(actual_type arg, unsigned char* type, \ |
| 463 uint64_t* value) { \ | 485 uint64_t* value) { \ |
| 464 TraceValueUnion type_value; \ | 486 TraceValueUnion type_value; \ |
| 465 type_value.union_member = arg; \ | 487 type_value.union_member = arg; \ |
| 466 *type = value_type_id; \ | 488 *type = value_type_id; \ |
| (...skipping 20 matching lines...) Expand all Loading... |
| 487 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, | 509 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, |
| 488 TRACE_VALUE_TYPE_POINTER) | 510 TRACE_VALUE_TYPE_POINTER) |
| 489 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, | 511 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, |
| 490 TRACE_VALUE_TYPE_STRING) | 512 TRACE_VALUE_TYPE_STRING) |
| 491 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, | 513 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, |
| 492 TRACE_VALUE_TYPE_COPY_STRING) | 514 TRACE_VALUE_TYPE_COPY_STRING) |
| 493 | 515 |
| 494 #undef INTERNAL_DECLARE_SET_TRACE_VALUE | 516 #undef INTERNAL_DECLARE_SET_TRACE_VALUE |
| 495 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT | 517 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT |
| 496 | 518 |
| 519 static V8_INLINE void SetTraceValue(ConvertableToTraceFormat* convertable_value, |
| 520 unsigned char* type, uint64_t* value) { |
| 521 *type = TRACE_VALUE_TYPE_CONVERTABLE; |
| 522 *value = static_cast<uint64_t>(reinterpret_cast<intptr_t>(convertable_value)); |
| 523 } |
| 524 |
| 525 template <typename T> |
| 526 static V8_INLINE typename std::enable_if< |
| 527 std::is_convertible<T*, ConvertableToTraceFormat*>::value>::type |
| 528 SetTraceValue(std::unique_ptr<T> ptr, unsigned char* type, uint64_t* value) { |
| 529 SetTraceValue(ptr.release(), type, value); |
| 530 } |
| 531 |
| 497 // These AddTraceEvent template | 532 // These AddTraceEvent template |
| 498 // function is defined here instead of in the macro, because the arg_values | 533 // 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 | 534 // 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, | 535 // pointers to the internal c_str and pass through to the tracing API, |
| 501 // the arg_values must live throughout these procedures. | 536 // the arg_values must live throughout these procedures. |
| 502 | 537 |
| 503 static V8_INLINE uint64_t AddTraceEvent(char phase, | 538 static V8_INLINE uint64_t AddTraceEvent(char phase, |
| 504 const uint8_t* category_group_enabled, | 539 const uint8_t* category_group_enabled, |
| 505 const char* name, const char* scope, | 540 const char* name, const char* scope, |
| 506 uint64_t id, uint64_t bind_id, | 541 uint64_t id, uint64_t bind_id, |
| 507 unsigned int flags) { | 542 unsigned int flags) { |
| 508 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, | 543 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, |
| 509 scope, id, bind_id, kZeroNumArgs, NULL, | 544 scope, id, bind_id, kZeroNumArgs, |
| 510 NULL, NULL, flags); | 545 nullptr, nullptr, nullptr, flags); |
| 511 } | 546 } |
| 512 | 547 |
| 513 template <class ARG1_TYPE> | 548 template <class ARG1_TYPE> |
| 514 static V8_INLINE uint64_t AddTraceEvent( | 549 static V8_INLINE uint64_t AddTraceEvent( |
| 515 char phase, const uint8_t* category_group_enabled, const char* name, | 550 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, | 551 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags, |
| 517 const char* arg1_name, const ARG1_TYPE& arg1_val) { | 552 const char* arg1_name, ARG1_TYPE&& arg1_val) { |
| 518 const int num_args = 1; | 553 const int num_args = 1; |
| 519 uint8_t arg_types[1]; | 554 uint8_t arg_type; |
| 520 uint64_t arg_values[1]; | 555 uint64_t arg_value; |
| 521 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 556 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value); |
| 522 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 557 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 523 phase, category_group_enabled, name, scope, id, bind_id, num_args, | 558 phase, category_group_enabled, name, scope, id, bind_id, num_args, |
| 524 &arg1_name, arg_types, arg_values, flags); | 559 &arg1_name, &arg_type, &arg_value, flags); |
| 525 } | 560 } |
| 526 | 561 |
| 527 template <class ARG1_TYPE, class ARG2_TYPE> | 562 template <class ARG1_TYPE, class ARG2_TYPE> |
| 528 static V8_INLINE uint64_t AddTraceEvent( | 563 static V8_INLINE uint64_t AddTraceEvent( |
| 529 char phase, const uint8_t* category_group_enabled, const char* name, | 564 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, | 565 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, | 566 const char* arg1_name, ARG1_TYPE&& arg1_val, const char* arg2_name, |
| 532 const ARG2_TYPE& arg2_val) { | 567 ARG2_TYPE&& arg2_val) { |
| 533 const int num_args = 2; | 568 const int num_args = 2; |
| 534 const char* arg_names[2] = {arg1_name, arg2_name}; | 569 const char* arg_names[2] = {arg1_name, arg2_name}; |
| 535 unsigned char arg_types[2]; | 570 unsigned char arg_types[2]; |
| 536 uint64_t arg_values[2]; | 571 uint64_t arg_values[2]; |
| 537 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); | 572 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0], |
| 538 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); | 573 &arg_values[0]); |
| 574 SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1], |
| 575 &arg_values[1]); |
| 539 return TRACE_EVENT_API_ADD_TRACE_EVENT( | 576 return TRACE_EVENT_API_ADD_TRACE_EVENT( |
| 540 phase, category_group_enabled, name, scope, id, bind_id, num_args, | 577 phase, category_group_enabled, name, scope, id, bind_id, num_args, |
| 541 arg_names, arg_types, arg_values, flags); | 578 arg_names, arg_types, arg_values, flags); |
| 542 } | 579 } |
| 543 | 580 |
| 544 // Used by TRACE_EVENTx macros. Do not use directly. | 581 // Used by TRACE_EVENTx macros. Do not use directly. |
| 545 class ScopedTracer { | 582 class ScopedTracer { |
| 546 public: | 583 public: |
| 547 // Note: members of data_ intentionally left uninitialized. See Initialize. | 584 // Note: members of data_ intentionally left uninitialized. See Initialize. |
| 548 ScopedTracer() : p_data_(NULL) {} | 585 ScopedTracer() : p_data_(NULL) {} |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 bool has_parent_scope_; | 678 bool has_parent_scope_; |
| 642 Data* p_data_; | 679 Data* p_data_; |
| 643 Data data_; | 680 Data data_; |
| 644 }; | 681 }; |
| 645 | 682 |
| 646 } // namespace tracing | 683 } // namespace tracing |
| 647 } // namespace internal | 684 } // namespace internal |
| 648 } // namespace v8 | 685 } // namespace v8 |
| 649 | 686 |
| 650 #endif // SRC_TRACING_TRACE_EVENT_H_ | 687 #endif // SRC_TRACING_TRACE_EVENT_H_ |
| OLD | NEW |