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

Side by Side Diff: base/metrics/statistics_recorder.cc

Issue 61983003: Add a switch to emit browser histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/statistics_recorder.h" 5 #include "base/metrics/statistics_recorder.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/json/string_escape.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/values.h"
14 16
15 using std::list; 17 using std::list;
16 using std::string; 18 using std::string;
17 19
18 namespace { 20 namespace {
19 // Initialize histogram statistics gathering system. 21 // Initialize histogram statistics gathering system.
20 base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ = 22 base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ =
21 LAZY_INSTANCE_INITIALIZER; 23 LAZY_INSTANCE_INITIALIZER;
22 } // namespace 24 } // namespace
23 25
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 GetSnapshot(query, &snapshot); 158 GetSnapshot(query, &snapshot);
157 for (Histograms::iterator it = snapshot.begin(); 159 for (Histograms::iterator it = snapshot.begin();
158 it != snapshot.end(); 160 it != snapshot.end();
159 ++it) { 161 ++it) {
160 (*it)->WriteAscii(output); 162 (*it)->WriteAscii(output);
161 output->append("\n"); 163 output->append("\n");
162 } 164 }
163 } 165 }
164 166
165 // static 167 // static
168 std::string StatisticsRecorder::ToJSON(const std::string& query) {
169 if (!IsActive())
170 return std::string();
171
172 std::string output("{");
173 if (!query.empty()) {
174 output += "\"query\":";
175 JsonDoubleQuote(query, true, &output);
176 output += ",";
177 }
178
179 Histograms snapshot;
180 GetSnapshot(query, &snapshot);
181 output += "\"histograms\":[";
182 std::string json;
183 bool first_histogram = true;
184 for (Histograms::const_iterator it = snapshot.begin(); it != snapshot.end();
185 ++it) {
186 if (first_histogram)
187 first_histogram = false;
188 else
189 output += ",";
190 json.clear();
191 (*it)->WriteJSON(&json);
192 output += json;
193 }
194 output += "]}";
195 return output;
196 }
197
198 // static
166 void StatisticsRecorder::GetHistograms(Histograms* output) { 199 void StatisticsRecorder::GetHistograms(Histograms* output) {
167 if (lock_ == NULL) 200 if (lock_ == NULL)
168 return; 201 return;
169 base::AutoLock auto_lock(*lock_); 202 base::AutoLock auto_lock(*lock_);
170 if (histograms_ == NULL) 203 if (histograms_ == NULL)
171 return; 204 return;
172 205
173 for (HistogramMap::iterator it = histograms_->begin(); 206 for (HistogramMap::iterator it = histograms_->begin();
174 histograms_->end() != it; 207 histograms_->end() != it;
175 ++it) { 208 ++it) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 316
284 317
285 // static 318 // static
286 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 319 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
287 // static 320 // static
288 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 321 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
289 // static 322 // static
290 base::Lock* StatisticsRecorder::lock_ = NULL; 323 base::Lock* StatisticsRecorder::lock_ = NULL;
291 324
292 } // namespace base 325 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698