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

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: Requested changes + separation for disk/network reads Created 8 years, 4 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). When performing an action which should be done on a certain thread,
Yoyo Zhou 2012/08/21 21:29:16 You don't need this bit about DCHECKing threads; i
Devlin 2012/08/21 22:51:52 Done.
52 // a (D)CHECK is in place to ensure that it is always safe.
34 class PerformanceMonitor : public content::NotificationObserver { 53 class PerformanceMonitor : public content::NotificationObserver {
35 public: 54 public:
55 struct ByteCount {
56 ByteCount();
57
58 int64 disk;
eaugusti 2012/08/21 21:19:32 Should these be uint64?
Devlin 2012/08/21 22:51:52 Done.
59 int64 network;
60 };
battre 2012/08/21 20:37:33 I haven't read all the code, but I would probably
Devlin 2012/08/21 21:49:02 I understand your suggestion, but am still confuse
Devlin 2012/08/21 22:10:33 Ignore that. Implementing change. (*grumbles some
Devlin 2012/08/21 22:51:52 Done.
61
36 typedef std::map<base::ProcessHandle, 62 typedef std::map<base::ProcessHandle,
37 linked_ptr<base::ProcessMetrics> > MetricsMap; 63 linked_ptr<base::ProcessMetrics> > MetricsMap;
38 64
39 // Set the path which the PerformanceMonitor should use for the database files 65 // Set the path which the PerformanceMonitor should use for the database files
40 // constructed. This must be done prior to the initialization of the 66 // constructed. This must be done prior to the initialization of the
41 // PerformanceMonitor. Returns true on success, false on failure (failure 67 // PerformanceMonitor. Returns true on success, false on failure (failure
42 // likely indicates that PerformanceMonitor has already been started at the 68 // likely indicates that PerformanceMonitor has already been started at the
43 // time of the call). 69 // time of the call).
44 bool SetDatabasePath(const FilePath& path); 70 bool SetDatabasePath(const FilePath& path);
45 71
46 // Returns the current PerformanceMonitor instance if one exists; otherwise 72 // Returns the current PerformanceMonitor instance if one exists; otherwise
47 // constructs a new PerformanceMonitor. 73 // constructs a new PerformanceMonitor.
48 static PerformanceMonitor* GetInstance(); 74 static PerformanceMonitor* GetInstance();
49 75
50 // Begins the initialization process for the PerformanceMonitor in order to 76 // Begins the initialization process for the PerformanceMonitor in order to
51 // start collecting data. 77 // start collecting data.
52 void Start(); 78 void Start();
53 79
80 // Inform PerformanceMonitor that bytes have been read; increment the count
81 // accordingly.
battre 2012/08/21 20:37:33 Sorry for my imprecise comment. I was asking to ex
Yoyo Zhou 2012/08/21 21:29:16 Ooh, what about network file systems? file:/// URL
Devlin 2012/08/21 22:51:52 Got rid of the disk metric, as requested. Per Yoyo
82 void BytesRead(const net::URLRequest& request, const int bytes);
83
54 // content::NotificationObserver 84 // content::NotificationObserver
55 // Wait for various notifications; insert events into the database upon 85 // Wait for various notifications; insert events into the database upon
56 // occurance. 86 // occurance.
57 virtual void Observe(int type, 87 virtual void Observe(int type,
58 const content::NotificationSource& source, 88 const content::NotificationSource& source,
59 const content::NotificationDetails& details) OVERRIDE; 89 const content::NotificationDetails& details) OVERRIDE;
60 90
61 Database* database() { return database_.get(); } 91 Database* database() { return database_.get(); }
62 FilePath database_path() { return database_path_; } 92 FilePath database_path() { return database_path_; }
93 static bool initialized() { return initialized_; }
63 94
64 private: 95 private:
65 friend struct DefaultSingletonTraits<PerformanceMonitor>; 96 friend struct DefaultSingletonTraits<PerformanceMonitor>;
66 friend class PerformanceMonitorBrowserTest; 97 friend class PerformanceMonitorBrowserTest;
67 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, 98 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
68 OneProfileUncleanExit); 99 OneProfileUncleanExit);
69 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest, 100 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
70 TwoProfileUncleanExit); 101 TwoProfileUncleanExit);
102 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, DiskBytesRead);
103 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, NetworkBytesRead);
71 104
72 PerformanceMonitor(); 105 PerformanceMonitor();
73 virtual ~PerformanceMonitor(); 106 virtual ~PerformanceMonitor();
74 107
75 // Perform any additional initialization which must be performed on a 108 // Perform any additional initialization which must be performed on a
76 // background thread (e.g. constructing the database). 109 // background thread (e.g. constructing the database).
77 void InitOnBackgroundThread(); 110 void InitOnBackgroundThread();
78 111
79 void FinishInit(); 112 void FinishInit();
80 113
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // Generate an appropriate ExtensionEvent for an extension-related occurrance 164 // Generate an appropriate ExtensionEvent for an extension-related occurrance
132 // and insert it in the database. 165 // and insert it in the database.
133 void AddExtensionEvent(EventType type, 166 void AddExtensionEvent(EventType type,
134 const extensions::Extension* extension); 167 const extensions::Extension* extension);
135 168
136 // Generate an appropriate CrashEvent for a renderer crash and insert it in 169 // Generate an appropriate CrashEvent for a renderer crash and insert it in
137 // the database. 170 // the database.
138 void AddCrashEvent( 171 void AddCrashEvent(
139 const content::RenderProcessHost::RendererClosedDetails& details); 172 const content::RenderProcessHost::RendererClosedDetails& details);
140 173
174 // A count of how many bytes have been read. This corresponds to the total
175 // number of bytes that have been read since PerformanceMonitor first started
176 // recording, and persists across browser runs. There are two separate counts:
177 // one for disk reads, and one for network reads.
178 ByteCount bytes_read_;
179
141 // The location at which the database files are stored; if empty, the database 180 // The location at which the database files are stored; if empty, the database
142 // will default to '<user_data_dir>/performance_monitor_dbs'. 181 // will default to '<user_data_dir>/performance_monitor_dbs'.
143 FilePath database_path_; 182 FilePath database_path_;
144 183
145 scoped_ptr<Database> database_; 184 scoped_ptr<Database> database_;
146 185
147 // A map of currently running ProcessHandles to ProcessMetrics. 186 // A map of currently running ProcessHandles to ProcessMetrics.
148 MetricsMap metrics_map_; 187 MetricsMap metrics_map_;
149 188
150 // The timer to signal PerformanceMonitor to perform its timed collections. 189 // The timer to signal PerformanceMonitor to perform its timed collections.
151 base::RepeatingTimer<PerformanceMonitor> timer_; 190 base::RepeatingTimer<PerformanceMonitor> timer_;
152 191
153 content::NotificationRegistrar registrar_; 192 content::NotificationRegistrar registrar_;
154 193
194 // A flag indicating whether or not PerformanceMonitor is initialized. Any
195 // external sources accessing PerformanceMonitor should either wait for
196 // the PERFORMANCE_MONITOR_INITIALIZED notification or should check this
197 // flag.
198 static bool initialized_;
199
155 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 200 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
156 }; 201 };
157 202
158 } // namespace performance_monitor 203 } // namespace performance_monitor
159 204
160 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 205 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698