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

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