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