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

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: review 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
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index f23c81054cf5cff26915da0ae36ffd34f9e69050..e75857b41a969e1882339425bb987b2bc63ef22e 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
+void StatisticsRecorder::WriteJSON(const std::string& query,
+ std::string* output) {
+ if (!IsActive())
+ return;
+
+ *output = "{";
+ if (query.length()) {
+ output->append("\"query\":");
+ JsonDoubleQuote(query, true, output);
+ output->append(",");
+ }
+
+ Histograms snapshot;
+ GetSnapshot(query, &snapshot);
+ output->append("\"histograms\":[");
+ std::string json;
+ bool first_time = true;
+ for (Histograms::const_iterator it = snapshot.begin(); it != snapshot.end();
+ ++it) {
+ if (first_time)
+ first_time = false;
+ else
+ output->append(",");
+ json.clear();
+ (*it)->WriteJSON(&json);
+ output->append(json);
+ }
+ output->append("]}");
+}
+
+// static
void StatisticsRecorder::GetHistograms(Histograms* output) {
if (lock_ == NULL)
return;

Powered by Google App Engine
This is Rietveld 408576698