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

Side by Side Diff: chromecast/base/metrics/grouped_histogram.cc

Issue 1689833002: Add ownership-transfer to histogram management calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 10 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
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromecast/base/metrics/grouped_histogram.h" 5 #include "chromecast/base/metrics/grouped_histogram.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 GroupedHistogram::Sample minimum, 136 GroupedHistogram::Sample minimum,
137 GroupedHistogram::Sample maximum, 137 GroupedHistogram::Sample maximum,
138 uint32_t bucket_count, 138 uint32_t bucket_count,
139 int32_t flags) { 139 int32_t flags) {
140 DCHECK(base::StatisticsRecorder::IsActive()); 140 DCHECK(base::StatisticsRecorder::IsActive());
141 DCHECK(base::Histogram::InspectConstructionArguments( 141 DCHECK(base::Histogram::InspectConstructionArguments(
142 name, &minimum, &maximum, &bucket_count)); 142 name, &minimum, &maximum, &bucket_count));
143 DCHECK(!base::StatisticsRecorder::FindHistogram(name)) 143 DCHECK(!base::StatisticsRecorder::FindHistogram(name))
144 << "Failed to preregister " << name << ", Histogram already exists."; 144 << "Failed to preregister " << name << ", Histogram already exists.";
145 145
146 // To avoid racy destruction at shutdown, the following will be leaked. 146 scoped_ptr<base::BucketRanges> ranges(
147 base::BucketRanges* ranges = new base::BucketRanges(bucket_count + 1); 147 new base::BucketRanges(bucket_count + 1));
148 base::Histogram::InitializeBucketRanges(minimum, maximum, ranges); 148 base::Histogram::InitializeBucketRanges(minimum, maximum, ranges.get());
149 const base::BucketRanges* registered_ranges = 149 const base::BucketRanges* registered_ranges =
150 base::StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); 150 base::StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
151 std::move(ranges));
151 152
152 GroupedHistogram* tentative_histogram = 153 scoped_ptr<GroupedHistogram> tentative_histogram(
153 new GroupedHistogram(name, minimum, maximum, registered_ranges); 154 new GroupedHistogram(name, minimum, maximum, registered_ranges));
154 155
155 tentative_histogram->SetFlags(flags); 156 tentative_histogram->SetFlags(flags);
157 const void* allocated_histogram = tentative_histogram.get();
156 base::HistogramBase* histogram = 158 base::HistogramBase* histogram =
157 base::StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); 159 base::StatisticsRecorder::RegisterOrDeleteDuplicate(
160 std::move(tentative_histogram));
158 161
159 DCHECK_EQ(histogram, tentative_histogram); 162 DCHECK_EQ(histogram, allocated_histogram);
160 DCHECK_EQ(base::HISTOGRAM, histogram->GetHistogramType()); 163 DCHECK_EQ(base::HISTOGRAM, histogram->GetHistogramType());
161 DCHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); 164 DCHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count));
162 } 165 }
163 166
164 } // namespace 167 } // namespace
165 168
166 void PreregisterAllGroupedHistograms() { 169 void PreregisterAllGroupedHistograms() {
167 base::StatisticsRecorder::Initialize(); 170 base::StatisticsRecorder::Initialize();
168 for (size_t i = 0; i < arraysize(kHistogramsToGroup); ++i) { 171 for (size_t i = 0; i < arraysize(kHistogramsToGroup); ++i) {
169 PreregisterHistogram( 172 PreregisterHistogram(
170 kHistogramsToGroup[i].name, 173 kHistogramsToGroup[i].name,
171 kHistogramsToGroup[i].minimum, 174 kHistogramsToGroup[i].minimum,
172 kHistogramsToGroup[i].maximum, 175 kHistogramsToGroup[i].maximum,
173 kHistogramsToGroup[i].bucket_count, 176 kHistogramsToGroup[i].bucket_count,
174 base::HistogramBase::kUmaTargetedHistogramFlag); 177 base::HistogramBase::kUmaTargetedHistogramFlag);
175 } 178 }
176 } 179 }
177 180
178 void TagAppStartForGroupedHistograms(const std::string& app_name) { 181 void TagAppStartForGroupedHistograms(const std::string& app_name) {
179 base::AutoLock lock(g_current_app.Get().lock); 182 base::AutoLock lock(g_current_app.Get().lock);
180 g_current_app.Get().app_name = app_name; 183 g_current_app.Get().app_name = app_name;
181 } 184 }
182 185
183 } // namespace metrics 186 } // namespace metrics
184 } // namespace chromecast 187 } // namespace chromecast
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698