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

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: Numero 3 Created 8 years, 5 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 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <string>
11
9 #include "base/callback.h" 12 #include "base/callback.h"
10 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/memory/linked_ptr.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/process.h"
18 #include "base/process_util.h"
13 #include "chrome/browser/performance_monitor/database.h" 19 #include "chrome/browser/performance_monitor/database.h"
14 #include "chrome/browser/performance_monitor/event.h" 20 #include "chrome/browser/performance_monitor/event.h"
15 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
19 25
20 namespace performance_monitor { 26 namespace performance_monitor {
21 class Database; 27 class Database;
22 28
23 class PerformanceMonitor : public content::NotificationObserver { 29 class PerformanceMonitor : public content::NotificationObserver {
24 public: 30 public:
25 typedef base::Callback<void(const std::string&)> StateValueCallback; 31 typedef base::Callback<void(const std::string&)> StateValueCallback;
26 32
33 typedef std::map<base::ProcessHandle,
34 linked_ptr<base::ProcessMetrics> > MetricsMap;
35
27 // Set the path which the PerformanceMonitor should use for the database files 36 // Set the path which the PerformanceMonitor should use for the database files
28 // constructed. This must be done prior to the initialization of the 37 // constructed. This must be done prior to the initialization of the
29 // PerformanceMonitor. Returns true on success, false on failure (failure 38 // PerformanceMonitor. Returns true on success, false on failure (failure
30 // likely indicates that PerformanceMonitor has already been started at the 39 // likely indicates that PerformanceMonitor has already been started at the
31 // time of the call). 40 // time of the call).
32 bool SetDatabasePath(const FilePath& path); 41 bool SetDatabasePath(const FilePath& path);
33 42
34 // Returns the current PerformanceMonitor instance if one exists; otherwise 43 // Returns the current PerformanceMonitor instance if one exists; otherwise
35 // constructs a new PerformanceMonitor. 44 // constructs a new PerformanceMonitor.
36 static PerformanceMonitor* GetInstance(); 45 static PerformanceMonitor* GetInstance();
37 46
38 // Begins the initialization process for the PerformanceMonitor in order to 47 // Begins the initialization process for the PerformanceMonitor in order to
39 // start collecting data. 48 // start collecting data.
40 void Start(); 49 void Start();
41 50
42 // Check the previous Chrome version from the Database and determine if 51 // Check the previous Chrome version from the Database and determine if
43 // it has been updated. If it has, insert an event in the database. 52 // it has been updated. If it has, insert an event in the database.
44 void CheckForVersionUpdate(); 53 void CheckForVersionUpdate();
45 54
55 // Gathers CPU usage and memory usage of all Chrome processes.
56 void GatherStatisticsOnBackgroundThread();
57
46 // content::NotificationObserver 58 // content::NotificationObserver
47 // Wait for various notifications; insert events into the database upon 59 // Wait for various notifications; insert events into the database upon
48 // occurance. 60 // occurance.
49 virtual void Observe(int type, 61 virtual void Observe(int type,
50 const content::NotificationSource& source, 62 const content::NotificationSource& source,
51 const content::NotificationDetails& details) OVERRIDE; 63 const content::NotificationDetails& details) OVERRIDE;
52 64
53 Database* database() { return database_.get(); } 65 Database* database() { return database_.get(); }
54 FilePath database_path() { return database_path_; } 66 FilePath database_path() { return database_path_; }
55 67
(...skipping 18 matching lines...) Expand all
74 const std::string& key, 86 const std::string& key,
75 const StateValueCallback& callback); 87 const StateValueCallback& callback);
76 88
77 void CheckForVersionUpdateHelper(const std::string& previous_version); 89 void CheckForVersionUpdateHelper(const std::string& previous_version);
78 90
79 // Wrapper function for inserting events into the database. 91 // Wrapper function for inserting events into the database.
80 void AddEvent(scoped_ptr<Event> event); 92 void AddEvent(scoped_ptr<Event> event);
81 93
82 void AddEventOnBackgroundThread(scoped_ptr<Event> event); 94 void AddEventOnBackgroundThread(scoped_ptr<Event> event);
83 95
96 // Gathers the CPU usage of every process that has been running since the
97 // last call to GatherStatistics().
98 void GatherCPUUsage();
99
100 // Gathers the memory usage of every process in the current list of processes.
101 void GatherMemoryUsage();
102
103 // Updates the ProcessMetrics map with the current list of processes.
104 void UpdateMetricsMap();
105
106
Devlin 2012/07/17 18:07:58 extra newline; also a short comment may be in orde
mitchellwrosen 2012/07/20 19:42:36 Done.
107 MetricsMap metrics_map_;
108
84 // The location at which the database files are stored; if empty, the database 109 // The location at which the database files are stored; if empty, the database
85 // will default to '<user_data_dir>/performance_monitor_dbs'. 110 // will default to '<user_data_dir>/performance_monitor_dbs'.
86 FilePath database_path_; 111 FilePath database_path_;
87 112
88 scoped_ptr<Database> database_; 113 scoped_ptr<Database> database_;
89 114
90 content::NotificationRegistrar registrar_; 115 content::NotificationRegistrar registrar_;
91 116
92 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor); 117 DISALLOW_COPY_AND_ASSIGN(PerformanceMonitor);
93 }; 118 };
94 119
95 } // namespace performance_monitor 120 } // namespace performance_monitor
96 121
97 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_ 122 #endif // CHROME_BROWSER_PERFORMANCE_MONITOR_PERFORMANCE_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698