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