Chromium Code Reviews| Index: base/metrics/statistics_recorder.cc |
| diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc |
| index 4eecddade8058c723392abb32152778e3c5c59eb..65c67ce7fe44eb87eb3c8768459b4232f6f56563 100644 |
| --- a/base/metrics/statistics_recorder.cc |
| +++ b/base/metrics/statistics_recorder.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/metrics/statistics_recorder.h" |
| #include <memory> |
| +#include <set> |
| #include "base/at_exit.h" |
| #include "base/debug/leak_annotations.h" |
| @@ -29,6 +30,9 @@ bool HistogramNameLesser(const base::HistogramBase* a, |
| return a->histogram_name() < b->histogram_name(); |
| } |
| +base::LazyInstance<std::set<base::StatisticsRecorder::MetricsDisplayer*>>::Leaky |
| + g_metrics_displayers_ = LAZY_INSTANCE_INITIALIZER; |
|
Ilya Sherman
2016/04/25 20:53:14
Rather than introducing an additional global objec
bcwhite
2016/04/26 19:51:53
Yes. That'll mean including lazy_instance.h in th
Ilya Sherman
2016/04/26 20:21:58
Why would it need to be a lazy instance (or static
bcwhite
2016/04/26 21:03:29
Calls to this method are made as MetricsDisplayer
|
| + |
| } // namespace |
| namespace base { |
| @@ -211,9 +215,16 @@ void StatisticsRecorder::WriteHTMLGraph(const std::string& query, |
| GetSnapshot(query, &snapshot); |
| std::sort(snapshot.begin(), snapshot.end(), &HistogramNameLesser); |
| for (const HistogramBase* histogram : snapshot) { |
| - histogram->WriteHTMLGraph(output); |
| + histogram->WriteHTMLGraph(nullptr, output); |
| output->append("<br><hr><br>"); |
| } |
| + |
| + for (auto display : g_metrics_displayers_.Get()) { |
| + output->append("<hr size=10 noshade><br><hr><br>\n<p>"); |
| + display->WriteTitleString(output); |
| + output->append("</p>\n"); |
| + display->WriteGraphs(query, MetricsDisplayer::DISPLAY_TEXT_HTML, output); |
| + } |
| } |
| // static |
| @@ -230,9 +241,18 @@ void StatisticsRecorder::WriteGraph(const std::string& query, |
| GetSnapshot(query, &snapshot); |
| std::sort(snapshot.begin(), snapshot.end(), &HistogramNameLesser); |
| for (const HistogramBase* histogram : snapshot) { |
| - histogram->WriteAscii(output); |
| + histogram->WriteAscii(nullptr, output); |
| output->append("\n"); |
| } |
| + |
| + for (auto display : g_metrics_displayers_.Get()) { |
| + output->append( |
| + "########################################" |
| + "########################################\n\n"); |
| + display->WriteTitleString(output); |
| + output->append("\n\n"); |
| + display->WriteGraphs(query, MetricsDisplayer::DISPLAY_TEXT_PLAIN, output); |
| + } |
| } |
| // static |
| @@ -415,6 +435,18 @@ size_t StatisticsRecorder::GetHistogramCount() { |
| } |
| // static |
| +void StatisticsRecorder::RegisterMetricsDisplayer(MetricsDisplayer* display) { |
| + DCHECK(!ContainsKey(g_metrics_displayers_.Get(), display)); |
| + g_metrics_displayers_.Get().insert(display); |
| +} |
| + |
| +// static |
| +void StatisticsRecorder::DeregisterMetricsDisplayer(MetricsDisplayer* display) { |
| + DCHECK(ContainsKey(g_metrics_displayers_.Get(), display)); |
| + g_metrics_displayers_.Get().erase(display); |
| +} |
| + |
| +// static |
| void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { |
| if (histograms_) |
| histograms_->erase(name); |