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

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

Issue 55363003: Send compressed histograms with system logs when sending feedback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback feedback 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
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 void StatisticsRecorder::WriteJSON(const std::string& query,
Alexei Svitkine (slow) 2013/11/02 00:05:26 Can you add some unit tests for this?
michaelpg 2013/11/02 17:39:09 Done.
169 std::string* output) {
170 if (!IsActive())
171 return;
172
173 *output = "{";
174 if (query.length()) {
175 output->append("\"query\":");
176 JsonDoubleQuote(query, true, output);
177 output->append(",");
178 }
179
180 Histograms snapshot;
181 GetSnapshot(query, &snapshot);
182 output->append("\"histograms\":[");
183 for (Histograms::iterator it = snapshot.begin();
184 it != snapshot.end();
185 ++it) {
186 std::string json;
187 (*it)->WriteJSON(&json);
188 output->append(json);
189 output->append(",");
190 }
191 // Remove trailing comma.
192 if (snapshot.size())
193 output->resize(output->size() - 1);
194
195 output->append("]}");
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

Powered by Google App Engine
This is Rietveld 408576698