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> | |
9 #include <string> | |
10 | |
8 #include "base/callback.h" | 11 #include "base/callback.h" |
9 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/linked_ptr.h" | |
10 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/process.h" | |
17 #include "base/process_util.h" | |
12 #include "chrome/browser/performance_monitor/database.h" | 18 #include "chrome/browser/performance_monitor/database.h" |
13 #include "chrome/browser/performance_monitor/event.h" | 19 #include "chrome/browser/performance_monitor/event.h" |
14 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
18 | 24 |
19 namespace performance_monitor { | 25 namespace performance_monitor { |
20 class Database; | 26 class Database; |
21 | 27 |
22 class PerformanceMonitor : public content::NotificationObserver { | 28 class PerformanceMonitor : public content::NotificationObserver { |
23 public: | 29 public: |
24 typedef base::Callback<void(const std::string&)> StateValueCallback; | 30 typedef base::Callback<void(const std::string&)> StateValueCallback; |
25 | 31 |
32 typedef std::map<base::ProcessHandle, | |
33 linked_ptr<base::ProcessMetrics> > MetricsMap; | |
34 | |
26 // Set the path which the PerformanceMonitor should use for the database files | 35 // Set the path which the PerformanceMonitor should use for the database files |
27 // constructed. This must be done prior to the initialization of the | 36 // constructed. This must be done prior to the initialization of the |
28 // PerformanceMonitor. Returns true on success, false on failure (failure | 37 // PerformanceMonitor. Returns true on success, false on failure (failure |
29 // likely indicates that PerformanceMonitor has already been started at the | 38 // likely indicates that PerformanceMonitor has already been started at the |
30 // time of the call). | 39 // time of the call). |
31 bool SetDatabasePath(const FilePath& path); | 40 bool SetDatabasePath(const FilePath& path); |
32 | 41 |
33 // Returns the current PerformanceMonitor instance if one exists; otherwise | 42 // Returns the current PerformanceMonitor instance if one exists; otherwise |
34 // constructs a new PerformanceMonitor. | 43 // constructs a new PerformanceMonitor. |
35 static PerformanceMonitor* GetInstance(); | 44 static PerformanceMonitor* GetInstance(); |
36 | 45 |
37 // Begins the initialization process for the PerformanceMonitor in order to | 46 // Begins the initialization process for the PerformanceMonitor in order to |
38 // start collecting data. | 47 // start collecting data. |
39 void Start(); | 48 void Start(); |
40 | 49 |
50 // Check the previous Chrome version from the Database and determine if | |
51 // it has been updated. If it has, insert an event in the database. | |
52 void CheckForVersionUpdate(); | |
Devlin
2012/07/27 22:09:47
This doesn't belong here - the method has been rep
mitchellwrosen
2012/07/30 21:50:40
Aye, a git mistake. Done.
| |
53 | |
54 // Gathers CPU usage and memory usage of all Chrome processes. | |
55 void GatherStatisticsOnBackgroundThread(); | |
56 | |
41 // content::NotificationObserver | 57 // content::NotificationObserver |
42 // Wait for various notifications; insert events into the database upon | 58 // Wait for various notifications; insert events into the database upon |
43 // occurance. | 59 // occurance. |
44 virtual void Observe(int type, | 60 virtual void Observe(int type, |
45 const content::NotificationSource& source, | 61 const content::NotificationSource& source, |
46 const content::NotificationDetails& details) OVERRIDE; | 62 const content::NotificationDetails& details) OVERRIDE; |
47 | 63 |
48 Database* database() { return database_.get(); } | 64 Database* database() { return database_.get(); } |
49 FilePath database_path() { return database_path_; } | 65 FilePath database_path() { return database_path_; } |
50 | 66 |
(...skipping 15 matching lines...) Expand all Loading... | |
66 | 82 |
67 // Check the previous Chrome version from the Database and determine if | 83 // Check the previous Chrome version from the Database and determine if |
68 // it has been updated. If it has, insert an event in the database. | 84 // it has been updated. If it has, insert an event in the database. |
69 void CheckForVersionUpdateOnBackgroundThread(); | 85 void CheckForVersionUpdateOnBackgroundThread(); |
70 | 86 |
71 // Wrapper function for inserting events into the database. | 87 // Wrapper function for inserting events into the database. |
72 void AddEvent(scoped_ptr<Event> event); | 88 void AddEvent(scoped_ptr<Event> event); |
73 | 89 |
74 void AddEventOnBackgroundThread(scoped_ptr<Event> event); | 90 void AddEventOnBackgroundThread(scoped_ptr<Event> event); |
75 | 91 |
92 // Gathers the CPU usage of every Chrome process that has been running since | |
93 // the last call to GatherStatistics(). | |
94 void GatherCPUUsage(); | |
95 | |
96 // Gathers the memory usage of every process in the current list of processes. | |
97 void GatherMemoryUsage(); | |
98 | |
99 // Updates the ProcessMetrics map with the current list of processes. | |
100 void UpdateMetricsMap(); | |
101 | |
102 // A map of currently running ProcessHandles to ProcessMetrics. | |
103 MetricsMap metrics_map_; | |
Devlin
2012/07/27 22:09:47
Put this with the other data members.
mitchellwrosen
2012/07/30 21:50:40
Done.
| |
104 | |
76 // Gets the corresponding value of |key| from the database, and then runs | 105 // Gets the corresponding value of |key| from the database, and then runs |
77 // |callback| on the UI thread with that value as a parameter. | 106 // |callback| on the UI thread with that value as a parameter. |
78 void GetStateValueOnBackgroundThread( | 107 void GetStateValueOnBackgroundThread( |
79 const std::string& key, | 108 const std::string& key, |
80 const StateValueCallback& callback); | 109 const StateValueCallback& callback); |
81 | 110 |
82 // Notify any listeners that PerformanceMonitor has finished the initializing. | 111 // Notify any listeners that PerformanceMonitor has finished the initializing. |
83 void NotifyInitialized(); | 112 void NotifyInitialized(); |
84 | 113 |
85 // The location at which the database files are stored; if empty, the database | 114 // The location at which the database files are stored; if empty, the database |
86 // will default to '<user_data_dir>/performance_monitor_dbs'. | 115 // will default to '<user_data_dir>/performance_monitor_dbs'. |
87 FilePath database_path_; | 116 FilePath database_path_; |
88 | 117 |
89 scoped_ptr<Database> database_; | 118 scoped_ptr<Database> database_; |
90 | 119 |
91 content::NotificationRegistrar registrar_; | 120 content::NotificationRegistrar registrar_; |
92 | 121 |
93 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); | 122 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); |
94 }; | 123 }; |
95 | 124 |
96 } // namespace performance_monitor | 125 } // namespace performance_monitor |
97 | 126 |
98 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 127 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
OLD | NEW |