| 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/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 if (!(ret & RECORD_UNTIL_FULL) && !(ret & RECORD_CONTINUOUSLY)) | 768 if (!(ret & RECORD_UNTIL_FULL) && !(ret & RECORD_CONTINUOUSLY)) |
| 769 ret |= RECORD_UNTIL_FULL; // Default when no options are specified. | 769 ret |= RECORD_UNTIL_FULL; // Default when no options are specified. |
| 770 | 770 |
| 771 return static_cast<Options>(ret); | 771 return static_cast<Options>(ret); |
| 772 } | 772 } |
| 773 | 773 |
| 774 TraceLog::TraceLog() | 774 TraceLog::TraceLog() |
| 775 : enable_count_(0), | 775 : enable_count_(0), |
| 776 num_traces_recorded_(0), |
| 776 logged_events_(NULL), | 777 logged_events_(NULL), |
| 777 dispatching_to_observer_list_(false), | 778 dispatching_to_observer_list_(false), |
| 778 watch_category_(NULL), | 779 watch_category_(NULL), |
| 779 trace_options_(RECORD_UNTIL_FULL), | 780 trace_options_(RECORD_UNTIL_FULL), |
| 780 sampling_thread_handle_(0), | 781 sampling_thread_handle_(0), |
| 781 category_filter_(CategoryFilter::kDefaultCategoryFilterString) { | 782 category_filter_(CategoryFilter::kDefaultCategoryFilterString) { |
| 782 // Trace is enabled or disabled on one thread while other threads are | 783 // Trace is enabled or disabled on one thread while other threads are |
| 783 // accessing the enabled flag. We don't care whether edge-case events are | 784 // accessing the enabled flag. We don't care whether edge-case events are |
| 784 // traced or not, so we allow races on the enabled flag to keep the trace | 785 // traced or not, so we allow races on the enabled flag to keep the trace |
| 785 // macros fast. | 786 // macros fast. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 trace_options_ = options; | 921 trace_options_ = options; |
| 921 logged_events_.reset(GetTraceBuffer()); | 922 logged_events_.reset(GetTraceBuffer()); |
| 922 } | 923 } |
| 923 | 924 |
| 924 if (dispatching_to_observer_list_) { | 925 if (dispatching_to_observer_list_) { |
| 925 DLOG(ERROR) << | 926 DLOG(ERROR) << |
| 926 "Cannot manipulate TraceLog::Enabled state from an observer."; | 927 "Cannot manipulate TraceLog::Enabled state from an observer."; |
| 927 return; | 928 return; |
| 928 } | 929 } |
| 929 | 930 |
| 931 num_traces_recorded_++; |
| 932 |
| 930 dispatching_to_observer_list_ = true; | 933 dispatching_to_observer_list_ = true; |
| 931 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, | 934 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, |
| 932 OnTraceLogWillEnable()); | 935 OnTraceLogWillEnable()); |
| 933 dispatching_to_observer_list_ = false; | 936 dispatching_to_observer_list_ = false; |
| 934 | 937 |
| 935 category_filter_ = CategoryFilter(category_filter); | 938 category_filter_ = CategoryFilter(category_filter); |
| 936 EnableIncludedCategoryGroups(); | 939 EnableIncludedCategoryGroups(); |
| 937 | 940 |
| 938 // Not supported in split-dll build. http://crbug.com/237249 | 941 // Not supported in split-dll build. http://crbug.com/237249 |
| 939 #if !defined(CHROME_SPLIT_DLL) | 942 #if !defined(CHROME_SPLIT_DLL) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 dispatching_to_observer_list_ = false; | 997 dispatching_to_observer_list_ = false; |
| 995 | 998 |
| 996 category_filter_.Clear(); | 999 category_filter_.Clear(); |
| 997 watch_category_ = NULL; | 1000 watch_category_ = NULL; |
| 998 watch_event_name_ = ""; | 1001 watch_event_name_ = ""; |
| 999 for (int i = 0; i < g_category_index; i++) | 1002 for (int i = 0; i < g_category_index; i++) |
| 1000 SetCategoryGroupEnabled(i, false); | 1003 SetCategoryGroupEnabled(i, false); |
| 1001 AddThreadNameMetadataEvents(); | 1004 AddThreadNameMetadataEvents(); |
| 1002 } | 1005 } |
| 1003 | 1006 |
| 1007 int TraceLog::GetNumTracesRecorded() { |
| 1008 AutoLock lock(lock_); |
| 1009 if (enable_count_ == 0) |
| 1010 return -1; |
| 1011 return num_traces_recorded_; |
| 1012 } |
| 1013 |
| 1004 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { | 1014 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { |
| 1005 enabled_state_observer_list_.AddObserver(listener); | 1015 enabled_state_observer_list_.AddObserver(listener); |
| 1006 } | 1016 } |
| 1007 | 1017 |
| 1008 void TraceLog::RemoveEnabledStateObserver( | 1018 void TraceLog::RemoveEnabledStateObserver( |
| 1009 EnabledStateChangedObserver* listener) { | 1019 EnabledStateChangedObserver* listener) { |
| 1010 enabled_state_observer_list_.RemoveObserver(listener); | 1020 enabled_state_observer_list_.RemoveObserver(listener); |
| 1011 } | 1021 } |
| 1012 | 1022 |
| 1013 float TraceLog::GetBufferPercentFull() const { | 1023 float TraceLog::GetBufferPercentFull() const { |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 0, // num_args | 1514 0, // num_args |
| 1505 NULL, // arg_names | 1515 NULL, // arg_names |
| 1506 NULL, // arg_types | 1516 NULL, // arg_types |
| 1507 NULL, // arg_values | 1517 NULL, // arg_values |
| 1508 NULL, // convertable values | 1518 NULL, // convertable values |
| 1509 TRACE_EVENT_FLAG_NONE); // flags | 1519 TRACE_EVENT_FLAG_NONE); // flags |
| 1510 } | 1520 } |
| 1511 } | 1521 } |
| 1512 | 1522 |
| 1513 } // namespace trace_event_internal | 1523 } // namespace trace_event_internal |
| 1514 | |
| OLD | NEW |