Chromium Code Reviews| 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, |
|
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.
|
| + 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; |