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; |