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

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

Issue 10656052: Performance monitor stats gathering. (Closed) Base URL: http://git.chromium.org/chromium/src.git@cpm_main
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
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>
10
8 #include "base/callback.h" 11 #include "base/callback.h"
9 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/memory/linked_ptr.h"
10 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/process.h"
17 #include "base/process_util.h"
12 #include "chrome/browser/performance_monitor/database.h" 18 #include "chrome/browser/performance_monitor/database.h"
13 #include "chrome/browser/performance_monitor/event.h" 19 #include "chrome/browser/performance_monitor/event.h"
14 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
18 24
19 namespace performance_monitor { 25 namespace performance_monitor {
20 class Database; 26 class Database;
21 27
22 class PerformanceMonitor : public content::NotificationObserver { 28 class PerformanceMonitor : public content::NotificationObserver {
23 public: 29 public:
24 typedef base::Callback<void(const std::string&)> StateValueCallback; 30 typedef base::Callback<void(const std::string&)> StateValueCallback;
25 31
32 typedef std::map<base::ProcessHandle,
33 linked_ptr<base::ProcessMetrics> > MetricsMap;
34
26 // Set the path which the PerformanceMonitor should use for the database files 35 // Set the path which the PerformanceMonitor should use for the database files
27 // constructed. This must be done prior to the initialization of the 36 // constructed. This must be done prior to the initialization of the
28 // PerformanceMonitor. Returns true on success, false on failure (failure 37 // PerformanceMonitor. Returns true on success, false on failure (failure
29 // likely indicates that PerformanceMonitor has already been started at the 38 // likely indicates that PerformanceMonitor has already been started at the
30 // time of the call). 39 // time of the call).
31 bool SetDatabasePath(const FilePath& path); 40 bool SetDatabasePath(const FilePath& path);
32 41
33 // Returns the current PerformanceMonitor instance if one exists; otherwise 42 // Returns the current PerformanceMonitor instance if one exists; otherwise
34 // constructs a new PerformanceMonitor. 43 // constructs a new PerformanceMonitor.
35 static PerformanceMonitor* GetInstance(); 44 static PerformanceMonitor* GetInstance();
36 45
37 // Begins the initialization process for the PerformanceMonitor in order to 46 // Begins the initialization process for the PerformanceMonitor in order to
38 // start collecting data. 47 // start collecting data.
39 void Start(); 48 void Start();
40 49
50 // Gathers CPU usage and memory usage of all Chrome processes.
51 void GatherStatisticsOnBackgroundThread();
52
41 // content::NotificationObserver 53 // content::NotificationObserver
42 // Wait for various notifications; insert events into the database upon 54 // Wait for various notifications; insert events into the database upon
43 // occurance. 55 // occurance.
44 virtual void Observe(int type, 56 virtual void Observe(int type,
45 const content::NotificationSource& source, 57 const content::NotificationSource& source,
46 const content::NotificationDetails& details) OVERRIDE; 58 const content::NotificationDetails& details) OVERRIDE;
47 59
48 Database* database() { return database_.get(); } 60 Database* database() { return database_.get(); }
49 FilePath database_path() { return database_path_; } 61 FilePath database_path() { return database_path_; }
50 62
(...skipping 15 matching lines...) Expand all
66 78
67 // Check the previous Chrome version from the Database and determine if 79 // Check the previous Chrome version from the Database and determine if
68 // it has been updated. If it has, insert an event in the database. 80 // it has been updated. If it has, insert an event in the database.
69 void CheckForVersionUpdateOnBackgroundThread(); 81 void CheckForVersionUpdateOnBackgroundThread();
70 82
71 // Wrapper function for inserting events into the database. 83 // Wrapper function for inserting events into the database.
72 void AddEvent(scoped_ptr<Event> event); 84 void AddEvent(scoped_ptr<Event> event);
73 85
74 void AddEventOnBackgroundThread(scoped_ptr<Event> event); 86 void AddEventOnBackgroundThread(scoped_ptr<Event> event);
75 87
88 // Gathers the CPU usage of every Chrome process that has been running since
89 // the last call to GatherStatistics().
90 void GatherCPUUsageOnBackgroundThread();
91
92 // Gathers the memory usage of every process in the current list of processes.
93 void GatherMemoryUsageOnBackgroundThread();
94
95 // Updates the ProcessMetrics map with the current list of processes.
96 void UpdateMetricsMapOnBackgroundThread();
97
76 // Gets the corresponding value of |key| from the database, and then runs 98 // Gets the corresponding value of |key| from the database, and then runs
77 // |callback| on the UI thread with that value as a parameter. 99 // |callback| on the UI thread with that value as a parameter.
78 void GetStateValueOnBackgroundThread( 100 void GetStateValueOnBackgroundThread(
79 const std::string& key, 101 const std::string& key,
80 const StateValueCallback& callback); 102 const StateValueCallback& callback);
81 103
82 // Notify any listeners that PerformanceMonitor has finished the initializing. 104 // Notify any listeners that PerformanceMonitor has finished the initializing.
83 void NotifyInitialized(); 105 void NotifyInitialized();
84 106
85 // The location at which the database files are stored; if empty, the database 107 // The location at which the database files are stored; if empty, the database
86 // will default to '<user_data_dir>/performance_monitor_dbs'. 108 // will default to '<user_data_dir>/performance_monitor_dbs'.
87 FilePath database_path_; 109 FilePath database_path_;
88 110
89 scoped_ptr<Database> database_; 111 scoped_ptr<Database> database_;
90 112
113 // A map of currently running ProcessHandles to ProcessMetrics.
114 MetricsMap metrics_map_;
115
91 content::NotificationRegistrar registrar_; 116 content::NotificationRegistrar registrar_;
92 117
93 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 118 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
94 }; 119 };
95 120
96 } // namespace performance_monitor 121 } // namespace performance_monitor
97 122
98 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 123 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698