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

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

Issue 2367603002: [tracing] Support ConvertableToTraceFormat argument type. (Closed)
Patch Set: Created 4 years, 2 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/libplatform/tracing/trace-writer.cc ('k') | test/cctest/libplatform/test-tracing.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 #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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer, 488 INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, as_pointer,
488 TRACE_VALUE_TYPE_POINTER) 489 TRACE_VALUE_TYPE_POINTER)
489 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string, 490 INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, as_string,
490 TRACE_VALUE_TYPE_STRING) 491 TRACE_VALUE_TYPE_STRING)
491 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string, 492 INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string,
492 TRACE_VALUE_TYPE_COPY_STRING) 493 TRACE_VALUE_TYPE_COPY_STRING)
493 494
494 #undef INTERNAL_DECLARE_SET_TRACE_VALUE 495 #undef INTERNAL_DECLARE_SET_TRACE_VALUE
495 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT 496 #undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT
496 497
498 static V8_INLINE void SetTraceValue(ConvertableToTraceFormat* convertable_value,
499 unsigned char* type, uint64_t* value) {
500 *type = TRACE_VALUE_TYPE_CONVERTABLE;
501 *value = static_cast<uint64_t>(reinterpret_cast<intptr_t>(convertable_value));
502 }
503
504 template <typename T>
505 static V8_INLINE void SetTraceValue(std::unique_ptr<T>&& ptr,
caseq 2016/09/23 01:00:50 This does not look well -- we thus accept unique_p
alph 2016/09/23 06:33:24 Done.
506 unsigned char* type, uint64_t* value) {
507 SetTraceValue(ptr.release(), type, value);
508 }
509
497 // These AddTraceEvent template 510 // These AddTraceEvent template
498 // function is defined here instead of in the macro, because the arg_values 511 // 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 512 // 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, 513 // pointers to the internal c_str and pass through to the tracing API,
501 // the arg_values must live throughout these procedures. 514 // the arg_values must live throughout these procedures.
502 515
503 static V8_INLINE uint64_t AddTraceEvent(char phase, 516 static V8_INLINE uint64_t AddTraceEvent(char phase,
504 const uint8_t* category_group_enabled, 517 const uint8_t* category_group_enabled,
505 const char* name, const char* scope, 518 const char* name, const char* scope,
506 uint64_t id, uint64_t bind_id, 519 uint64_t id, uint64_t bind_id,
507 unsigned int flags) { 520 unsigned int flags) {
508 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, 521 return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
509 scope, id, bind_id, kZeroNumArgs, NULL, 522 scope, id, bind_id, kZeroNumArgs, NULL,
510 NULL, NULL, flags); 523 NULL, NULL, flags);
511 } 524 }
512 525
513 template <class ARG1_TYPE> 526 template <class ARG1_TYPE>
514 static V8_INLINE uint64_t AddTraceEvent( 527 static V8_INLINE uint64_t AddTraceEvent(
515 char phase, const uint8_t* category_group_enabled, const char* name, 528 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, 529 const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
517 const char* arg1_name, const ARG1_TYPE& arg1_val) { 530 const char* arg1_name, ARG1_TYPE&& arg1_val) {
518 const int num_args = 1; 531 const int num_args = 1;
519 uint8_t arg_types[1]; 532 uint8_t arg_type;
520 uint64_t arg_values[1]; 533 uint64_t arg_value;
521 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 534 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
522 return TRACE_EVENT_API_ADD_TRACE_EVENT( 535 return TRACE_EVENT_API_ADD_TRACE_EVENT(
523 phase, category_group_enabled, name, scope, id, bind_id, num_args, 536 phase, category_group_enabled, name, scope, id, bind_id, num_args,
524 &arg1_name, arg_types, arg_values, flags); 537 &arg1_name, &arg_type, &arg_value, flags);
525 } 538 }
526 539
527 template <class ARG1_TYPE, class ARG2_TYPE> 540 template <class ARG1_TYPE, class ARG2_TYPE>
528 static V8_INLINE uint64_t AddTraceEvent( 541 static V8_INLINE uint64_t AddTraceEvent(
529 char phase, const uint8_t* category_group_enabled, const char* name, 542 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, 543 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, 544 const char* arg1_name, ARG1_TYPE&& arg1_val, const char* arg2_name,
532 const ARG2_TYPE& arg2_val) { 545 ARG2_TYPE&& arg2_val) {
533 const int num_args = 2; 546 const int num_args = 2;
534 const char* arg_names[2] = {arg1_name, arg2_name}; 547 const char* arg_names[2] = {arg1_name, arg2_name};
535 unsigned char arg_types[2]; 548 unsigned char arg_types[2];
536 uint64_t arg_values[2]; 549 uint64_t arg_values[2];
537 SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]); 550 SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
538 SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]); 551 &arg_values[0]);
552 SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
553 &arg_values[1]);
539 return TRACE_EVENT_API_ADD_TRACE_EVENT( 554 return TRACE_EVENT_API_ADD_TRACE_EVENT(
540 phase, category_group_enabled, name, scope, id, bind_id, num_args, 555 phase, category_group_enabled, name, scope, id, bind_id, num_args,
541 arg_names, arg_types, arg_values, flags); 556 arg_names, arg_types, arg_values, flags);
542 } 557 }
543 558
544 // Used by TRACE_EVENTx macros. Do not use directly. 559 // Used by TRACE_EVENTx macros. Do not use directly.
545 class ScopedTracer { 560 class ScopedTracer {
546 public: 561 public:
547 // Note: members of data_ intentionally left uninitialized. See Initialize. 562 // Note: members of data_ intentionally left uninitialized. See Initialize.
548 ScopedTracer() : p_data_(NULL) {} 563 ScopedTracer() : p_data_(NULL) {}
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 bool has_parent_scope_; 656 bool has_parent_scope_;
642 Data* p_data_; 657 Data* p_data_;
643 Data data_; 658 Data data_;
644 }; 659 };
645 660
646 } // namespace tracing 661 } // namespace tracing
647 } // namespace internal 662 } // namespace internal
648 } // namespace v8 663 } // namespace v8
649 664
650 #endif // SRC_TRACING_TRACE_EVENT_H_ 665 #endif // SRC_TRACING_TRACE_EVENT_H_
OLDNEW
« no previous file with comments | « src/libplatform/tracing/trace-writer.cc ('k') | test/cctest/libplatform/test-tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698