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

Unified 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: attachment helper 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..2e960baa630aaf5394b77e5a7f5d25ed03d44a05 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\":[");
+ for (Histograms::iterator it = snapshot.begin();
+ it != snapshot.end();
+ ++it) {
+ std::string json;
+ (*it)->WriteJSON(&json);
+ output->append(json);
+ output->append(",");
+ }
+ // Remove trailing comma.
+ if (snapshot.size())
+ output->resize(output->size() - 1);
+
+ output->append("]}");
+}
+
+// static
void StatisticsRecorder::GetHistograms(Histograms* output) {
if (lock_ == NULL)
return;

Powered by Google App Engine
This is Rietveld 408576698