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 "components/metrics/call_stack_profile_metrics_provider.h" | 5 #include "components/metrics/call_stack_profile_metrics_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // True if profiles are being collected. | 88 // True if profiles are being collected. |
89 bool IsCollectionEnabled() const; | 89 bool IsCollectionEnabled() const; |
90 | 90 |
91 // Adds |profile| to the list of profiles if collection is enabled. | 91 // Adds |profile| to the list of profiles if collection is enabled. |
92 void CollectProfilesIfCollectionEnabled(const ProfilesState& profiles); | 92 void CollectProfilesIfCollectionEnabled(const ProfilesState& profiles); |
93 | 93 |
94 // Allows testing against the initial state multiple times. | 94 // Allows testing against the initial state multiple times. |
95 void ResetToDefaultStateForTesting(); | 95 void ResetToDefaultStateForTesting(); |
96 | 96 |
97 private: | 97 private: |
98 friend struct DefaultSingletonTraits<PendingProfiles>; | 98 friend struct base::DefaultSingletonTraits<PendingProfiles>; |
99 | 99 |
100 PendingProfiles(); | 100 PendingProfiles(); |
101 ~PendingProfiles(); | 101 ~PendingProfiles(); |
102 | 102 |
103 mutable base::Lock lock_; | 103 mutable base::Lock lock_; |
104 | 104 |
105 // If true, profiles provided to CollectProfilesIfCollectionEnabled should be | 105 // If true, profiles provided to CollectProfilesIfCollectionEnabled should be |
106 // collected. Otherwise they will be ignored. | 106 // collected. Otherwise they will be ignored. |
107 bool collection_enabled_; | 107 bool collection_enabled_; |
108 | 108 |
109 // The last time collection was disabled. Used to determine if collection was | 109 // The last time collection was disabled. Used to determine if collection was |
110 // disabled at any point since a profile was started. | 110 // disabled at any point since a profile was started. |
111 base::TimeTicks last_collection_disable_time_; | 111 base::TimeTicks last_collection_disable_time_; |
112 | 112 |
113 // The set of completed profiles that should be reported. | 113 // The set of completed profiles that should be reported. |
114 std::vector<ProfilesState> profiles_; | 114 std::vector<ProfilesState> profiles_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(PendingProfiles); | 116 DISALLOW_COPY_AND_ASSIGN(PendingProfiles); |
117 }; | 117 }; |
118 | 118 |
119 // static | 119 // static |
120 PendingProfiles* PendingProfiles::GetInstance() { | 120 PendingProfiles* PendingProfiles::GetInstance() { |
121 // Leaky for performance rather than correctness reasons. | 121 // Leaky for performance rather than correctness reasons. |
122 return Singleton<PendingProfiles, | 122 return base::Singleton<PendingProfiles, |
123 LeakySingletonTraits<PendingProfiles>>::get(); | 123 base::LeakySingletonTraits<PendingProfiles>>::get(); |
124 } | 124 } |
125 | 125 |
126 void PendingProfiles::Clear() { | 126 void PendingProfiles::Clear() { |
127 base::AutoLock scoped_lock(lock_); | 127 base::AutoLock scoped_lock(lock_); |
128 profiles_.clear(); | 128 profiles_.clear(); |
129 } | 129 } |
130 | 130 |
131 void PendingProfiles::Swap(std::vector<ProfilesState>* profiles) { | 131 void PendingProfiles::Swap(std::vector<ProfilesState>* profiles) { |
132 base::AutoLock scoped_lock(lock_); | 132 base::AutoLock scoped_lock(lock_); |
133 profiles_.swap(*profiles); | 133 profiles_.swap(*profiles); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 | 384 |
385 // static | 385 // static |
386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { | 386 bool CallStackProfileMetricsProvider::IsReportingEnabledByFieldTrial() { |
387 const std::string group_name = base::FieldTrialList::FindFullName( | 387 const std::string group_name = base::FieldTrialList::FindFullName( |
388 CallStackProfileMetricsProvider::kFieldTrialName); | 388 CallStackProfileMetricsProvider::kFieldTrialName); |
389 return group_name == | 389 return group_name == |
390 CallStackProfileMetricsProvider::kReportProfilesGroupName; | 390 CallStackProfileMetricsProvider::kReportProfilesGroupName; |
391 } | 391 } |
392 | 392 |
393 } // namespace metrics | 393 } // namespace metrics |
OLD | NEW |