OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 6 #define CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
| 12 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
14 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
15 #include "chrome/browser/performance_monitor/process_metrics_history.h" | 16 #include "chrome/browser/performance_monitor/process_metrics_history.h" |
16 | 17 |
17 namespace base { | |
18 template <typename Type> | |
19 struct DefaultSingletonTraits; | |
20 } // namespace base | |
21 | |
22 namespace content { | 18 namespace content { |
23 struct ChildProcessData; | 19 struct ChildProcessData; |
24 } | 20 } |
25 | 21 |
26 namespace performance_monitor { | 22 namespace performance_monitor { |
27 | 23 |
| 24 class ProcessMetricsHistory; |
| 25 |
28 // PerformanceMonitor is a tool which periodically monitors performance metrics | 26 // PerformanceMonitor is a tool which periodically monitors performance metrics |
29 // for histogram logging and possibly taking action upon noticing serious | 27 // for histogram logging and possibly taking action upon noticing serious |
30 // performance degradation. | 28 // performance degradation. |
31 class PerformanceMonitor { | 29 class PerformanceMonitor { |
32 public: | 30 public: |
33 // Returns the current PerformanceMonitor instance if one exists; otherwise | 31 // Returns the current PerformanceMonitor instance if one exists; otherwise |
34 // constructs a new PerformanceMonitor. | 32 // constructs a new PerformanceMonitor. |
35 static PerformanceMonitor* GetInstance(); | 33 static PerformanceMonitor* GetInstance(); |
36 | 34 |
37 // Start the cycle of metrics gathering. | 35 // Start the cycle of metrics gathering. |
38 void StartGatherCycle(); | 36 void StartGatherCycle(); |
39 | 37 |
40 private: | 38 private: |
41 typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap; | 39 friend struct base::DefaultLazyInstanceTraits<PerformanceMonitor>; |
42 | 40 |
43 friend struct base::DefaultSingletonTraits<PerformanceMonitor>; | 41 using MetricsMap = |
| 42 std::map<base::ProcessHandle, std::unique_ptr<ProcessMetricsHistory>>; |
44 | 43 |
45 PerformanceMonitor(); | 44 PerformanceMonitor(); |
46 virtual ~PerformanceMonitor(); | 45 ~PerformanceMonitor(); |
47 | 46 |
48 // Perform any collections that are done on a timed basis. | 47 // Perform any collections that are done on a timed basis. |
49 void DoTimedCollections(); | 48 void DoTimedCollections(); |
50 | 49 |
51 // Mark the given process as alive in the current update iteration. | 50 // Mark the given process as alive in the current update iteration. |
52 // This means adding an entry to the map of watched processes if it's not | 51 // This means adding an entry to the map of watched processes if it's not |
53 // already present. | 52 // already present. |
54 void MarkProcessAsAlive(const ProcessMetricsMetadata& process_data, | 53 void MarkProcessAsAlive(const ProcessMetricsMetadata& process_data, |
55 int current_update_sequence); | 54 int current_update_sequence); |
56 void MarkProcessesAsAliveOnUIThread( | 55 void MarkProcessesAsAliveOnUIThread( |
(...skipping 13 matching lines...) Expand all Loading... |
70 | 69 |
71 // The timer to signal PerformanceMonitor to perform its timed collections. | 70 // The timer to signal PerformanceMonitor to perform its timed collections. |
72 base::OneShotTimer repeating_timer_; | 71 base::OneShotTimer repeating_timer_; |
73 | 72 |
74 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); | 73 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); |
75 }; | 74 }; |
76 | 75 |
77 } // namespace performance_monitor | 76 } // namespace performance_monitor |
78 | 77 |
79 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 78 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
OLD | NEW |