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

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

Issue 547063003: Remove the unmaintained performance monitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Devlin's comments Created 6 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 <set>
10 #include <string>
11 9
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
15 #include "base/time/time.h"
16 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
17 #include "chrome/browser/performance_monitor/event_type.h"
18 #include "chrome/browser/performance_monitor/process_metrics_history.h" 12 #include "chrome/browser/performance_monitor/process_metrics_history.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/render_process_host.h"
22 13
23 template <typename Type> 14 template <typename Type>
24 struct DefaultSingletonTraits; 15 struct DefaultSingletonTraits;
25 16
26 namespace extensions { 17 namespace performance_monitor {
27 class Extension;
28 }
29 18
30 namespace net { 19 // The default interval at which PerformanceMonitor performs its timed
31 class URLRequest; 20 // collections.
32 } 21 const int kGatherIntervalInSeconds = 120;
Devlin 2014/09/10 21:40:57 Do we need this here, or could it be in an anonymo
33 22
34 namespace performance_monitor { 23 // PerformanceMonitor is a tool which periodically monitors performance metrics
35 class Database; 24 // for histogram logging and possibly taking action upon noticing serious
36 class Event; 25 // performance degradation.
37 struct Metric; 26 class PerformanceMonitor {
38
39 // PerformanceMonitor is a tool which will allow the user to view information
40 // about Chrome's performance over a period of time. It will gather statistics
41 // pertaining to performance-oriented areas (e.g. CPU usage, memory usage, and
42 // network usage) and will also store information about significant events which
43 // are related to performance, either being indicative (e.g. crashes) or
44 // potentially causal (e.g. extension installation/uninstallation).
45 //
46 // Thread Safety: PerformanceMonitor lives on multiple threads. When interacting
47 // with the Database, PerformanceMonitor acts on a background thread (which has
48 // the sequence guaranteed by a token, Database::kDatabaseSequenceToken). At
49 // other times, the PerformanceMonitor will act on the appropriate thread for
50 // the task (for instance, gathering statistics about CPU and memory usage
51 // is done on the background thread, but most notifications occur on the UI
52 // thread).
53 class PerformanceMonitor : public content::NotificationObserver {
54 public: 27 public:
55 struct PerformanceDataForIOThread {
56 PerformanceDataForIOThread();
57
58 uint64 network_bytes_read;
59 };
60
61 typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap; 28 typedef std::map<base::ProcessHandle, ProcessMetricsHistory> MetricsMap;
62 29
63 // Set the path which the PerformanceMonitor should use for the database files
64 // constructed. This must be done prior to the initialization of the
65 // PerformanceMonitor. Returns true on success, false on failure (failure
66 // likely indicates that PerformanceMonitor has already been started at the
67 // time of the call).
68 bool SetDatabasePath(const base::FilePath& path);
69
70 bool database_logging_enabled() const { return database_logging_enabled_; }
71
72 // Returns the current PerformanceMonitor instance if one exists; otherwise 30 // Returns the current PerformanceMonitor instance if one exists; otherwise
73 // constructs a new PerformanceMonitor. 31 // constructs a new PerformanceMonitor.
74 static PerformanceMonitor* GetInstance(); 32 static PerformanceMonitor* GetInstance();
75 33
76 // Begins the initialization process for the PerformanceMonitor in order to
77 // start collecting data.
78 void Initialize();
79
80 // Start the cycle of metrics gathering. 34 // Start the cycle of metrics gathering.
81 void StartGatherCycle(); 35 void StartGatherCycle();
82 36
83 // Inform PerformanceMonitor that bytes have been read; if these came across
84 // the network (and PerformanceMonitor is initialized), then increment the
85 // count accordingly.
86 void BytesReadOnIOThread(const net::URLRequest& request, const int bytes);
87
88 // content::NotificationObserver
89 // Wait for various notifications; insert events into the database upon
90 // occurance.
91 virtual void Observe(int type,
92 const content::NotificationSource& source,
93 const content::NotificationDetails& details) OVERRIDE;
94
95 Database* database() { return database_.get(); }
96 base::FilePath database_path() { return database_path_; }
97 static bool initialized() { return initialized_; }
98
99 private: 37 private:
100 friend struct DefaultSingletonTraits<PerformanceMonitor>; 38 friend struct DefaultSingletonTraits<PerformanceMonitor>;
101 friend class PerformanceMonitorBrowserTest;
102 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
103 OneProfileUncleanExit);
104 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorUncleanExitBrowserTest,
105 TwoProfileUncleanExit);
106 FRIEND_TEST_ALL_PREFIXES(PerformanceMonitorBrowserTest, NetworkBytesRead);
107 39
108 PerformanceMonitor(); 40 PerformanceMonitor();
109 virtual ~PerformanceMonitor(); 41 virtual ~PerformanceMonitor();
110 42
111 // Perform any additional initialization which must be performed on a
112 // background thread (e.g. constructing the database).
113 void InitOnBackgroundThread();
114
115 void FinishInit();
116
117 // Create the persistent database if we haven't already done so.
118 void InitializeDatabaseIfNeeded();
119
120 // Register for the appropriate notifications as a NotificationObserver.
121 void RegisterForNotifications();
122
123 // Checks for whether the previous profiles closed uncleanly; this method
124 // should only be called once per run in order to avoid duplication of events
125 // (exceptions made for testing purposes where we construct the environment).
126 void CheckForUncleanExits();
127
128 // Find the last active time for the profile and insert the event into the
129 // database.
130 void AddUncleanExitEventOnBackgroundThread(const std::string& profile_name);
131
132 // Check the previous Chrome version from the Database and determine if
133 // it has been updated. If it has, insert an event in the database.
134 void CheckForVersionUpdateOnBackgroundThread();
135
136 // Wrapper function for inserting events into the database.
137 void AddEvent(scoped_ptr<Event> event);
138
139 void AddEventOnBackgroundThread(scoped_ptr<Event> event);
140
141 // Since Database::AddMetric() is overloaded, base::Bind() does not work and
142 // we need a helper function.
143 void AddMetricOnBackgroundThread(const Metric& metric);
144
145 // Notify any listeners that PerformanceMonitor has finished the initializing.
146 void NotifyInitialized();
147
148 // Perform any collections that are done on a timed basis. 43 // Perform any collections that are done on a timed basis.
149 void DoTimedCollections(); 44 void DoTimedCollections();
150 45
151 // Update the database record of the last time the active profiles were
152 // running; this is used in determining when an unclean exit occurred.
153 #if !defined(OS_ANDROID)
154 void UpdateLiveProfiles();
155 void UpdateLiveProfilesHelper(
156 scoped_ptr<std::set<std::string> > active_profiles, std::string time);
157 #endif
158
159 // Stores CPU/memory usage metrics to the database.
160 void StoreMetricsOnBackgroundThread(
161 int current_update_sequence,
162 const PerformanceDataForIOThread& performance_data_for_io_thread);
163
164 // Mark the given process as alive in the current update iteration. 46 // Mark the given process as alive in the current update iteration.
165 // This means adding an entry to the map of watched processes if it's not 47 // This means adding an entry to the map of watched processes if it's not
166 // already present. 48 // already present.
167 void MarkProcessAsAlive(const base::ProcessHandle& handle, 49 void MarkProcessAsAlive(const base::ProcessHandle& handle,
168 int process_type, 50 int process_type,
169 int current_update_sequence); 51 int current_update_sequence);
170 52
171 // Updates the ProcessMetrics map with the current list of processes and 53 // Updates the ProcessMetrics map with the current list of processes and
172 // gathers metrics from each entry. 54 // gathers metrics from each entry.
173 void GatherMetricsMapOnUIThread(); 55 void GatherMetricsMapOnUIThread();
174 void GatherMetricsMapOnIOThread(int current_update_sequence); 56 void GatherMetricsMapOnIOThread(int current_update_sequence);
175 57
176 #if defined(ENABLE_EXTENSIONS)
177 // Generate an appropriate ExtensionEvent for an extension-related occurrance
178 // and insert it in the database.
179 void AddExtensionEvent(EventType type,
180 const extensions::Extension* extension);
181 #endif
182
183 // Generate an appropriate RendererFailure for a renderer crash and insert it
184 // in the database.
185 void AddRendererClosedEvent(
186 content::RenderProcessHost* host,
187 const content::RenderProcessHost::RendererClosedDetails& details);
188
189 // The store for all performance data that must be gathered from the IO
190 // thread.
191 PerformanceDataForIOThread performance_data_for_io_thread_;
192
193 // The location at which the database files are stored; if empty, the database
194 // will default to '<user_data_dir>/performance_monitor_dbs'.
195 base::FilePath database_path_;
196
197 scoped_ptr<Database> database_;
198
199 // A map of currently running ProcessHandles to ProcessMetrics. 58 // A map of currently running ProcessHandles to ProcessMetrics.
200 MetricsMap metrics_map_; 59 MetricsMap metrics_map_;
201 60
202 // The next time we should collect averages from the performance metrics
203 // and act on them.
204 base::Time next_collection_time_;
205
206 // How long to wait between collections.
207 int gather_interval_in_seconds_;
208
209 // Enable persistent logging of performance metrics to a database.
210 bool database_logging_enabled_;
211
212 // The timer to signal PerformanceMonitor to perform its timed collections. 61 // The timer to signal PerformanceMonitor to perform its timed collections.
213 base::DelayTimer<PerformanceMonitor> timer_; 62 base::RepeatingTimer<PerformanceMonitor> repeating_timer_;
214
215 content::NotificationRegistrar registrar_;
216
217 // A flag indicating whether or not PerformanceMonitor is initialized. Any
218 // external sources accessing PerformanceMonitor should either wait for
219 // the PERFORMANCE_MONITOR_INITIALIZED notification or should check this
220 // flag.
221 static bool initialized_;
222
223 // Disable auto-starting the collection timer; used for tests.
224 bool disable_timer_autostart_for_testing_;
225 63
226 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 64 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
227 }; 65 };
228 66
229 } // namespace performance_monitor 67 } // namespace performance_monitor
230 68
231 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 69 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698