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

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

Issue 10827151: Revert 149766 - Performance monitor stats gathering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
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>
9 #include <string> 8 #include <string>
10 9
11 #include "base/callback.h" 10 #include "base/callback.h"
12 #include "base/file_path.h" 11 #include "base/file_path.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
16 #include "base/process.h"
17 #include "base/process_util.h"
18 #include "base/timer.h" 14 #include "base/timer.h"
19 #include "chrome/browser/performance_monitor/database.h" 15 #include "chrome/browser/performance_monitor/database.h"
20 #include "chrome/browser/performance_monitor/event.h" 16 #include "chrome/browser/performance_monitor/event.h"
21 #include "content/public/browser/notification_details.h" 17 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
25 21
26 namespace performance_monitor { 22 namespace performance_monitor {
27 class Database; 23 class Database;
28 24
29 class PerformanceMonitor : public content::NotificationObserver { 25 class PerformanceMonitor : public content::NotificationObserver {
30 public: 26 public:
31 typedef base::Callback<void(const std::string&)> StateValueCallback; 27 typedef base::Callback<void(const std::string&)> StateValueCallback;
32 28
33 typedef std::map<base::ProcessHandle,
34 linked_ptr<base::ProcessMetrics> > MetricsMap;
35
36 // Set the path which the PerformanceMonitor should use for the database files 29 // Set the path which the PerformanceMonitor should use for the database files
37 // constructed. This must be done prior to the initialization of the 30 // constructed. This must be done prior to the initialization of the
38 // PerformanceMonitor. Returns true on success, false on failure (failure 31 // PerformanceMonitor. Returns true on success, false on failure (failure
39 // likely indicates that PerformanceMonitor has already been started at the 32 // likely indicates that PerformanceMonitor has already been started at the
40 // time of the call). 33 // time of the call).
41 bool SetDatabasePath(const FilePath& path); 34 bool SetDatabasePath(const FilePath& path);
42 35
43 // Returns the current PerformanceMonitor instance if one exists; otherwise 36 // Returns the current PerformanceMonitor instance if one exists; otherwise
44 // constructs a new PerformanceMonitor. 37 // constructs a new PerformanceMonitor.
45 static PerformanceMonitor* GetInstance(); 38 static PerformanceMonitor* GetInstance();
46 39
47 // Begins the initialization process for the PerformanceMonitor in order to 40 // Begins the initialization process for the PerformanceMonitor in order to
48 // start collecting data. 41 // start collecting data.
49 void Start(); 42 void Start();
50 43
51 // Gathers CPU usage and memory usage of all Chrome processes.
52 void GatherStatisticsOnBackgroundThread();
53
54 // content::NotificationObserver 44 // content::NotificationObserver
55 // Wait for various notifications; insert events into the database upon 45 // Wait for various notifications; insert events into the database upon
56 // occurance. 46 // occurance.
57 virtual void Observe(int type, 47 virtual void Observe(int type,
58 const content::NotificationSource& source, 48 const content::NotificationSource& source,
59 const content::NotificationDetails& details) OVERRIDE; 49 const content::NotificationDetails& details) OVERRIDE;
60 50
61 Database* database() { return database_.get(); } 51 Database* database() { return database_.get(); }
62 FilePath database_path() { return database_path_; } 52 FilePath database_path() { return database_path_; }
63 53
(...skipping 28 matching lines...) Expand all
92 82
93 // Check the previous Chrome version from the Database and determine if 83 // Check the previous Chrome version from the Database and determine if
94 // it has been updated. If it has, insert an event in the database. 84 // it has been updated. If it has, insert an event in the database.
95 void CheckForVersionUpdateOnBackgroundThread(); 85 void CheckForVersionUpdateOnBackgroundThread();
96 86
97 // Wrapper function for inserting events into the database. 87 // Wrapper function for inserting events into the database.
98 void AddEvent(scoped_ptr<Event> event); 88 void AddEvent(scoped_ptr<Event> event);
99 89
100 void AddEventOnBackgroundThread(scoped_ptr<Event> event); 90 void AddEventOnBackgroundThread(scoped_ptr<Event> event);
101 91
102 // Gathers the CPU usage of every Chrome process that has been running since
103 // the last call to GatherStatistics().
104 void GatherCPUUsageOnBackgroundThread();
105
106 // Gathers the memory usage of every process in the current list of processes.
107 void GatherMemoryUsageOnBackgroundThread();
108
109 // Updates the ProcessMetrics map with the current list of processes.
110 void UpdateMetricsMapOnBackgroundThread();
111
112 // Gets the corresponding value of |key| from the database, and then runs 92 // Gets the corresponding value of |key| from the database, and then runs
113 // |callback| on the UI thread with that value as a parameter. 93 // |callback| on the UI thread with that value as a parameter.
114 void GetStateValueOnBackgroundThread( 94 void GetStateValueOnBackgroundThread(
115 const std::string& key, 95 const std::string& key,
116 const StateValueCallback& callback); 96 const StateValueCallback& callback);
117 97
118 // Notify any listeners that PerformanceMonitor has finished the initializing. 98 // Notify any listeners that PerformanceMonitor has finished the initializing.
119 void NotifyInitialized(); 99 void NotifyInitialized();
120 100
121 // Update the database record of the last time the active profiles were 101 // Update the database record of the last time the active profiles were
122 // running; this is used in determining when an unclean exit occurred. 102 // running; this is used in determining when an unclean exit occurred.
123 void UpdateLiveProfiles(); 103 void UpdateLiveProfiles();
124 void UpdateLiveProfilesHelper( 104 void UpdateLiveProfilesHelper(
125 scoped_ptr<std::set<std::string> > active_profiles, std::string time); 105 scoped_ptr<std::set<std::string> > active_profiles, std::string time);
126 106
127 // Perform any collections that are done on a timed basis. 107 // Perform any collections that are done on a timed basis.
128 void DoTimedCollections(); 108 void DoTimedCollections();
129 109
130 // The location at which the database files are stored; if empty, the database 110 // The location at which the database files are stored; if empty, the database
131 // will default to '<user_data_dir>/performance_monitor_dbs'. 111 // will default to '<user_data_dir>/performance_monitor_dbs'.
132 FilePath database_path_; 112 FilePath database_path_;
133 113
134 scoped_ptr<Database> database_; 114 scoped_ptr<Database> database_;
135 115
136 // A map of currently running ProcessHandles to ProcessMetrics.
137 MetricsMap metrics_map_;
138
139 // The timer to signal PerformanceMonitor to perform its timed collections. 116 // The timer to signal PerformanceMonitor to perform its timed collections.
140 base::RepeatingTimer<PerformanceMonitor> timer_; 117 base::RepeatingTimer<PerformanceMonitor> timer_;
141 118
142 content::NotificationRegistrar registrar_; 119 content::NotificationRegistrar registrar_;
143 120
144 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 121 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
145 }; 122 };
146 123
147 } // namespace performance_monitor 124 } // namespace performance_monitor
148 125
149 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 126 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698