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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index f23c81054cf5cff26915da0ae36ffd34f9e69050..1e28fbe877cfdb1a788293439cca6b08ad5befef 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -6,11 +6,13 @@
#include "base/at_exit.h"
#include "base/debug/leak_annotations.h"
+#include "base/json/string_escape.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
+#include "base/values.h"
using std::list;
using std::string;
@@ -163,6 +165,37 @@ void StatisticsRecorder::WriteGraph(const std::string& query,
}
// static
+std::string StatisticsRecorder::ToJSON(const std::string& query) {
+ if (!IsActive())
+ return std::string();
+
+ std::string output("{");
+ if (!query.empty()) {
+ output += "\"query\":";
+ JsonDoubleQuote(query, true, &output);
+ output += ",";
+ }
+
+ Histograms snapshot;
+ GetSnapshot(query, &snapshot);
+ output += "\"histograms\":[";
+ std::string json;
+ bool first_histogram = true;
+ for (Histograms::const_iterator it = snapshot.begin(); it != snapshot.end();
+ ++it) {
+ if (first_histogram)
+ first_histogram = false;
+ else
+ output += ",";
+ json.clear();
+ (*it)->WriteJSON(&json);
+ output += json;
+ }
+ output += "]}";
+ return output;
+}
+
+// static
void StatisticsRecorder::GetHistograms(Histograms* output) {
if (lock_ == NULL)
return;
« 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