| 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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 NOTREACHED(); | 811 NOTREACHED(); |
| 812 return kInternalNone; | 812 return kInternalNone; |
| 813 } | 813 } |
| 814 | 814 |
| 815 TraceConfig TraceLog::GetCurrentTraceConfig() const { | 815 TraceConfig TraceLog::GetCurrentTraceConfig() const { |
| 816 AutoLock lock(lock_); | 816 AutoLock lock(lock_); |
| 817 return trace_config_; | 817 return trace_config_; |
| 818 } | 818 } |
| 819 | 819 |
| 820 void TraceLog::SetDisabled() { | 820 void TraceLog::SetDisabled() { |
| 821 AutoLock lock(lock_); | 821 AutoLock lock1(disabling_lock_); |
| 822 AutoLock lock2(lock_); |
| 822 SetDisabledWhileLocked(); | 823 SetDisabledWhileLocked(); |
| 823 } | 824 } |
| 824 | 825 |
| 825 void TraceLog::SetDisabledWhileLocked() { | 826 void TraceLog::SetDisabledWhileLocked() { |
| 826 lock_.AssertAcquired(); | 827 lock_.AssertAcquired(); |
| 827 | 828 |
| 828 if (!IsEnabled()) | 829 if (!IsEnabled()) |
| 829 return; | 830 return; |
| 830 | 831 |
| 831 if (dispatching_to_observer_list_) { | 832 if (dispatching_to_observer_list_) { |
| 832 DLOG(ERROR) | 833 DLOG(ERROR) |
| 833 << "Cannot manipulate TraceLog::Enabled state from an observer."; | 834 << "Cannot manipulate TraceLog::Enabled state from an observer."; |
| 834 return; | 835 return; |
| 835 } | 836 } |
| 836 | 837 |
| 838 std::vector<EnabledStateObserver*> observer_list = |
| 839 enabled_state_observer_list_; |
| 840 dispatching_to_observer_list_ = true; |
| 841 { |
| 842 // Dispatch to observers outside the lock in case the observer triggers a |
| 843 // trace event. |
| 844 AutoUnlock unlock(lock_); |
| 845 for (EnabledStateObserver* observer : observer_list) |
| 846 observer->OnBeforeTraceLogDisabled(); |
| 847 } |
| 848 dispatching_to_observer_list_ = false; |
| 849 |
| 837 mode_ = DISABLED; | 850 mode_ = DISABLED; |
| 838 | 851 |
| 839 if (sampling_thread_) { | 852 if (sampling_thread_) { |
| 840 // Stop the sampling thread. | 853 // Stop the sampling thread. |
| 841 sampling_thread_->Stop(); | 854 sampling_thread_->Stop(); |
| 842 lock_.Release(); | 855 lock_.Release(); |
| 843 PlatformThread::Join(sampling_thread_handle_); | 856 PlatformThread::Join(sampling_thread_handle_); |
| 844 lock_.Acquire(); | 857 lock_.Acquire(); |
| 845 sampling_thread_handle_ = PlatformThreadHandle(); | 858 sampling_thread_handle_ = PlatformThreadHandle(); |
| 846 sampling_thread_.reset(); | 859 sampling_thread_.reset(); |
| 847 } | 860 } |
| 848 | 861 |
| 849 trace_config_.Clear(); | 862 trace_config_.Clear(); |
| 850 subtle::NoBarrier_Store(&watch_category_, 0); | 863 subtle::NoBarrier_Store(&watch_category_, 0); |
| 851 watch_event_name_.clear(); | 864 watch_event_name_.clear(); |
| 852 UpdateCategoryGroupEnabledFlags(); | 865 UpdateCategoryGroupEnabledFlags(); |
| 853 AddMetadataEventsWhileLocked(); | 866 AddMetadataEventsWhileLocked(); |
| 854 | 867 |
| 855 // Remove metadata events so they will not get added to a subsequent trace. | 868 // Remove metadata events so they will not get added to a subsequent trace. |
| 856 metadata_events_.clear(); | 869 metadata_events_.clear(); |
| 857 | 870 |
| 858 dispatching_to_observer_list_ = true; | |
| 859 std::vector<EnabledStateObserver*> observer_list = | |
| 860 enabled_state_observer_list_; | |
| 861 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map = | 871 std::map<AsyncEnabledStateObserver*, RegisteredAsyncObserver> observer_map = |
| 862 async_observers_; | 872 async_observers_; |
| 863 | 873 dispatching_to_observer_list_ = true; |
| 864 { | 874 { |
| 865 // Dispatch to observers outside the lock in case the observer triggers a | 875 // Dispatch to observers outside the lock in case the observer triggers a |
| 866 // trace event. | 876 // trace event. |
| 867 AutoUnlock unlock(lock_); | 877 AutoUnlock unlock(lock_); |
| 868 for (EnabledStateObserver* observer : observer_list) | 878 for (EnabledStateObserver* observer : observer_list) |
| 869 observer->OnTraceLogDisabled(); | 879 observer->OnTraceLogDisabled(); |
| 870 for (const auto& it : observer_map) { | 880 for (const auto& it : observer_map) { |
| 871 it.second.task_runner->PostTask( | 881 it.second.task_runner->PostTask( |
| 872 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogDisabled, | 882 FROM_HERE, Bind(&AsyncEnabledStateObserver::OnTraceLogDisabled, |
| 873 it.second.observer)); | 883 it.second.observer)); |
| (...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 } | 1933 } |
| 1924 | 1934 |
| 1925 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 1935 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 1926 if (*category_group_enabled_) { | 1936 if (*category_group_enabled_) { |
| 1927 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, | 1937 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, |
| 1928 event_handle_); | 1938 event_handle_); |
| 1929 } | 1939 } |
| 1930 } | 1940 } |
| 1931 | 1941 |
| 1932 } // namespace trace_event_internal | 1942 } // namespace trace_event_internal |
| OLD | NEW |