Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/browser/performance_monitor/performance_monitor.h

Issue 10829342: Add BytesRead metric to CPM (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed const char[]s so that FILE_PATH_LITERAL and append both work Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
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 net {
32 class URLRequest;
33 }
34
31 namespace performance_monitor { 35 namespace performance_monitor {
32 class Database; 36 class Database;
33 37
38 // PerformanceMonitor is a tool which will allow the user to view information
39 // about Chrome's performance over a period of time. It will gather statistics
40 // pertaining to performance-oriented areas (e.g. CPU usage, memory usage, and
41 // network usage) and will also store information about significant events which
42 // are related to performance, either being indicative (e.g. crashes) or
43 // potentially causal (e.g. extension installation/uninstallation).
44 //
45 // Thread Safety: PerformanceMonitor lives on multiple threads. When interacting
46 // with the Database, PerformanceMonitor acts on a background thread (which has
47 // the sequence guaranteed by a token, Database::kDatabaseSequenceToken). At
48 // other times, the PerformanceMonitor will act on the appropriate thread for
49 // the task (for instance, gathering statistics about CPU and memory usage
50 // is done on the background thread, but most notifications occur on the UI
51 // thread).
34 class PerformanceMonitor : public content::NotificationObserver { 52 class PerformanceMonitor : public content::NotificationObserver {
35 public: 53 public:
54 struct PerformanceDataForIOThread {
55 PerformanceDataForIOThread();
56
57 uint64 network_bytes_read;
58 };
59
36 typedef std::map<base::ProcessHandle, 60 typedef std::map<base::ProcessHandle,
37 linked_ptr<base::ProcessMetrics> > MetricsMap; 61 linked_ptr<base::ProcessMetrics> > MetricsMap;
38 62
39 // Set the path which the PerformanceMonitor should use for the database files 63 // Set the path which the PerformanceMonitor should use for the database files
40 // constructed. This must be done prior to the initialization of the 64 // constructed. This must be done prior to the initialization of the
41 // PerformanceMonitor. Returns true on success, false on failure (failure 65 // PerformanceMonitor. Returns true on success, false on failure (failure
42 // likely indicates that PerformanceMonitor has already been started at the 66 // likely indicates that PerformanceMonitor has already been started at the
43 // time of the call). 67 // time of the call).
44 bool SetDatabasePath(const FilePath& path); 68 bool SetDatabasePath(const FilePath& path);
45 69
46 // Returns the current PerformanceMonitor instance if one exists; otherwise 70 // Returns the current PerformanceMonitor instance if one exists; otherwise
47 // constructs a new PerformanceMonitor. 71 // constructs a new PerformanceMonitor.
48 static PerformanceMonitor* GetInstance(); 72 static PerformanceMonitor* GetInstance();
49 73
50 // Begins the initialization process for the PerformanceMonitor in order to 74 // Begins the initialization process for the PerformanceMonitor in order to
51 // start collecting data. 75 // start collecting data.
52 void Start(); 76 void Start();
53 77
78 // Inform PerformanceMonitor that bytes have been read; if these came across
79 // the network (and PerformanceMonitor is initialized), then increment the
80 // count accordingly.
81 void BytesReadOnIOThread(const net::URLRequest& request, const int bytes);
82
54 // content::NotificationObserver 83 // content::NotificationObserver
55 // Wait for various notifications; insert events into the database upon 84 // Wait for various notifications; insert events into the database upon
56 // occurance. 85 // occurance.
57 virtual void Observe(int type, 86 virtual void Observe(int type,
58 const content::NotificationSource& source, 87 const content::NotificationSource& source,
59 const content::NotificationDetails& details) OVERRIDE; 88 const content::NotificationDetails& details) OVERRIDE;
60 89
61 Database* database() { return database_.get(); } 90 Database* database() { return database_.get(); }
62 FilePath database_path() { return database_path_; } 91 FilePath database_path() { return database_path_; }
92 static bool initialized() { return initialized_; }
63 93
64 private: 94 private:
65 friend struct DefaultSingletonTraits<PerformanceMonitor>; 95 friend struct DefaultSingletonTraits<PerformanceMonitor>;
66 friend class PerformanceMonitorBrowserTest; 96 friend class PerformanceMonitorBrowserTest;
67 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, 97 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
68 OneProfileUncleanExit); 98 OneProfileUncleanExit);
69 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, 99 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
70 TwoProfileUncleanExit); 100 TwoProfileUncleanExit);
101 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, NetworkBytesRead);
71 102
72 PerformanceMonitor(); 103 PerformanceMonitor();
73 virtual ~PerformanceMonitor(); 104 virtual ~PerformanceMonitor();
74 105
75 // Perform any additional initialization which must be performed on a 106 // Perform any additional initialization which must be performed on a
76 // background thread (e.g. constructing the database). 107 // background thread (e.g. constructing the database).
77 void InitOnBackgroundThread(); 108 void InitOnBackgroundThread();
78 109
79 void FinishInit(); 110 void FinishInit();
80 111
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Generate an appropriate ExtensionEvent for an extension-related occurrance 162 // Generate an appropriate ExtensionEvent for an extension-related occurrance
132 // and insert it in the database. 163 // and insert it in the database.
133 void AddExtensionEvent(EventType type, 164 void AddExtensionEvent(EventType type,
134 const extensions::Extension* extension); 165 const extensions::Extension* extension);
135 166
136 // Generate an appropriate CrashEvent for a renderer crash and insert it in 167 // Generate an appropriate CrashEvent for a renderer crash and insert it in
137 // the database. 168 // the database.
138 void AddCrashEvent( 169 void AddCrashEvent(
139 const content::RenderProcessHost::RendererClosedDetails& details); 170 const content::RenderProcessHost::RendererClosedDetails& details);
140 171
172 // Called on the IO thread, this will call InsertIOData on the background
173 // thread with a copy of the PerformanceDataForIOThread object to prevent
174 // any possible race conditions.
175 void CallInsertIOData();
176
177 // Insert the collected IO data into the database (deliberately not const & so
178 // we create a copy and it becomes thread-safe).
179 void InsertIOData(PerformanceDataForIOThread performance_data_for_io_thread);
180
181 // The store for all performance data that must be gathered from the IO
182 // thread.
183 PerformanceDataForIOThread performance_data_for_io_thread_;
184
141 // The location at which the database files are stored; if empty, the database 185 // The location at which the database files are stored; if empty, the database
142 // will default to '<user_data_dir>/performance_monitor_dbs'. 186 // will default to '<user_data_dir>/performance_monitor_dbs'.
143 FilePath database_path_; 187 FilePath database_path_;
144 188
145 scoped_ptr<Database> database_; 189 scoped_ptr<Database> database_;
146 190
147 // A map of currently running ProcessHandles to ProcessMetrics. 191 // A map of currently running ProcessHandles to ProcessMetrics.
148 MetricsMap metrics_map_; 192 MetricsMap metrics_map_;
149 193
150 // The timer to signal PerformanceMonitor to perform its timed collections. 194 // The timer to signal PerformanceMonitor to perform its timed collections.
151 base::RepeatingTimer<PerformanceMonitor> timer_; 195 base::RepeatingTimer<PerformanceMonitor> timer_;
152 196
153 content::NotificationRegistrar registrar_; 197 content::NotificationRegistrar registrar_;
154 198
199 // A flag indicating whether or not PerformanceMonitor is initialized. Any
200 // external sources accessing PerformanceMonitor should either wait for
201 // the PERFORMANCE_MONITOR_INITIALIZED notification or should check this
202 // flag.
203 static bool initialized_;
204
155 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 205 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
156 }; 206 };
157 207
158 } // namespace performance_monitor 208 } // namespace performance_monitor
159 209
160 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 210 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/performance_monitor/metric_details.cc ('k') | chrome/browser/performance_monitor/performance_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698