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

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

Issue 2323483005: [tracing] Add filtering mode in TraceLog (Closed)
Patch Set: Created 4 years, 3 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
« base/trace_event/trace_log.h ('K') | « base/trace_event/trace_log.h ('k') | no next file » | 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 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 TraceLogStatus::TraceLogStatus() : event_capacity(0), event_count(0) {} 458 TraceLogStatus::TraceLogStatus() : event_capacity(0), event_count(0) {}
459 459
460 TraceLogStatus::~TraceLogStatus() {} 460 TraceLogStatus::~TraceLogStatus() {}
461 461
462 // static 462 // static
463 TraceLog* TraceLog::GetInstance() { 463 TraceLog* TraceLog::GetInstance() {
464 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get(); 464 return Singleton<TraceLog, LeakySingletonTraits<TraceLog>>::get();
465 } 465 }
466 466
467 TraceLog::TraceLog() 467 TraceLog::TraceLog()
468 : mode_(DISABLED), 468 : mode_(0),
469 num_traces_recorded_(0), 469 num_traces_recorded_(0),
470 event_callback_(0), 470 event_callback_(0),
471 dispatching_to_observer_list_(false), 471 dispatching_to_observer_list_(false),
472 process_sort_index_(0), 472 process_sort_index_(0),
473 process_id_hash_(0), 473 process_id_hash_(0),
474 process_id_(0), 474 process_id_(0),
475 watch_category_(0), 475 watch_category_(0),
476 trace_options_(kInternalRecordUntilFull), 476 trace_options_(kInternalRecordUntilFull),
477 sampling_thread_handle_(0), 477 sampling_thread_handle_(0),
478 trace_config_(TraceConfig()), 478 trace_config_(TraceConfig()),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 557 }
558 558
559 const char* TraceLog::GetCategoryGroupName( 559 const char* TraceLog::GetCategoryGroupName(
560 const unsigned char* category_group_enabled) { 560 const unsigned char* category_group_enabled) {
561 return g_category_groups[GetCategoryIndex(category_group_enabled)]; 561 return g_category_groups[GetCategoryIndex(category_group_enabled)];
562 } 562 }
563 563
564 void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) { 564 void TraceLog::UpdateCategoryGroupEnabledFlag(size_t category_index) {
565 unsigned char enabled_flag = 0; 565 unsigned char enabled_flag = 0;
566 const char* category_group = g_category_groups[category_index]; 566 const char* category_group = g_category_groups[category_index];
567 if (mode_ == RECORDING_MODE && 567 if (mode_ & RECORDING_MODE &&
568 trace_config_.IsCategoryGroupEnabled(category_group)) { 568 trace_config_.IsCategoryGroupEnabled(category_group)) {
569 enabled_flag |= ENABLED_FOR_RECORDING; 569 enabled_flag |= ENABLED_FOR_RECORDING;
570 } 570 }
571 571
572 if (event_callback_ && 572 if (event_callback_ &&
573 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) { 573 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) {
574 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; 574 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK;
575 } 575 }
576 576
577 #if defined(OS_WIN) 577 #if defined(OS_WIN)
578 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled( 578 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled(
579 category_group)) { 579 category_group)) {
580 enabled_flag |= ENABLED_FOR_ETW_EXPORT; 580 enabled_flag |= ENABLED_FOR_ETW_EXPORT;
581 } 581 }
582 #endif 582 #endif
583 583
584 // TODO(primiano): this is a temporary workaround for catapult:#2341, 584 // TODO(primiano): this is a temporary workaround for catapult:#2341,
585 // to guarantee that metadata events are always added even if the category 585 // to guarantee that metadata events are always added even if the category
586 // filter is "-*". See crbug.com/618054 for more details and long-term fix. 586 // filter is "-*". See crbug.com/618054 for more details and long-term fix.
587 if (mode_ == RECORDING_MODE && !strcmp(category_group, "__metadata")) 587 if (mode_ & RECORDING_MODE && !strcmp(category_group, "__metadata"))
588 enabled_flag |= ENABLED_FOR_RECORDING; 588 enabled_flag |= ENABLED_FOR_RECORDING;
589 589
590 uint32_t enabled_filters_bitmap = 0; 590 uint32_t enabled_filters_bitmap = 0;
591 int index = 0; 591 int index = 0;
592 for (const auto& event_filter : trace_config_.event_filters()) { 592 for (const auto& event_filter : event_filters_enabled_) {
593 if (event_filter.IsCategoryGroupEnabled(category_group)) { 593 if (event_filter.IsCategoryGroupEnabled(category_group)) {
594 enabled_flag |= ENABLED_FOR_FILTERING; 594 enabled_flag |= ENABLED_FOR_FILTERING;
595 DCHECK(g_category_group_filters.Get()[index]); 595 DCHECK(g_category_group_filters.Get()[index]);
596 enabled_filters_bitmap |= 1 << index; 596 enabled_filters_bitmap |= 1 << index;
597 } 597 }
598 if (index++ >= MAX_TRACE_EVENT_FILTERS) { 598 if (index++ >= MAX_TRACE_EVENT_FILTERS) {
599 NOTREACHED(); 599 NOTREACHED();
600 break; 600 break;
601 } 601 }
602 } 602 }
603 g_category_group_filters_enabled[category_index] = enabled_filters_bitmap; 603 g_category_group_filters_enabled[category_index] = enabled_filters_bitmap;
604 604
605 g_category_group_enabled[category_index] = enabled_flag; 605 g_category_group_enabled[category_index] = enabled_flag;
606 } 606 }
607 607
608 void TraceLog::UpdateCategoryGroupEnabledFlags() { 608 void TraceLog::UpdateCategoryGroupEnabledFlags() {
609 CreateFiltersForTraceConfig(); 609 CreateFiltersForTraceConfig();
610 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); 610 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index);
611 for (size_t i = 0; i < category_index; i++) 611 for (size_t i = 0; i < category_index; i++)
612 UpdateCategoryGroupEnabledFlag(i); 612 UpdateCategoryGroupEnabledFlag(i);
613 } 613 }
614 614
615 void TraceLog::CreateFiltersForTraceConfig() { 615 void TraceLog::CreateFiltersForTraceConfig() {
616 // Filters were already added and tracing could be enabled. Filters list 616 // Filters were already added and tracing could be enabled. Filters list
617 // cannot be changed when trace events are using them. 617 // cannot be changed when trace events are using them.
618 if (g_category_group_filters.Get().size()) 618 if (g_category_group_filters.Get().size())
619 return; 619 return;
620 620
621 for (auto& event_filter : trace_config_.event_filters()) { 621 for (auto& event_filter : event_filters_enabled_) {
622 if (g_category_group_filters.Get().size() >= MAX_TRACE_EVENT_FILTERS) { 622 if (g_category_group_filters.Get().size() >= MAX_TRACE_EVENT_FILTERS) {
623 NOTREACHED() 623 NOTREACHED()
624 << "Too many trace event filters installed in the current session"; 624 << "Too many trace event filters installed in the current session";
625 break; 625 break;
626 } 626 }
627 627
628 std::unique_ptr<TraceEventFilter> new_filter; 628 std::unique_ptr<TraceEventFilter> new_filter;
629 if (event_filter.predicate_name() == 629 if (event_filter.predicate_name() ==
630 TraceEventFilter::kEventWhitelistPredicate) { 630 TraceEventFilter::kEventWhitelistPredicate) {
631 new_filter = MakeUnique<EventNameFilter>(event_filter.filter_args()); 631 new_filter = MakeUnique<EventNameFilter>(event_filter.filter_args());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 724 }
725 725
726 void TraceLog::GetKnownCategoryGroups( 726 void TraceLog::GetKnownCategoryGroups(
727 std::vector<std::string>* category_groups) { 727 std::vector<std::string>* category_groups) {
728 AutoLock lock(lock_); 728 AutoLock lock(lock_);
729 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index); 729 size_t category_index = base::subtle::NoBarrier_Load(&g_category_index);
730 for (size_t i = kNumBuiltinCategories; i < category_index; i++) 730 for (size_t i = kNumBuiltinCategories; i < category_index; i++)
731 category_groups->push_back(g_category_groups[i]); 731 category_groups->push_back(g_category_groups[i]);
732 } 732 }
733 733
734 void TraceLog::SetEnabled(const TraceConfig& trace_config, Mode mode) { 734 void TraceLog::SetEnabled(const TraceConfig& trace_config, Mode new_mode) {
735 std::vector<EnabledStateObserver*> observer_list; 735 std::vector<EnabledStateObserver*> observer_list;
736 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map; 736 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map;
737 { 737 {
738 AutoLock lock(lock_); 738 AutoLock lock(lock_);
739 739
740 // Can't enable tracing when Flush() is in progress. 740 // Can't enable tracing when Flush() is in progress.
741 DCHECK(!flush_task_runner_); 741 DCHECK(!flush_task_runner_);
742 742
743 InternalTraceOptions new_options = 743 InternalTraceOptions new_options =
744 GetInternalOptionsFromTraceConfig(trace_config); 744 GetInternalOptionsFromTraceConfig(trace_config);
745 745
746 InternalTraceOptions old_options = trace_options(); 746 InternalTraceOptions old_options = trace_options();
747 747
748 if (IsEnabled()) {
749 if (new_options != old_options) {
750 DLOG(ERROR) << "Attempting to re-enable tracing with a different "
751 << "set of options.";
752 }
753
754 if (mode != mode_) {
755 DLOG(ERROR) << "Attempting to re-enable tracing with a different mode.";
756 }
757
758 DCHECK(!trace_config.event_filters().size())
759 << "Adding new filters while tracing was already enabled is not "
760 "supported.";
761
762 trace_config_.Merge(trace_config);
763 UpdateCategoryGroupEnabledFlags();
764 return;
765 }
766
767 if (dispatching_to_observer_list_) { 748 if (dispatching_to_observer_list_) {
768 DLOG(ERROR) 749 NOTREACHED()
769 << "Cannot manipulate TraceLog::Enabled state from an observer."; 750 << "Cannot manipulate TraceLog::Enabled state from an observer.";
770 return; 751 return;
771 } 752 }
772 753
773 mode_ = mode; 754 // Update event filters:
755 DCHECK(
756 !(new_mode == FILTERING_MODE && trace_config.event_filters().empty()))
757 << "Attempting to enable filtering without any filters";
758 if (!mode_) {
759 // Clear all filters from previous tracing session. These filters are not
760 // cleared at the end of tracing because some threads which hit trace
761 // event when disabling, could try to use the filters.
762 g_category_group_filters.Get().clear();
763 }
764 if (event_filters_enabled_.empty()) {
765 // Use the given event filters only if filtering was not enabled.
766 event_filters_enabled_ = trace_config.event_filters();
767 } else if (new_mode == FILTERING_MODE) {
768 NOTREACHED() << "Attempting to re-enable filtering when filters are "
769 "already enabled.";
770 return;
771 }
772
773 // Update trace config for recording.
774 bool already_recording = mode_ & RECORDING_MODE;
775 if (new_mode == RECORDING_MODE) {
776 if (already_recording) {
777 DCHECK_EQ(new_options, old_options) << "Attempting to re-enable "
778 "tracing with a different set "
779 "of options.";
780 trace_config_.Merge(trace_config);
781 } else {
782 trace_config_ = trace_config;
783 }
784 }
785 // Keep the |trace_config_| updated with only enabled filters in case anyone
786 // tries to read it using |GetCurrentTraceConfig|
787 trace_config_.SetEventFilterConfigs(event_filters_enabled_);
788
789 mode_ |= new_mode;
790 UpdateCategoryGroupEnabledFlags();
791
792 // Do not notify observers and create trace buffer if enabled for filtering
793 // or if recording was already enabled.
794 if (new_mode == FILTERING_MODE || already_recording)
795 return;
774 796
775 if (new_options != old_options) { 797 if (new_options != old_options) {
776 subtle::NoBarrier_Store(&trace_options_, new_options); 798 subtle::NoBarrier_Store(&trace_options_, new_options);
777 UseNextTraceBuffer(); 799 UseNextTraceBuffer();
778 } 800 }
779 801
780 num_traces_recorded_++; 802 num_traces_recorded_++;
781 803
782 // Clear all filters from previous tracing session. These filters are not
783 // cleared at the end of tracing because some threads which hit trace event
784 // when disabling, could try to use the filters.
785 g_category_group_filters.Get().clear();
786
787 trace_config_ = TraceConfig(trace_config);
788 UpdateCategoryGroupEnabledFlags(); 804 UpdateCategoryGroupEnabledFlags();
789 UpdateSyntheticDelaysFromTraceConfig(); 805 UpdateSyntheticDelaysFromTraceConfig();
790 806
791 if (new_options & kInternalEnableSampling) { 807 if (new_options & kInternalEnableSampling) {
792 sampling_thread_.reset(new TraceSamplingThread); 808 sampling_thread_.reset(new TraceSamplingThread);
793 sampling_thread_->RegisterSampleBucket( 809 sampling_thread_->RegisterSampleBucket(
794 &g_trace_state[0], "bucket0", 810 &g_trace_state[0], "bucket0",
795 Bind(&TraceSamplingThread::DefaultSamplingCallback)); 811 Bind(&TraceSamplingThread::DefaultSamplingCallback));
796 sampling_thread_->RegisterSampleBucket( 812 sampling_thread_->RegisterSampleBucket(
797 &g_trace_state[1], "bucket1", 813 &g_trace_state[1], "bucket1",
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 return kInternalNone; 868 return kInternalNone;
853 } 869 }
854 870
855 TraceConfig TraceLog::GetCurrentTraceConfig() const { 871 TraceConfig TraceLog::GetCurrentTraceConfig() const {
856 AutoLock lock(lock_); 872 AutoLock lock(lock_);
857 return trace_config_; 873 return trace_config_;
858 } 874 }
859 875
860 void TraceLog::SetDisabled() { 876 void TraceLog::SetDisabled() {
861 AutoLock lock(lock_); 877 AutoLock lock(lock_);
862 SetDisabledWhileLocked(); 878 SetDisabledWhileLocked(RECORDING_MODE);
863 } 879 }
864 880
865 void TraceLog::SetDisabledWhileLocked() { 881 void TraceLog::SetDisabled(Mode mode) {
882 AutoLock lock(lock_);
883 SetDisabledWhileLocked(mode);
884 }
885
886 void TraceLog::SetDisabledWhileLocked(Mode mode) {
866 lock_.AssertAcquired(); 887 lock_.AssertAcquired();
867 888
868 if (!IsEnabled()) 889 if (!(mode_ & mode))
869 return; 890 return;
870 891
871 if (dispatching_to_observer_list_) { 892 if (dispatching_to_observer_list_) {
872 DLOG(ERROR) 893 NOTREACHED()
873 << "Cannot manipulate TraceLog::Enabled state from an observer."; 894 << "Cannot manipulate TraceLog::Enabled state from an observer.";
874 return; 895 return;
875 } 896 }
876 897
877 mode_ = DISABLED;
878
879 if (sampling_thread_) { 898 if (sampling_thread_) {
880 // Stop the sampling thread. 899 // Stop the sampling thread.
881 sampling_thread_->Stop(); 900 sampling_thread_->Stop();
882 lock_.Release(); 901 lock_.Release();
883 PlatformThread::Join(sampling_thread_handle_); 902 PlatformThread::Join(sampling_thread_handle_);
884 lock_.Acquire(); 903 lock_.Acquire();
885 sampling_thread_handle_ = PlatformThreadHandle(); 904 sampling_thread_handle_ = PlatformThreadHandle();
886 sampling_thread_.reset(); 905 sampling_thread_.reset();
887 } 906 }
888 907
889 trace_config_.Clear(); 908 mode_ &= ~mode;
909 if (mode == RECORDING_MODE)
910 trace_config_.Clear();
911 // Clear the filters if tracing is no longer enabled or filtering is disabled.
912 if (!mode || mode == FILTERING_MODE)
913 event_filters_enabled_.clear();
914
890 subtle::NoBarrier_Store(&watch_category_, 0); 915 subtle::NoBarrier_Store(&watch_category_, 0);
891 watch_event_name_.clear(); 916 watch_event_name_.clear();
892 UpdateCategoryGroupEnabledFlags(); 917 UpdateCategoryGroupEnabledFlags();
918
919 // Skip adding metadata events and notifying observers for filtering mode.
920 if (mode == FILTERING_MODE)
921 return;
922
893 AddMetadataEventsWhileLocked(); 923 AddMetadataEventsWhileLocked();
894 924
895 // Remove metadata events so they will not get added to a subsequent trace. 925 // Remove metadata events so they will not get added to a subsequent trace.
896 metadata_events_.clear(); 926 metadata_events_.clear();
897 927
898 dispatching_to_observer_list_ = true; 928 dispatching_to_observer_list_ = true;
899 std::vector<EnabledStateObserver*> observer_list = 929 std::vector<EnabledStateObserver*> observer_list =
900 enabled_state_observer_list_; 930 enabled_state_observer_list_;
901 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map = 931 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map =
902 async_observers_; 932 async_observers_;
903 933
904 { 934 {
905 // Dispatch to observers outside the lock in case the observer triggers a 935 // Dispatch to observers outside the lock in case the observer triggers a
906 // trace event. 936 // trace event.
907 AutoUnlock unlock(lock_); 937 AutoUnlock unlock(lock_);
908 for (EnabledStateObserver* observer : observer_list) 938 for (EnabledStateObserver* observer : observer_list)
909 observer->OnTraceLogDisabled(); 939 observer->OnTraceLogDisabled();
910 for (const auto& it : observer_map) { 940 for (const auto& it : observer_map) {
911 it.second.task_runner->PostTask( 941 it.second.task_runner->PostTask(
912 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogDisabled, 942 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogDisabled,
913 it.second.observer)); 943 it.second.observer));
914 } 944 }
915 } 945 }
916 dispatching_to_observer_list_ = false; 946 dispatching_to_observer_list_ = false;
917 } 947 }
918 948
949 bool TraceLog::IsFilteringEnabled() {
950 AutoLock lock(lock_);
951 return !event_filters_enabled_.empty();
952 }
953
919 int TraceLog::GetNumTracesRecorded() { 954 int TraceLog::GetNumTracesRecorded() {
920 AutoLock lock(lock_); 955 AutoLock lock(lock_);
921 if (!IsEnabled()) 956 if (!IsEnabled())
922 return -1; 957 return -1;
923 return num_traces_recorded_; 958 return num_traces_recorded_;
924 } 959 }
925 960
926 void TraceLog::AddEnabledStateObserver(EnabledStateObserver* listener) { 961 void TraceLog::AddEnabledStateObserver(EnabledStateObserver* listener) {
927 AutoLock lock(lock_); 962 AutoLock lock(lock_);
928 enabled_state_observer_list_.push_back(listener); 963 enabled_state_observer_list_.push_back(listener);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 1017 }
983 return trace_event; 1018 return trace_event;
984 } 1019 }
985 1020
986 void TraceLog::CheckIfBufferIsFullWhileLocked() { 1021 void TraceLog::CheckIfBufferIsFullWhileLocked() {
987 lock_.AssertAcquired(); 1022 lock_.AssertAcquired();
988 if (logged_events_->IsFull()) { 1023 if (logged_events_->IsFull()) {
989 if (buffer_limit_reached_timestamp_.is_null()) { 1024 if (buffer_limit_reached_timestamp_.is_null()) {
990 buffer_limit_reached_timestamp_ = OffsetNow(); 1025 buffer_limit_reached_timestamp_ = OffsetNow();
991 } 1026 }
992 SetDisabledWhileLocked(); 1027 SetDisabledWhileLocked(RECORDING_MODE);
993 } 1028 }
994 } 1029 }
995 1030
996 void TraceLog::SetEventCallbackEnabled(const TraceConfig& trace_config, 1031 void TraceLog::SetEventCallbackEnabled(const TraceConfig& trace_config,
997 EventCallback cb) { 1032 EventCallback cb) {
998 AutoLock lock(lock_); 1033 AutoLock lock(lock_);
999 subtle::NoBarrier_Store(&event_callback_, 1034 subtle::NoBarrier_Store(&event_callback_,
1000 reinterpret_cast<subtle::AtomicWord>(cb)); 1035 reinterpret_cast<subtle::AtomicWord>(cb));
1001 event_callback_trace_config_ = trace_config; 1036 event_callback_trace_config_ = trace_config;
1002 UpdateCategoryGroupEnabledFlags(); 1037 UpdateCategoryGroupEnabledFlags();
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) { 1404 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) {
1370 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) || 1405 if ((flags & TRACE_EVENT_FLAG_FLOW_IN) ||
1371 (flags & TRACE_EVENT_FLAG_FLOW_OUT)) 1406 (flags & TRACE_EVENT_FLAG_FLOW_OUT))
1372 bind_id = MangleEventId(bind_id); 1407 bind_id = MangleEventId(bind_id);
1373 id = MangleEventId(id); 1408 id = MangleEventId(id);
1374 } 1409 }
1375 1410
1376 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp); 1411 TimeTicks offset_event_timestamp = OffsetTimestamp(timestamp);
1377 ThreadTicks thread_now = ThreadNow(); 1412 ThreadTicks thread_now = ThreadNow();
1378 1413
1379 // |thread_local_event_buffer_| can be null if the current thread doesn't have
1380 // a message loop or the message loop is blocked.
1381 InitializeThreadLocalEventBufferIfSupported();
1382 auto* thread_local_event_buffer = thread_local_event_buffer_.Get();
1383
1384 // Check and update the current thread name only if the event is for the 1414 // Check and update the current thread name only if the event is for the
1385 // current thread to avoid locks in most cases. 1415 // current thread to avoid locks in most cases.
1386 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) { 1416 if (thread_id == static_cast<int>(PlatformThread::CurrentId())) {
1387 const char* new_name = 1417 const char* new_name =
1388 ThreadIdNameManager::GetInstance()->GetName(thread_id); 1418 ThreadIdNameManager::GetInstance()->GetName(thread_id);
1389 // Check if the thread name has been set or changed since the previous 1419 // Check if the thread name has been set or changed since the previous
1390 // call (if any), but don't bother if the new name is empty. Note this will 1420 // call (if any), but don't bother if the new name is empty. Note this will
1391 // not detect a thread name change within the same char* buffer address: we 1421 // not detect a thread name change within the same char* buffer address: we
1392 // favor common case performance over corner case correctness. 1422 // favor common case performance over corner case correctness.
1393 if (new_name != g_current_thread_name.Get().Get() && new_name && 1423 if (new_name != g_current_thread_name.Get().Get() && new_name &&
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 disabled_by_filters = false; 1475 disabled_by_filters = false;
1446 }); 1476 });
1447 if (!disabled_by_filters) 1477 if (!disabled_by_filters)
1448 filtered_trace_event = std::move(new_trace_event); 1478 filtered_trace_event = std::move(new_trace_event);
1449 } 1479 }
1450 1480
1451 // If enabled for recording, the event should be added only if one of the 1481 // If enabled for recording, the event should be added only if one of the
1452 // filters indicates or category is not enabled for filtering. 1482 // filters indicates or category is not enabled for filtering.
1453 if ((*category_group_enabled & ENABLED_FOR_RECORDING) && 1483 if ((*category_group_enabled & ENABLED_FOR_RECORDING) &&
1454 !disabled_by_filters) { 1484 !disabled_by_filters) {
1485 // |thread_local_event_buffer_| can be null if the current thread doesn't
1486 // have a message loop or the message loop is blocked.
1487 InitializeThreadLocalEventBufferIfSupported();
1488 auto* thread_local_event_buffer = thread_local_event_buffer_.Get();
1489
1455 OptionalAutoLock lock(&lock_); 1490 OptionalAutoLock lock(&lock_);
1456 1491
1457 TraceEvent* trace_event = NULL; 1492 TraceEvent* trace_event = NULL;
1458 if (thread_local_event_buffer) { 1493 if (thread_local_event_buffer) {
1459 trace_event = thread_local_event_buffer->AddTraceEvent(&handle); 1494 trace_event = thread_local_event_buffer->AddTraceEvent(&handle);
1460 } else { 1495 } else {
1461 lock.EnsureAcquired(); 1496 lock.EnsureAcquired();
1462 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true); 1497 trace_event = AddEventToThreadSharedChunkWhileLocked(&handle, true);
1463 } 1498 }
1464 1499
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1963 } 1998 }
1964 1999
1965 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 2000 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1966 if (*category_group_enabled_) { 2001 if (*category_group_enabled_) {
1967 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 2002 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1968 event_handle_); 2003 event_handle_);
1969 } 2004 }
1970 } 2005 }
1971 2006
1972 } // namespace trace_event_internal 2007 } // namespace trace_event_internal
OLDNEW
« base/trace_event/trace_log.h ('K') | « base/trace_event/trace_log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698