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 <string> | 9 #include <string> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
25 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
26 | 26 |
27 namespace extensions { | 27 namespace extensions { |
28 class Extension; | 28 class Extension; |
29 } | 29 } |
30 | 30 |
31 namespace performance_monitor { | 31 namespace performance_monitor { |
32 class Database; | 32 class Database; |
33 | 33 |
34 class PerformanceMonitor : public content::NotificationObserver { | 34 class PerformanceMonitor : public content::NotificationObserver { |
battre
2012/08/21 16:16:04
Can you document the thread-safety of this class?
Devlin
2012/08/21 19:46:46
Done (and very needed, thank you). Please let me k
| |
35 public: | 35 public: |
36 typedef std::map<base::ProcessHandle, | 36 typedef std::map<base::ProcessHandle, |
37 linked_ptr<base::ProcessMetrics> > MetricsMap; | 37 linked_ptr<base::ProcessMetrics> > MetricsMap; |
38 | 38 |
39 // Set the path which the PerformanceMonitor should use for the database files | 39 // Set the path which the PerformanceMonitor should use for the database files |
40 // constructed. This must be done prior to the initialization of the | 40 // constructed. This must be done prior to the initialization of the |
41 // PerformanceMonitor. Returns true on success, false on failure (failure | 41 // PerformanceMonitor. Returns true on success, false on failure (failure |
42 // likely indicates that PerformanceMonitor has already been started at the | 42 // likely indicates that PerformanceMonitor has already been started at the |
43 // time of the call). | 43 // time of the call). |
44 bool SetDatabasePath(const FilePath& path); | 44 bool SetDatabasePath(const FilePath& path); |
45 | 45 |
46 // Returns the current PerformanceMonitor instance if one exists; otherwise | 46 // Returns the current PerformanceMonitor instance if one exists; otherwise |
47 // constructs a new PerformanceMonitor. | 47 // constructs a new PerformanceMonitor. |
48 static PerformanceMonitor* GetInstance(); | 48 static PerformanceMonitor* GetInstance(); |
49 | 49 |
50 // Begins the initialization process for the PerformanceMonitor in order to | 50 // Begins the initialization process for the PerformanceMonitor in order to |
51 // start collecting data. | 51 // start collecting data. |
52 void Start(); | 52 void Start(); |
53 | 53 |
54 // Inform PerformanceMonitor that bytes have been read; increment the count | |
55 // accordingly. | |
56 void BytesRead(int bytes); | |
57 | |
54 // content::NotificationObserver | 58 // content::NotificationObserver |
55 // Wait for various notifications; insert events into the database upon | 59 // Wait for various notifications; insert events into the database upon |
56 // occurance. | 60 // occurance. |
57 virtual void Observe(int type, | 61 virtual void Observe(int type, |
58 const content::NotificationSource& source, | 62 const content::NotificationSource& source, |
59 const content::NotificationDetails& details) OVERRIDE; | 63 const content::NotificationDetails& details) OVERRIDE; |
60 | 64 |
61 Database* database() { return database_.get(); } | 65 Database* database() { return database_.get(); } |
62 FilePath database_path() { return database_path_; } | 66 FilePath database_path() { return database_path_; } |
67 static bool enabled() { return enabled_; } | |
63 | 68 |
64 private: | 69 private: |
65 friend struct DefaultSingletonTraits<PerformanceMonitor>; | 70 friend struct DefaultSingletonTraits<PerformanceMonitor>; |
66 friend class PerformanceMonitorBrowserTest; | 71 friend class PerformanceMonitorBrowserTest; |
67 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, | 72 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, |
68 OneProfileUncleanExit); | 73 OneProfileUncleanExit); |
69 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, | 74 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, |
70 TwoProfileUncleanExit); | 75 TwoProfileUncleanExit); |
76 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, BytesRead); | |
71 | 77 |
72 PerformanceMonitor(); | 78 PerformanceMonitor(); |
73 virtual ~PerformanceMonitor(); | 79 virtual ~PerformanceMonitor(); |
74 | 80 |
75 // Perform any additional initialization which must be performed on a | 81 // Perform any additional initialization which must be performed on a |
76 // background thread (e.g. constructing the database). | 82 // background thread (e.g. constructing the database). |
77 void InitOnBackgroundThread(); | 83 void InitOnBackgroundThread(); |
78 | 84 |
79 void FinishInit(); | 85 void FinishInit(); |
80 | 86 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 // Generate an appropriate ExtensionEvent for an extension-related occurrance | 137 // Generate an appropriate ExtensionEvent for an extension-related occurrance |
132 // and insert it in the database. | 138 // and insert it in the database. |
133 void AddExtensionEvent(EventType type, | 139 void AddExtensionEvent(EventType type, |
134 const extensions::Extension* extension); | 140 const extensions::Extension* extension); |
135 | 141 |
136 // Generate an appropriate CrashEvent for a renderer crash and insert it in | 142 // Generate an appropriate CrashEvent for a renderer crash and insert it in |
137 // the database. | 143 // the database. |
138 void AddCrashEvent( | 144 void AddCrashEvent( |
139 const content::RenderProcessHost::RendererClosedDetails& details); | 145 const content::RenderProcessHost::RendererClosedDetails& details); |
140 | 146 |
147 // A count of how many bytes have been read. This corresponds to the total | |
148 // number of bytes that have been read since PerformanceMonitor first started | |
battre
2012/08/21 16:16:04
"have been read from where"? net/disk/...
Devlin
2012/08/21 19:46:46
Good point. I found this through TaskManager's cod
| |
149 // recording, and persists across browser runs. | |
150 int64 bytes_read_; | |
151 | |
141 // The location at which the database files are stored; if empty, the database | 152 // The location at which the database files are stored; if empty, the database |
142 // will default to '<user_data_dir>/performance_monitor_dbs'. | 153 // will default to '<user_data_dir>/performance_monitor_dbs'. |
143 FilePath database_path_; | 154 FilePath database_path_; |
144 | 155 |
145 scoped_ptr<Database> database_; | 156 scoped_ptr<Database> database_; |
146 | 157 |
147 // A map of currently running ProcessHandles to ProcessMetrics. | 158 // A map of currently running ProcessHandles to ProcessMetrics. |
148 MetricsMap metrics_map_; | 159 MetricsMap metrics_map_; |
149 | 160 |
150 // The timer to signal PerformanceMonitor to perform its timed collections. | 161 // The timer to signal PerformanceMonitor to perform its timed collections. |
151 base::RepeatingTimer<PerformanceMonitor> timer_; | 162 base::RepeatingTimer<PerformanceMonitor> timer_; |
152 | 163 |
153 content::NotificationRegistrar registrar_; | 164 content::NotificationRegistrar registrar_; |
154 | 165 |
166 // A flag indicating whether or not PerformanceMonitor is enabled. Any | |
167 // external sources accessing PerformanceMonitor should either wait for | |
168 // the PERFORMANCE_MONITOR_INITIALIZED notification or should check this | |
169 // flag. | |
170 static bool enabled_; | |
battre
2012/08/21 16:16:04
static attributes don't use the _ notation but use
eaugusti
2012/08/21 17:17:26
Isn't the g_ prefix only for global data?
I think
Devlin
2012/08/21 19:46:46
Other examples:
http://code.google.com/searchframe
| |
171 | |
155 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); | 172 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); |
156 }; | 173 }; |
157 | 174 |
158 } // namespace performance_monitor | 175 } // namespace performance_monitor |
159 | 176 |
160 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ | 177 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ |
OLD | NEW |