1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
10 #include "base/process/process_handle.h"
11 #include "base/timer/timer.h"
12 #include "chrome/browser/performance_monitor/process_metrics_history.h"
14 template <typename Type
>
15 struct DefaultSingletonTraits
;
17 namespace performance_monitor
{
19 // PerformanceMonitor is a tool which periodically monitors performance metrics
20 // for histogram logging and possibly taking action upon noticing serious
21 // performance degradation.
22 class PerformanceMonitor
{
24 typedef std::map
<base::ProcessHandle
, ProcessMetricsHistory
> MetricsMap
;
26 // Returns the current PerformanceMonitor instance if one exists; otherwise
27 // constructs a new PerformanceMonitor.
28 static PerformanceMonitor
* GetInstance();
30 // Start the cycle of metrics gathering.
31 void StartGatherCycle();
34 friend struct DefaultSingletonTraits
<PerformanceMonitor
>;
37 virtual ~PerformanceMonitor();
39 // Perform any collections that are done on a timed basis.
40 void DoTimedCollections();
42 // Mark the given process as alive in the current update iteration.
43 // This means adding an entry to the map of watched processes if it's not
45 void MarkProcessAsAlive(const base::ProcessHandle
& handle
,
47 int current_update_sequence
);
49 // Updates the ProcessMetrics map with the current list of processes and
50 // gathers metrics from each entry.
51 void GatherMetricsMapOnUIThread();
52 void GatherMetricsMapOnIOThread(int current_update_sequence
);
54 // A map of currently running ProcessHandles to ProcessMetrics.
55 MetricsMap metrics_map_
;
57 // The timer to signal PerformanceMonitor to perform its timed collections.
58 base::RepeatingTimer
<PerformanceMonitor
> repeating_timer_
;
60 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor
);
63 } // namespace performance_monitor
65 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_