OLD | NEW |
---|---|
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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 int thread_id, | 400 int thread_id, |
401 const char* metadata_name, const char* arg_name, | 401 const char* metadata_name, const char* arg_name, |
402 const T& value) { | 402 const T& value) { |
403 if (!trace_event) | 403 if (!trace_event) |
404 return; | 404 return; |
405 | 405 |
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( |
411 TraceTicks(), ThreadTicks(), | 411 thread_id, TraceTicks(), ThreadTicks(), TRACE_EVENT_PHASE_METADATA, |
412 TRACE_EVENT_PHASE_METADATA, | 412 &g_category_group_enabled[g_category_metadata], metadata_name, |
413 &g_category_group_enabled[g_category_metadata], | 413 ::trace_event_internal::kNoEventId, num_args, &arg_name, &arg_type, |
414 metadata_name, ::trace_event_internal::kNoEventId, | 414 &arg_value, NULL, TRACE_EVENT_FLAG_NONE, trace_event_internal::kNoBindId); |
415 num_args, &arg_name, &arg_type, &arg_value, NULL, | |
416 TRACE_EVENT_FLAG_NONE); | |
417 } | 415 } |
418 | 416 |
419 class AutoThreadLocalBoolean { | 417 class AutoThreadLocalBoolean { |
420 public: | 418 public: |
421 explicit AutoThreadLocalBoolean(ThreadLocalBoolean* thread_local_boolean) | 419 explicit AutoThreadLocalBoolean(ThreadLocalBoolean* thread_local_boolean) |
422 : thread_local_boolean_(thread_local_boolean) { | 420 : thread_local_boolean_(thread_local_boolean) { |
423 DCHECK(!thread_local_boolean_->Get()); | 421 DCHECK(!thread_local_boolean_->Get()); |
424 thread_local_boolean_->Set(true); | 422 thread_local_boolean_->Set(true); |
425 } | 423 } |
426 ~AutoThreadLocalBoolean() { | 424 ~AutoThreadLocalBoolean() { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 ThreadTicks thread_timestamp, | 588 ThreadTicks thread_timestamp, |
591 char phase, | 589 char phase, |
592 const unsigned char* category_group_enabled, | 590 const unsigned char* category_group_enabled, |
593 const char* name, | 591 const char* name, |
594 unsigned long long id, | 592 unsigned long long id, |
595 int num_args, | 593 int num_args, |
596 const char** arg_names, | 594 const char** arg_names, |
597 const unsigned char* arg_types, | 595 const unsigned char* arg_types, |
598 const unsigned long long* arg_values, | 596 const unsigned long long* arg_values, |
599 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 597 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
600 unsigned int flags) { | 598 unsigned int flags, |
599 unsigned long long bind_id) { | |
dsinclair
2015/07/17 13:39:41
Move up below id.
| |
601 timestamp_ = timestamp; | 600 timestamp_ = timestamp; |
602 thread_timestamp_ = thread_timestamp; | 601 thread_timestamp_ = thread_timestamp; |
603 duration_ = TimeDelta::FromInternalValue(-1); | 602 duration_ = TimeDelta::FromInternalValue(-1); |
604 id_ = id; | 603 id_ = id; |
605 category_group_enabled_ = category_group_enabled; | 604 category_group_enabled_ = category_group_enabled; |
606 name_ = name; | 605 name_ = name; |
607 thread_id_ = thread_id; | 606 thread_id_ = thread_id; |
608 phase_ = phase; | 607 phase_ = phase; |
609 flags_ = flags; | 608 flags_ = flags; |
609 bind_id_ = bind_id; | |
610 | 610 |
611 // Clamp num_args since it may have been set by a third_party library. | 611 // Clamp num_args since it may have been set by a third_party library. |
612 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; | 612 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; |
613 int i = 0; | 613 int i = 0; |
614 for (; i < num_args; ++i) { | 614 for (; i < num_args; ++i) { |
615 arg_names_[i] = arg_names[i]; | 615 arg_names_[i] = arg_names[i]; |
616 arg_types_[i] = arg_types[i]; | 616 arg_types_[i] = arg_types[i]; |
617 | 617 |
618 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) | 618 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) |
619 convertable_values_[i] = convertable_values[i]; | 619 convertable_values_[i] = convertable_values[i]; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 } | 841 } |
842 | 842 |
843 // If id_ is set, print it out as a hex string so we don't loose any | 843 // 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). | 844 // bits (it might be a 64-bit pointer). |
845 if (flags_ & TRACE_EVENT_FLAG_HAS_ID) | 845 if (flags_ & TRACE_EVENT_FLAG_HAS_ID) |
846 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64>(id_)); | 846 StringAppendF(out, ",\"id\":\"0x%" PRIx64 "\"", static_cast<uint64>(id_)); |
847 | 847 |
848 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) | 848 if (flags_ & TRACE_EVENT_FLAG_BIND_TO_ENCLOSING) |
849 StringAppendF(out, ",\"bp\":\"e\""); | 849 StringAppendF(out, ",\"bp\":\"e\""); |
850 | 850 |
851 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) { | |
dsinclair
2015/07/17 13:39:40
I think this needs to be a bit more complicated. W
| |
852 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", | |
853 static_cast<uint64>(bind_id_)); | |
854 StringAppendF(out, ",\"dir\":\"o\""); | |
855 } | |
856 | |
857 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) { | |
858 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", | |
859 static_cast<uint64>(bind_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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1201 CheckThisIsCurrentBuffer(); | 1213 CheckThisIsCurrentBuffer(); |
1202 | 1214 |
1203 event_count_++; | 1215 event_count_++; |
1204 ThreadTicks thread_now = ThreadNow(); | 1216 ThreadTicks thread_now = ThreadNow(); |
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()), event_timestamp, |
1212 event_timestamp, event_thread_timestamp, | 1224 event_thread_timestamp, TRACE_EVENT_PHASE_COMPLETE, |
1213 TRACE_EVENT_PHASE_COMPLETE, | |
1214 &g_category_group_enabled[g_category_trace_event_overhead], | 1225 &g_category_group_enabled[g_category_trace_event_overhead], |
1215 "overhead", 0, 0, NULL, NULL, NULL, NULL, 0); | 1226 "overhead", 0, 0, NULL, NULL, NULL, NULL, 0, 0); |
dsinclair
2015/07/17 13:39:41
If this 0 is id use the kNoId please.
| |
1216 trace_event->UpdateDuration(now, thread_now); | 1227 trace_event->UpdateDuration(now, thread_now); |
1217 } | 1228 } |
1218 } | 1229 } |
1219 overhead_ += overhead; | 1230 overhead_ += overhead; |
1220 } | 1231 } |
1221 | 1232 |
1222 void TraceLog::ThreadLocalEventBuffer::WillDestroyCurrentMessageLoop() { | 1233 void TraceLog::ThreadLocalEventBuffer::WillDestroyCurrentMessageLoop() { |
1223 delete this; | 1234 delete this; |
1224 } | 1235 } |
1225 | 1236 |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2003 const char* name, | 2014 const char* name, |
2004 unsigned long long id, | 2015 unsigned long long id, |
2005 int num_args, | 2016 int num_args, |
2006 const char** arg_names, | 2017 const char** arg_names, |
2007 const unsigned char* arg_types, | 2018 const unsigned char* arg_types, |
2008 const unsigned long long* arg_values, | 2019 const unsigned long long* arg_values, |
2009 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 2020 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
2010 unsigned int flags) { | 2021 unsigned int flags) { |
2011 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); | 2022 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); |
2012 base::TraceTicks now = base::TraceTicks::Now(); | 2023 base::TraceTicks now = base::TraceTicks::Now(); |
2013 return AddTraceEventWithThreadIdAndTimestamp(phase, category_group_enabled, | 2024 return AddTraceEventWithThreadIdAndTimestamp( |
2014 name, id, thread_id, now, | 2025 phase, category_group_enabled, name, id, thread_id, now, num_args, |
2015 num_args, arg_names, | 2026 arg_names, arg_types, arg_values, convertable_values, flags, |
2016 arg_types, arg_values, | 2027 trace_event_internal::kNoBindId); |
2017 convertable_values, flags); | |
2018 } | 2028 } |
2019 | 2029 |
2020 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( | 2030 TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp( |
2021 char phase, | 2031 char phase, |
2022 const unsigned char* category_group_enabled, | 2032 const unsigned char* category_group_enabled, |
2023 const char* name, | 2033 const char* name, |
2024 unsigned long long id, | 2034 unsigned long long id, |
2025 int thread_id, | 2035 int thread_id, |
2026 const TraceTicks& timestamp, | 2036 const TraceTicks& timestamp, |
2027 int num_args, | 2037 int num_args, |
2028 const char** arg_names, | 2038 const char** arg_names, |
2029 const unsigned char* arg_types, | 2039 const unsigned char* arg_types, |
2030 const unsigned long long* arg_values, | 2040 const unsigned long long* arg_values, |
2031 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 2041 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
2032 unsigned int flags) { | 2042 unsigned int flags, |
2043 unsigned long long bind_id) { | |
dsinclair
2015/07/17 13:39:41
Move up below thread_id
| |
2033 TraceEventHandle handle = { 0, 0, 0 }; | 2044 TraceEventHandle handle = { 0, 0, 0 }; |
2034 if (!*category_group_enabled) | 2045 if (!*category_group_enabled) |
2035 return handle; | 2046 return handle; |
2036 | 2047 |
2037 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when | 2048 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when |
2038 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> | 2049 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> |
2039 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... | 2050 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... |
2040 if (thread_is_in_trace_event_.Get()) | 2051 if (thread_is_in_trace_event_.Get()) |
2041 return handle; | 2052 return handle; |
2042 | 2053 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2114 TraceEvent* trace_event = NULL; | 2125 TraceEvent* trace_event = NULL; |
2115 if (thread_local_event_buffer) { | 2126 if (thread_local_event_buffer) { |
2116 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); | 2127 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); |
2117 } else { | 2128 } else { |
2118 lock.EnsureAcquired(); | 2129 lock.EnsureAcquired(); |
2119 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); | 2130 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); |
2120 } | 2131 } |
2121 | 2132 |
2122 if (trace_event) { | 2133 if (trace_event) { |
2123 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now, | 2134 trace_event->Initialize(thread_id, offset_event_timestamp, thread_now, |
2124 phase, category_group_enabled, name, id, | 2135 phase, category_group_enabled, name, id, num_args, |
2125 num_args, arg_names, arg_types, arg_values, | 2136 arg_names, arg_types, arg_values, |
2126 convertable_values, flags); | 2137 convertable_values, flags, bind_id); |
2127 | 2138 |
2128 #if defined(OS_ANDROID) | 2139 #if defined(OS_ANDROID) |
2129 trace_event->SendToATrace(); | 2140 trace_event->SendToATrace(); |
2130 #endif | 2141 #endif |
2131 } | 2142 } |
2132 | 2143 |
2133 if (trace_options() & kInternalEchoToConsole) { | 2144 if (trace_options() & kInternalEchoToConsole) { |
2134 console_message = EventToConsoleMessage( | 2145 console_message = EventToConsoleMessage( |
2135 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, | 2146 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, |
2136 timestamp, trace_event); | 2147 timestamp, trace_event); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2508 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( | 2519 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( |
2509 category_group, atomic, category_group_enabled_); | 2520 category_group, atomic, category_group_enabled_); |
2510 name_ = name; | 2521 name_ = name; |
2511 if (*category_group_enabled_) { | 2522 if (*category_group_enabled_) { |
2512 event_handle_ = | 2523 event_handle_ = |
2513 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( | 2524 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( |
2514 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name, | 2525 TRACE_EVENT_PHASE_COMPLETE, category_group_enabled_, name, |
2515 trace_event_internal::kNoEventId, | 2526 trace_event_internal::kNoEventId, |
2516 static_cast<int>(base::PlatformThread::CurrentId()), | 2527 static_cast<int>(base::PlatformThread::CurrentId()), |
2517 base::TraceTicks::Now(), 0, NULL, NULL, NULL, NULL, | 2528 base::TraceTicks::Now(), 0, NULL, NULL, NULL, NULL, |
2518 TRACE_EVENT_FLAG_NONE); | 2529 TRACE_EVENT_FLAG_NONE, 0); |
dsinclair
2015/07/17 13:39:40
Use kNoId.
| |
2519 } | 2530 } |
2520 } | 2531 } |
2521 | 2532 |
2522 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2533 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
2523 if (*category_group_enabled_) { | 2534 if (*category_group_enabled_) { |
2524 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2535 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
2525 name_, event_handle_); | 2536 name_, event_handle_); |
2526 } | 2537 } |
2527 } | 2538 } |
2528 | 2539 |
2529 } // namespace trace_event_internal | 2540 } // namespace trace_event_internal |
OLD | NEW |