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
;
18 struct ChildProcessData
;
21 namespace performance_monitor
{
23 // PerformanceMonitor is a tool which periodically monitors performance metrics
24 // for histogram logging and possibly taking action upon noticing serious
25 // performance degradation.
26 class PerformanceMonitor
{
28 // Returns the current PerformanceMonitor instance if one exists; otherwise
29 // constructs a new PerformanceMonitor.
30 static PerformanceMonitor
* GetInstance();
32 // Start the cycle of metrics gathering.
33 void StartGatherCycle();
36 typedef std::map
<base::ProcessHandle
, ProcessMetricsHistory
> MetricsMap
;
38 friend struct DefaultSingletonTraits
<PerformanceMonitor
>;
41 virtual ~PerformanceMonitor();
43 // Perform any collections that are done on a timed basis.
44 void DoTimedCollections();
46 // Mark the given process as alive in the current update iteration.
47 // This means adding an entry to the map of watched processes if it's not
49 void MarkProcessAsAlive(const ProcessMetricsMetadata
& process_data
,
50 int current_update_sequence
);
52 // Updates the ProcessMetrics map with the current list of processes and
53 // gathers metrics from each entry.
54 void GatherMetricsMapOnUIThread();
55 void GatherMetricsMapOnIOThread(int current_update_sequence
);
57 // A map of currently running ProcessHandles to ProcessMetrics.
58 MetricsMap metrics_map_
;
60 // The timer to signal PerformanceMonitor to perform its timed collections.
61 base::RepeatingTimer
<PerformanceMonitor
> repeating_timer_
;
63 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor
);
66 } // namespace performance_monitor
68 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_