| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_log.h" | 5 #include "base/trace_event/trace_log.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 TraceLogStatus::TraceLogStatus() : event_capacity(0), event_count(0) {} | 455 TraceLogStatus::TraceLogStatus() : event_capacity(0), event_count(0) {} |
| 456 | 456 |
| 457 TraceLogStatus::~TraceLogStatus() {} | 457 TraceLogStatus::~TraceLogStatus() {} |
| 458 | 458 |
| 459 // static | 459 // static |
| 460 TraceLog* TraceLog::GetInstance() { | 460 TraceLog* TraceLog::GetInstance() { |
| 461 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get(); | 461 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 TraceLog::TraceLog() | 464 TraceLog::TraceLog() |
| 465 : mode_(DISABLED), | 465 : enabled_modes_(0), |
| 466 num_traces_recorded_(0), | 466 num_traces_recorded_(0), |
| 467 event_callback_(0), | 467 event_callback_(0), |
| 468 dispatching_to_observer_list_(false), | 468 dispatching_to_observer_list_(false), |
| 469 process_sort_index_(0), | 469 process_sort_index_(0), |
| 470 process_id_hash_(0), | 470 process_id_hash_(0), |
| 471 process_id_(0), | 471 process_id_(0), |
| 472 watch_category_(0), | 472 watch_category_(0), |
| 473 trace_options_(kInternalRecordUntilFull), | 473 trace_options_(kInternalRecordUntilFull), |
| 474 trace_config_(TraceConfig()), | 474 trace_config_(TraceConfig()), |
| 475 event_callback_trace_config_(TraceConfig()), | 475 event_callback_trace_config_(TraceConfig()), |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 553 } |
| 554 | 554 |
| 555 const char* TraceLog::GetCategoryGroupName( | 555 const char* TraceLog::GetCategoryGroupName( |
| 556 const unsigned char* category_group_enabled) { | 556 const unsigned char* category_group_enabled) { |
| 557 return g_category_groups[GetCategoryIndex(category_group_enabled)]; | 557 return g_category_groups[GetCategoryIndex(category_group_enabled)]; |
| 558 } | 558 } |
| 559 | 559 |
| 560 void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) { | 560 void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) { |
| 561 unsigned char enabled_flag = 0; | 561 unsigned char enabled_flag = 0; |
| 562 const char* category_group = g_category_groups[category_index]; | 562 const char* category_group = g_category_groups[category_index]; |
| 563 if (mode_ == RECORDING_MODE && | 563 if (enabled_modes_ & RECORDING_MODE && |
| 564 trace_config_.IsCategoryGroupEnabled(category_group)) { | 564 trace_config_.IsCategoryGroupEnabled(category_group)) { |
| 565 enabled_flag |= ENABLED_FOR_RECORDING; | 565 enabled_flag |= ENABLED_FOR_RECORDING; |
| 566 } | 566 } |
| 567 | 567 |
| 568 if (event_callback_ && | 568 if (event_callback_ && |
| 569 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) { | 569 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) { |
| 570 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; | 570 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; |
| 571 } | 571 } |
| 572 | 572 |
| 573 #if defined(OS_WIN) | 573 #if defined(OS_WIN) |
| 574 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled( | 574 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled( |
| 575 category_group)) { | 575 category_group)) { |
| 576 enabled_flag |= ENABLED_FOR_ETW_EXPORT; | 576 enabled_flag |= ENABLED_FOR_ETW_EXPORT; |
| 577 } | 577 } |
| 578 #endif | 578 #endif |
| 579 | 579 |
| 580 // TODO(primiano): this is a temporary workaround for catapult:#2341, | 580 // TODO(primiano): this is a temporary workaround for catapult:#2341, |
| 581 // to guarantee that metadata events are always added even if the category | 581 // to guarantee that metadata events are always added even if the category |
| 582 // filter is "-*". See crbug.com/618054 for more details and long-term fix. | 582 // filter is "-*". See crbug.com/618054 for more details and long-term fix. |
| 583 if (mode_ == RECORDING_MODE && !strcmp(category_group, "__metadata")) | 583 if (enabled_modes_ & RECORDING_MODE && !strcmp(category_group, "__metadata")) |
| 584 enabled_flag |= ENABLED_FOR_RECORDING; | 584 enabled_flag |= ENABLED_FOR_RECORDING; |
| 585 | 585 |
| 586 uint32_t enabled_filters_bitmap = 0; | 586 uint32_t enabled_filters_bitmap = 0; |
| 587 int index = 0; | 587 int index = 0; |
| 588 for (const auto& event_filter : trace_config_.event_filters()) { | 588 for (const auto& event_filter : enabled_event_filters_) { |
| 589 if (event_filter.IsCategoryGroupEnabled(category_group)) { | 589 if (event_filter.IsCategoryGroupEnabled(category_group)) { |
| 590 enabled_flag |= ENABLED_FOR_FILTERING; | 590 enabled_flag |= ENABLED_FOR_FILTERING; |
| 591 DCHECK(g_category_group_filters.Get()[index]); | 591 DCHECK(g_category_group_filters.Get()[index]); |
| 592 enabled_filters_bitmap |= 1 << index; | 592 enabled_filters_bitmap |= 1 << index; |
| 593 } | 593 } |
| 594 if (index++ >= MAX_TRACE_EVENT_FILTERS) { | 594 if (index++ >= MAX_TRACE_EVENT_FILTERS) { |
| 595 NOTREACHED(); | 595 NOTREACHED(); |
| 596 break; | 596 break; |
| 597 } | 597 } |
| 598 } | 598 } |
| 599 g_category_group_filters_enabled[category_index] = enabled_filters_bitmap; | 599 g_category_group_filters_enabled[category_index] = enabled_filters_bitmap; |
| 600 | 600 |
| 601 g_category_group_enabled[category_index] = enabled_flag; | 601 g_category_group_enabled[category_index] = enabled_flag; |
| 602 } | 602 } |
| 603 | 603 |
| 604 void TraceLog::UpdateCategoryGroupEnabledFlags() { | 604 void TraceLog::UpdateCategoryGroupEnabledFlags() { |
| 605 CreateFiltersForTraceConfig(); | 605 CreateFiltersForTraceConfig(); |
| 606 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); | 606 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); |
| 607 for (size_t i = 0; i < category_index; i++) | 607 for (size_t i = 0; i < category_index; i++) |
| 608 UpdateCategoryGroupEnabledFlag(i); | 608 UpdateCategoryGroupEnabledFlag(i); |
| 609 } | 609 } |
| 610 | 610 |
| 611 void TraceLog::CreateFiltersForTraceConfig() { | 611 void TraceLog::CreateFiltersForTraceConfig() { |
| 612 if (!(enabled_modes_ & FILTERING_MODE)) |
| 613 return; |
| 614 |
| 612 // Filters were already added and tracing could be enabled. Filters list | 615 // Filters were already added and tracing could be enabled. Filters list |
| 613 // cannot be changed when trace events are using them. | 616 // cannot be changed when trace events are using them. |
| 614 if (g_category_group_filters.Get().size()) | 617 if (g_category_group_filters.Get().size()) |
| 615 return; | 618 return; |
| 616 | 619 |
| 617 for (auto& event_filter : trace_config_.event_filters()) { | 620 for (auto& event_filter : enabled_event_filters_) { |
| 618 if (g_category_group_filters.Get().size() >= MAX_TRACE_EVENT_FILTERS) { | 621 if (g_category_group_filters.Get().size() >= MAX_TRACE_EVENT_FILTERS) { |
| 619 NOTREACHED() | 622 NOTREACHED() |
| 620 << "Too many trace event filters installed in the current session"; | 623 << "Too many trace event filters installed in the current session"; |
| 621 break; | 624 break; |
| 622 } | 625 } |
| 623 | 626 |
| 624 std::unique_ptr<TraceEventFilter> new_filter; | 627 std::unique_ptr<TraceEventFilter> new_filter; |
| 625 if (event_filter.predicate_name() == | 628 if (event_filter.predicate_name() == |
| 626 TraceEventFilter::kEventWhitelistPredicate) { | 629 TraceEventFilter::kEventWhitelistPredicate) { |
| 627 new_filter = MakeUnique<EventNameFilter>(event_filter.filter_args()); | 630 new_filter = MakeUnique<EventNameFilter>(event_filter.filter_args()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 723 } |
| 721 | 724 |
| 722 void TraceLog::GetKnownCategoryGroups( | 725 void TraceLog::GetKnownCategoryGroups( |
| 723 std::vector<std::string>* category_groups) { | 726 std::vector<std::string>* category_groups) { |
| 724 AutoLock lock(lock_); | 727 AutoLock lock(lock_); |
| 725 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); | 728 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); |
| 726 for (size_t i = kNumBuiltinCategories; i < category_index; i++) | 729 for (size_t i = kNumBuiltinCategories; i < category_index; i++) |
| 727 category_groups->push_back(g_category_groups[i]); | 730 category_groups->push_back(g_category_groups[i]); |
| 728 } | 731 } |
| 729 | 732 |
| 730 void TraceLog::SetEnabled(const TraceConfig& trace_config, Mode mode) { | 733 void TraceLog::SetEnabled(const TraceConfig& trace_config, |
| 734 uint8_t modes_to_enable) { |
| 731 std::vector<EnabledStateObserver*> observer_list; | 735 std::vector<EnabledStateObserver*> observer_list; |
| 732 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map; | 736 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map; |
| 733 { | 737 { |
| 734 AutoLock lock(lock_); | 738 AutoLock lock(lock_); |
| 735 | 739 |
| 736 // Can't enable tracing when Flush() is in progress. | 740 // Can't enable tracing when Flush() is in progress. |
| 737 DCHECK(!flush_task_runner_); | 741 DCHECK(!flush_task_runner_); |
| 738 | 742 |
| 739 InternalTraceOptions new_options = | 743 InternalTraceOptions new_options = |
| 740 GetInternalOptionsFromTraceConfig(trace_config); | 744 GetInternalOptionsFromTraceConfig(trace_config); |
| 741 | 745 |
| 742 InternalTraceOptions old_options = trace_options(); | 746 InternalTraceOptions old_options = trace_options(); |
| 743 | 747 |
| 744 if (IsEnabled()) { | |
| 745 if (new_options != old_options) { | |
| 746 DLOG(ERROR) << "Attempting to re-enable tracing with a different " | |
| 747 << "set of options."; | |
| 748 } | |
| 749 | |
| 750 if (mode != mode_) { | |
| 751 DLOG(ERROR) << "Attempting to re-enable tracing with a different mode."; | |
| 752 } | |
| 753 | |
| 754 DCHECK(!trace_config.event_filters().size()) | |
| 755 << "Adding new filters while tracing was already enabled is not " | |
| 756 "supported."; | |
| 757 | |
| 758 trace_config_.Merge(trace_config); | |
| 759 UpdateCategoryGroupEnabledFlags(); | |
| 760 return; | |
| 761 } | |
| 762 | |
| 763 if (dispatching_to_observer_list_) { | 748 if (dispatching_to_observer_list_) { |
| 764 DLOG(ERROR) | 749 NOTREACHED() |
| 765 << "Cannot manipulate TraceLog::Enabled state from an observer."; | 750 << "Cannot manipulate TraceLog::Enabled state from an observer."; |
| 766 return; | 751 return; |
| 767 } | 752 } |
| 768 | 753 |
| 769 mode_ = mode; | 754 // Clear all filters from previous tracing session. These filters are not |
| 755 // cleared at the end of tracing because some threads which hit trace event |
| 756 // when disabling, could try to use the filters. |
| 757 if (!enabled_modes_) |
| 758 g_category_group_filters.Get().clear(); |
| 759 |
| 760 // Update trace config for recording. |
| 761 const bool already_recording = enabled_modes_ & RECORDING_MODE; |
| 762 if (modes_to_enable & RECORDING_MODE) { |
| 763 if (already_recording) { |
| 764 // TODO(ssid): Stop suporting enabling of RECODING_MODE when already |
| 765 // enabled crbug.com/625170. |
| 766 DCHECK_EQ(new_options, old_options) << "Attempting to re-enable " |
| 767 "tracing with a different set " |
| 768 "of options."; |
| 769 trace_config_.Merge(trace_config); |
| 770 } else { |
| 771 trace_config_ = trace_config; |
| 772 } |
| 773 } |
| 774 |
| 775 // Update event filters. |
| 776 if (modes_to_enable & FILTERING_MODE) { |
| 777 DCHECK(!trace_config.event_filters().empty()) |
| 778 << "Attempting to enable filtering without any filters"; |
| 779 DCHECK(enabled_event_filters_.empty()) << "Attempting to re-enable " |
| 780 "filtering when filters are " |
| 781 "already enabled."; |
| 782 |
| 783 // Use the given event filters only if filtering was not enabled. |
| 784 if (enabled_event_filters_.empty()) |
| 785 enabled_event_filters_ = trace_config.event_filters(); |
| 786 } |
| 787 // Keep the |trace_config_| updated with only enabled filters in case anyone |
| 788 // tries to read it using |GetCurrentTraceConfig| (even if filters are |
| 789 // empty). |
| 790 trace_config_.SetEventFilters(enabled_event_filters_); |
| 791 |
| 792 enabled_modes_ |= modes_to_enable; |
| 793 UpdateCategoryGroupEnabledFlags(); |
| 794 |
| 795 // Do not notify observers or create trace buffer if only enabled for |
| 796 // filtering or if recording was already enabled. |
| 797 if (!(modes_to_enable & RECORDING_MODE) || already_recording) |
| 798 return; |
| 770 | 799 |
| 771 if (new_options != old_options) { | 800 if (new_options != old_options) { |
| 772 subtle::NoBarrier_Store(&trace_options_, new_options); | 801 subtle::NoBarrier_Store(&trace_options_, new_options); |
| 773 UseNextTraceBuffer(); | 802 UseNextTraceBuffer(); |
| 774 } | 803 } |
| 775 | 804 |
| 776 num_traces_recorded_++; | 805 num_traces_recorded_++; |
| 777 | 806 |
| 778 // Clear all filters from previous tracing session. These filters are not | |
| 779 // cleared at the end of tracing because some threads which hit trace event | |
| 780 // when disabling, could try to use the filters. | |
| 781 g_category_group_filters.Get().clear(); | |
| 782 | |
| 783 trace_config_ = TraceConfig(trace_config); | |
| 784 UpdateCategoryGroupEnabledFlags(); | 807 UpdateCategoryGroupEnabledFlags(); |
| 785 UpdateSyntheticDelaysFromTraceConfig(); | 808 UpdateSyntheticDelaysFromTraceConfig(); |
| 786 | 809 |
| 787 dispatching_to_observer_list_ = true; | 810 dispatching_to_observer_list_ = true; |
| 788 observer_list = enabled_state_observer_list_; | 811 observer_list = enabled_state_observer_list_; |
| 789 observer_map = async_observers_; | 812 observer_map = async_observers_; |
| 790 } | 813 } |
| 791 // Notify observers outside the lock in case they trigger trace events. | 814 // Notify observers outside the lock in case they trigger trace events. |
| 792 for (EnabledStateObserver* observer : observer_list) | 815 for (EnabledStateObserver* observer : observer_list) |
| 793 observer->OnTraceLogEnabled(); | 816 observer->OnTraceLogEnabled(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 return kInternalNone; | 853 return kInternalNone; |
| 831 } | 854 } |
| 832 | 855 |
| 833 TraceConfig TraceLog::GetCurrentTraceConfig() const { | 856 TraceConfig TraceLog::GetCurrentTraceConfig() const { |
| 834 AutoLock lock(lock_); | 857 AutoLock lock(lock_); |
| 835 return trace_config_; | 858 return trace_config_; |
| 836 } | 859 } |
| 837 | 860 |
| 838 void TraceLog::SetDisabled() { | 861 void TraceLog::SetDisabled() { |
| 839 AutoLock lock(lock_); | 862 AutoLock lock(lock_); |
| 840 SetDisabledWhileLocked(); | 863 SetDisabledWhileLocked(RECORDING_MODE); |
| 841 } | 864 } |
| 842 | 865 |
| 843 void TraceLog::SetDisabledWhileLocked() { | 866 void TraceLog::SetDisabled(uint8_t modes_to_disable) { |
| 867 AutoLock lock(lock_); |
| 868 SetDisabledWhileLocked(modes_to_disable); |
| 869 } |
| 870 |
| 871 void TraceLog::SetDisabledWhileLocked(uint8_t modes_to_disable) { |
| 844 lock_.AssertAcquired(); | 872 lock_.AssertAcquired(); |
| 845 | 873 |
| 846 if (!IsEnabled()) | 874 if (!(enabled_modes_ & modes_to_disable)) |
| 847 return; | 875 return; |
| 848 | 876 |
| 849 if (dispatching_to_observer_list_) { | 877 if (dispatching_to_observer_list_) { |
| 850 DLOG(ERROR) | 878 NOTREACHED() |
| 851 << "Cannot manipulate TraceLog::Enabled state from an observer."; | 879 << "Cannot manipulate TraceLog::Enabled state from an observer."; |
| 852 return; | 880 return; |
| 853 } | 881 } |
| 854 | 882 |
| 855 mode_ = DISABLED; | 883 bool is_recording_mode_disabled = |
| 884 (enabled_modes_ & RECORDING_MODE) && (modes_to_disable & RECORDING_MODE); |
| 885 enabled_modes_ &= ~modes_to_disable; |
| 856 | 886 |
| 857 trace_config_.Clear(); | 887 if (modes_to_disable & FILTERING_MODE) |
| 858 subtle::NoBarrier_Store(&watch_category_, 0); | 888 enabled_event_filters_.clear(); |
| 859 watch_event_name_.clear(); | 889 |
| 890 if (modes_to_disable & RECORDING_MODE) { |
| 891 trace_config_.Clear(); |
| 892 |
| 893 subtle::NoBarrier_Store(&watch_category_, 0); |
| 894 watch_event_name_.clear(); |
| 895 } |
| 896 |
| 860 UpdateCategoryGroupEnabledFlags(); | 897 UpdateCategoryGroupEnabledFlags(); |
| 898 |
| 899 // Add metadata events and notify observers only if recording mode was |
| 900 // disabled now. |
| 901 if (!is_recording_mode_disabled) |
| 902 return; |
| 903 |
| 861 AddMetadataEventsWhileLocked(); | 904 AddMetadataEventsWhileLocked(); |
| 862 | 905 |
| 863 // Remove metadata events so they will not get added to a subsequent trace. | 906 // Remove metadata events so they will not get added to a subsequent trace. |
| 864 metadata_events_.clear(); | 907 metadata_events_.clear(); |
| 865 | 908 |
| 866 dispatching_to_observer_list_ = true; | 909 dispatching_to_observer_list_ = true; |
| 867 std::vector<EnabledStateObserver*> observer_list = | 910 std::vector<EnabledStateObserver*> observer_list = |
| 868 enabled_state_observer_list_; | 911 enabled_state_observer_list_; |
| 869 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map = | 912 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map = |
| 870 async_observers_; | 913 async_observers_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 } | 993 } |
| 951 return trace_event; | 994 return trace_event; |
| 952 } | 995 } |
| 953 | 996 |
| 954 void TraceLog::CheckIfBufferIsFullWhileLocked() { | 997 void TraceLog::CheckIfBufferIsFullWhileLocked() { |
| 955 lock_.AssertAcquired(); | 998 lock_.AssertAcquired(); |
| 956 if (logged_events_->IsFull()) { | 999 if (logged_events_->IsFull()) { |
| 957 if (buffer_limit_reached_timestamp_.is_null()) { | 1000 if (buffer_limit_reached_timestamp_.is_null()) { |
| 958 buffer_limit_reached_timestamp_ = OffsetNow(); | 1001 buffer_limit_reached_timestamp_ = OffsetNow(); |
| 959 } | 1002 } |
| 960 SetDisabledWhileLocked(); | 1003 SetDisabledWhileLocked(RECORDING_MODE); |
| 961 } | 1004 } |
| 962 } | 1005 } |
| 963 | 1006 |
| 964 void TraceLog::SetEventCallbackEnabled(const TraceConfig& trace_config, | 1007 void TraceLog::SetEventCallbackEnabled(const TraceConfig& trace_config, |
| 965 EventCallback cb) { | 1008 EventCallback cb) { |
| 966 AutoLock lock(lock_); | 1009 AutoLock lock(lock_); |
| 967 subtle::NoBarrier_Store(&event_callback_, | 1010 subtle::NoBarrier_Store(&event_callback_, |
| 968 reinterpret_cast<subtle::AtomicWord>(cb)); | 1011 reinterpret_cast<subtle::AtomicWord>(cb)); |
| 969 event_callback_trace_config_ = trace_config; | 1012 event_callback_trace_config_ = trace_config; |
| 970 UpdateCategoryGroupEnabledFlags(); | 1013 UpdateCategoryGroupEnabledFlags(); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) { | 1380 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) { |
| 1338 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) || | 1381 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) || |
| 1339 (flags & TRACE_EVENT_FLAG_FLOW_OUT)) | 1382 (flags & TRACE_EVENT_FLAG_FLOW_OUT)) |
| 1340 bind_id = MangleEventId(bind_id); | 1383 bind_id = MangleEventId(bind_id); |
| 1341 id = MangleEventId(id); | 1384 id = MangleEventId(id); |
| 1342 } | 1385 } |
| 1343 | 1386 |
| 1344 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); | 1387 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); |
| 1345 ThreadTicks thread_now = ThreadNow(); | 1388 ThreadTicks thread_now = ThreadNow(); |
| 1346 | 1389 |
| 1347 // |thread_local_event_buffer_| can be null if the current thread doesn't have | 1390 ThreadLocalEventBuffer* thread_local_event_buffer = nullptr; |
| 1348 // a message loop or the message loop is blocked. | 1391 if (enabled_modes_ & RECORDING_MODE) { |
| 1349 InitializeThreadLocalEventBufferIfSupported(); | 1392 // |thread_local_event_buffer_| can be null if the current thread doesn't |
| 1350 auto* thread_local_event_buffer = thread_local_event_buffer_.Get(); | 1393 // have a message loop or the message loop is blocked. |
| 1394 InitializeThreadLocalEventBufferIfSupported(); |
| 1395 thread_local_event_buffer = thread_local_event_buffer_.Get(); |
| 1396 } |
| 1351 | 1397 |
| 1352 // Check and update the current thread name only if the event is for the | 1398 // Check and update the current thread name only if the event is for the |
| 1353 // current thread to avoid locks in most cases. | 1399 // current thread to avoid locks in most cases. |
| 1354 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) { | 1400 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) { |
| 1355 const char* new_name = | 1401 const char* new_name = |
| 1356 ThreadIdNameManager::GetInstance()->GetName(thread_id); | 1402 ThreadIdNameManager::GetInstance()->GetName(thread_id); |
| 1357 // Check if the thread name has been set or changed since the previous | 1403 // Check if the thread name has been set or changed since the previous |
| 1358 // call (if any), but don't bother if the new name is empty. Note this will | 1404 // call (if any), but don't bother if the new name is empty. Note this will |
| 1359 // not detect a thread name change within the same char* buffer address: we | 1405 // not detect a thread name change within the same char* buffer address: we |
| 1360 // favor common case performance over corner case correctness. | 1406 // favor common case performance over corner case correctness. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 } | 1971 } |
| 1926 | 1972 |
| 1927 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 1973 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 1928 if (*category_group_enabled_) { | 1974 if (*category_group_enabled_) { |
| 1929 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, | 1975 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, |
| 1930 event_handle_); | 1976 event_handle_); |
| 1931 } | 1977 } |
| 1932 } | 1978 } |
| 1933 | 1979 |
| 1934 } // namespace trace_event_internal | 1980 } // namespace trace_event_internal |
| OLD | NEW |