Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Quang Minh Tuan Nguyen | 36d4dca | 2021-03-30 02:41:22 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_METRICS_HISTOGRAMS_MONITOR_H_ |
| 6 | #define CONTENT_BROWSER_METRICS_HISTOGRAMS_MONITOR_H_ |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 7 | |
| 8 | #include <map> |
Alexei Svitkine | 8591a1b4 | 2024-02-01 18:48:02 | [diff] [blame] | 9 | #include <string_view> |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 10 | |
| 11 | #include "base/metrics/histogram_samples.h" |
| 12 | #include "base/metrics/statistics_recorder.h" |
| 13 | #include "content/common/content_export.h" |
| 14 | |
| 15 | namespace content { |
| 16 | |
| 17 | // This class handles the monitoring feature of chrome://histograms page, |
Alexei Svitkine | 8591a1b4 | 2024-02-01 18:48:02 | [diff] [blame] | 18 | // which allows the page to be updated with histograms logged since the |
| 19 | // monitoring started. |
Yulun Zeng | 5e521f4 | 2022-11-01 00:13:58 | [diff] [blame] | 20 | // |
| 21 | // Note that this class does not handle merging histograms from any |
| 22 | // |HistogramProvider| instances. It also does not handle synchronizing |
| 23 | // histograms from subprocesses. The caller has the responsibility for these |
| 24 | // beforehand. |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 25 | class CONTENT_EXPORT HistogramsMonitor { |
| 26 | public: |
| 27 | HistogramsMonitor(); |
| 28 | ~HistogramsMonitor(); |
| 29 | |
| 30 | HistogramsMonitor(const HistogramsMonitor&) = delete; |
| 31 | HistogramsMonitor& operator=(const HistogramsMonitor&) = delete; |
| 32 | |
Alexei Svitkine | 8591a1b4 | 2024-02-01 18:48:02 | [diff] [blame] | 33 | // Fetches and records a snapshot of the current histograms, as the baseline |
| 34 | // to compare against in subsequent calls to GetDiff(). |
Andrzej Fiedukowicz | f5d01b5 | 2025-01-21 17:56:26 | [diff] [blame] | 35 | void StartMonitoring(); |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 36 | |
| 37 | // Gets the histogram diffs between the current histograms and the snapshot |
Andrzej Fiedukowicz | f5d01b5 | 2025-01-21 17:56:26 | [diff] [blame] | 38 | // recorded in StartMonitoring(). Only returns the histograms that match |
| 39 | // the query string. |
| 40 | base::Value::List GetDiff(const std::string& query); |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 41 | |
| 42 | private: |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 43 | // Gets the difference between the histograms argument and the stored snapshot |
| 44 | // recorded in StartMonitoring(). |
Claudio DeSouza | 464bba7b | 2022-08-04 22:55:40 | [diff] [blame] | 45 | base::Value::List GetDiffInternal( |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 46 | const base::StatisticsRecorder::Histograms& histograms); |
| 47 | |
Roger McFarlane | 8952859 | 2025-02-20 20:50:27 | [diff] [blame] | 48 | std::map<std::string, std::unique_ptr<base::HistogramSamples>, std::less<>> |
Quang Minh Tuan Nguyen | 636a7ab2 | 2021-03-25 22:55:34 | [diff] [blame] | 49 | histograms_snapshot_; |
| 50 | }; |
| 51 | |
| 52 | } // namespace content |
| 53 | |
Quang Minh Tuan Nguyen | 36d4dca | 2021-03-30 02:41:22 | [diff] [blame] | 54 | #endif // CONTENT_BROWSER_METRICS_HISTOGRAMS_MONITOR_H_ |