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

Side by Side Diff: base/trace_event/trace_event_impl.cc

Issue 1239593002: Implement a new flow event API that allows binding flow events and regular events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary comments. Created 5 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 #include "base/trace_event/trace_event_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 int num_args = 1; 406 int num_args = 1;
407 unsigned char arg_type; 407 unsigned char arg_type;
408 unsigned long long arg_value; 408 unsigned long long arg_value;
409 ::trace_event_internal::SetTraceValue(value, &arg_type, &arg_value); 409 ::trace_event_internal::SetTraceValue(value, &arg_type, &arg_value);
410 trace_event->Initialize(thread_id, 410 trace_event->Initialize(thread_id,
411 TraceTicks(), ThreadTicks(), 411 TraceTicks(), ThreadTicks(),
412 TRACE_EVENT_PHASE_METADATA, 412 TRACE_EVENT_PHASE_METADATA,
413 &g_category_group_enabled[g_category_metadata], 413 &g_category_group_enabled[g_category_metadata],
414 metadata_name, ::trace_event_internal::kNoEventId, 414 metadata_name, ::trace_event_internal::kNoEventId,
415 num_args, &arg_name, &arg_type, &arg_value, NULL, 415 num_args, &arg_name, &arg_type, &arg_value, NULL,
416 TRACE_EVENT_FLAG_NONE); 416 TRACE_EVENT_FLAG_NONE, trace_event_internal::kNoBindId );
417 } 417 }
418 418
419 class AutoThreadLocalBoolean { 419 class AutoThreadLocalBoolean {
420 public: 420 public:
421 explicit AutoThreadLocalBoolean(ThreadLocalBoolean* thread_local_boolean) 421 explicit AutoThreadLocalBoolean(ThreadLocalBoolean* thread_local_boolean)
422 : thread_local_boolean_(thread_local_boolean) { 422 : thread_local_boolean_(thread_local_boolean) {
423 DCHECK(!thread_local_boolean_->Get()); 423 DCHECK(!thread_local_boolean_->Get());
424 thread_local_boolean_->Set(true); 424 thread_local_boolean_->Set(true);
425 } 425 }
426 ~AutoThreadLocalBoolean() { 426 ~AutoThreadLocalBoolean() {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 ThreadTicks thread_timestamp, 590 ThreadTicks thread_timestamp,
591 char phase, 591 char phase,
592 const unsigned char* category_group_enabled, 592 const unsigned char* category_group_enabled,
593 const char* name, 593 const char* name,
594 unsigned long long id, 594 unsigned long long id,
595 int num_args, 595 int num_args,
596 const char** arg_names, 596 const char** arg_names,
597 const unsigned char* arg_types, 597 const unsigned char* arg_types,
598 const unsigned long long* arg_values, 598 const unsigned long long* arg_values,
599 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, 599 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
600 unsigned int flags) { 600 unsigned int flags,
601 unsigned long long bind_id) {
601 timestamp_ = timestamp; 602 timestamp_ = timestamp;
602 thread_timestamp_ = thread_timestamp; 603 thread_timestamp_ = thread_timestamp;
603 duration_ = TimeDelta::FromInternalValue(-1); 604 duration_ = TimeDelta::FromInternalValue(-1);
604 id_ = id; 605 id_ = id;
605 category_group_enabled_ = category_group_enabled; 606 category_group_enabled_ = category_group_enabled;
606 name_ = name; 607 name_ = name;
607 thread_id_ = thread_id; 608 thread_id_ = thread_id;
608 phase_ = phase; 609 phase_ = phase;
609 flags_ = flags; 610 flags_ = flags;
611 bind_id_ = bind_id;
610 612
611 // Clamp num_args since it may have been set by a third_party library. 613 // Clamp num_args since it may have been set by a third_party library.
612 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; 614 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args;
613 int i = 0; 615 int i = 0;
614 for (; i < num_args; ++i) { 616 for (; i < num_args; ++i) {
615 arg_names_[i] = arg_names[i]; 617 arg_names_[i] = arg_names[i];
616 arg_types_[i] = arg_types[i]; 618 arg_types_[i] = arg_types[i];
617 619
618 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) 620 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE)
619 convertable_values_[i] = convertable_values[i]; 621 convertable_values_[i] = convertable_values[i];
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 843 }
842 844
843 // If id_ is set, print it out as a hex string so we don't loose any 845 // If id_ is set, print it out as a hex string so we don't loose any
844 // bits (it might be a 64-bit pointer). 846 // bits (it might be a 64-bit pointer).
845 if (flags_ & TRACE_EVENT_FLAG_HAS_ID) 847 if (flags_ & TRACE_EVENT_FLAG_HAS_ID)
846 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64>(id_)); 848 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64>(id_));
847 849
848 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) 850 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING)
849 StringAppendF(out, ",\"bp\":\"e\""); 851 StringAppendF(out, ",\"bp\":\"e\"");
850 852
853 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) {
854 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", static_cast<uint64>(bin d_id_));
vmpstr 2015/07/16 21:30:11 why not just make the type uint64?
855 StringAppendF(out, ",\"dir\":\"o\"");
856 }
857
858 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) {
859 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", static_cast<uint64>(bin d_id_));
860 StringAppendF(out, ",\"dir\":\"i\"");
861 }
862
851 // Instant events also output their scope. 863 // Instant events also output their scope.
852 if (phase_ == TRACE_EVENT_PHASE_INSTANT) { 864 if (phase_ == TRACE_EVENT_PHASE_INSTANT) {
853 char scope = '?'; 865 char scope = '?';
854 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) { 866 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) {
855 case TRACE_EVENT_SCOPE_GLOBAL: 867 case TRACE_EVENT_SCOPE_GLOBAL:
856 scope = TRACE_EVENT_SCOPE_NAME_GLOBAL; 868 scope = TRACE_EVENT_SCOPE_NAME_GLOBAL;
857 break; 869 break;
858 870
859 case TRACE_EVENT_SCOPE_PROCESS: 871 case TRACE_EVENT_SCOPE_PROCESS:
860 scope = TRACE_EVENT_SCOPE_NAME_PROCESS; 872 scope = TRACE_EVENT_SCOPE_NAME_PROCESS;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 TraceTicks now = trace_log_->OffsetNow(); 1217 TraceTicks now = trace_log_->OffsetNow();
1206 TimeDelta overhead = now - event_timestamp; 1218 TimeDelta overhead = now - event_timestamp;
1207 if (overhead.InMicroseconds() >= kOverheadReportThresholdInMicroseconds) { 1219 if (overhead.InMicroseconds() >= kOverheadReportThresholdInMicroseconds) {
1208 TraceEvent* trace_event = AddTraceEvent(NULL); 1220 TraceEvent* trace_event = AddTraceEvent(NULL);
1209 if (trace_event) { 1221 if (trace_event) {
1210 trace_event->Initialize( 1222 trace_event->Initialize(
1211 static_cast<int>(PlatformThread::CurrentId()), 1223 static_cast<int>(PlatformThread::CurrentId()),
1212 event_timestamp, event_thread_timestamp, 1224 event_timestamp, event_thread_timestamp,
1213 TRACE_EVENT_PHASE_COMPLETE, 1225 TRACE_EVENT_PHASE_COMPLETE,
1214 &g_category_group_enabled[g_category_trace_event_overhead], 1226 &g_category_group_enabled[g_category_trace_event_overhead],
1215 "overhead", 0, 0, NULL, NULL, NULL, NULL, 0); 1227 "overhead", 0, 0, NULL, NULL, NULL, NULL, 0, 0);
1216 trace_event->UpdateDuration(now, thread_now); 1228 trace_event->UpdateDuration(now, thread_now);
1217 } 1229 }
1218 } 1230 }
1219 overhead_ += overhead; 1231 overhead_ += overhead;
1220 } 1232 }
1221 1233
1222 void TraceLog::ThreadLocalEventBuffer::WillDestroyCurrentMessageLoop() { 1234 void TraceLog::ThreadLocalEventBuffer::WillDestroyCurrentMessageLoop() {
1223 delete this; 1235 delete this;
1224 } 1236 }
1225 1237
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 const unsigned char* arg_types, 2019 const unsigned char* arg_types,
2008 const unsigned long long* arg_values, 2020 const unsigned long long* arg_values,
2009 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, 2021 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
2010 unsigned int flags) { 2022 unsigned int flags) {
2011 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 2023 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
2012 base::TraceTicks now = base::TraceTicks::Now(); 2024 base::TraceTicks now = base::TraceTicks::Now();
2013 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, 2025 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled,
2014 name, id, thread_id, now, 2026 name, id, thread_id, now,
2015 num_args, arg_names, 2027 num_args, arg_names,
2016 arg_types, arg_values, 2028 arg_types, arg_values,
2017 convertable_values, flags); 2029 convertable_values, flags,
2030 trace_event_internal::kNoBindId);
2018 } 2031 }
2019 2032
2020 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( 2033 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
2021 char phase, 2034 char phase,
2022 const unsigned char* category_group_enabled, 2035 const unsigned char* category_group_enabled,
2023 const char* name, 2036 const char* name,
2024 unsigned long long id, 2037 unsigned long long id,
2025 int thread_id, 2038 int thread_id,
2026 const TraceTicks& timestamp, 2039 const TraceTicks& timestamp,
2027 int num_args, 2040 int num_args,
2028 const char** arg_names, 2041 const char** arg_names,
2029 const unsigned char* arg_types, 2042 const unsigned char* arg_types,
2030 const unsigned long long* arg_values, 2043 const unsigned long long* arg_values,
2031 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, 2044 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
2032 unsigned int flags) { 2045 unsigned int flags,
2046 unsigned long long bind_id) {
2033 TraceEventHandle handle = { 0, 0, 0 }; 2047 TraceEventHandle handle = { 0, 0, 0 };
2034 if (!*category_group_enabled) 2048 if (!*category_group_enabled)
2035 return handle; 2049 return handle;
2036 2050
2037 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when 2051 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
2038 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> 2052 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) ->
2039 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... 2053 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ...
2040 if (thread_is_in_trace_event_.Get()) 2054 if (thread_is_in_trace_event_.Get())
2041 return handle; 2055 return handle;
2042 2056
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); 2130 trace_event = thread_local_event_buffer->AddTraceEvent(&handle);
2117 } else { 2131 } else {
2118 lock.EnsureAcquired(); 2132 lock.EnsureAcquired();
2119 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); 2133 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true);
2120 } 2134 }
2121 2135
2122 if (trace_event) { 2136 if (trace_event) {
2123 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now, 2137 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now,
2124 phase, category_group_enabled, name, id, 2138 phase, category_group_enabled, name, id,
2125 num_args, arg_names, arg_types, arg_values, 2139 num_args, arg_names, arg_types, arg_values,
2126 convertable_values, flags); 2140 convertable_values, flags, bind_id);
2127 2141
2128 #if defined(OS_ANDROID) 2142 #if defined(OS_ANDROID)
2129 trace_event->SendToATrace(); 2143 trace_event->SendToATrace();
2130 #endif 2144 #endif
2131 } 2145 }
2132 2146
2133 if (trace_options() & kInternalEchoToConsole) { 2147 if (trace_options() & kInternalEchoToConsole) {
2134 console_message = EventToConsoleMessage( 2148 console_message = EventToConsoleMessage(
2135 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, 2149 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase,
2136 timestamp, trace_event); 2150 timestamp, trace_event);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( 2522 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(
2509 category_group, atomic, category_group_enabled_); 2523 category_group, atomic, category_group_enabled_);
2510 name_ = name; 2524 name_ = name;
2511 if (*category_group_enabled_) { 2525 if (*category_group_enabled_) {
2512 event_handle_ = 2526 event_handle_ =
2513 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 2527 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
2514 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name, 2528 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name,
2515 trace_event_internal::kNoEventId, 2529 trace_event_internal::kNoEventId,
2516 static_cast<int>(base::PlatformThread::CurrentId()), 2530 static_cast<int>(base::PlatformThread::CurrentId()),
2517 base::TraceTicks::Now(), 0, NULL, NULL, NULL, NULL, 2531 base::TraceTicks::Now(), 0, NULL, NULL, NULL, NULL,
2518 TRACE_EVENT_FLAG_NONE); 2532 TRACE_EVENT_FLAG_NONE, 0);
2519 } 2533 }
2520 } 2534 }
2521 2535
2522 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2536 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
2523 if (*category_group_enabled_) { 2537 if (*category_group_enabled_) {
2524 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, 2538 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_,
2525 name_, event_handle_); 2539 name_, event_handle_);
2526 } 2540 }
2527 } 2541 }
2528 2542
2529 } // namespace trace_event_internal 2543 } // namespace trace_event_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698