blob: dd042fcbb84fc43f830f7b6f7d134fe4ad75b0bf [file] [log] [blame]
[email protected]82916812012-02-21 04:14:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]a5d1e1e2010-09-23 19:34:125#ifndef CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
6#define CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]b7937d5b2008-09-10 22:12:198#include <map>
[email protected]b7937d5b2008-09-10 22:12:199#include <vector>
10
[email protected]5d438dbad2009-04-30 08:59:3911#include "base/basictypes.h"
[email protected]20f5f8a32013-08-20 01:50:5812#include "base/callback_forward.h"
[email protected]a918f872010-06-01 14:30:5113#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
15#include "base/memory/singleton.h"
[email protected]a754453c2009-07-15 20:32:5116#include "base/observer_list.h"
[email protected]9f0abdb2013-06-10 21:49:3417#include "base/strings/string16.h"
[email protected]cc86ccfe2013-06-28 00:10:5018#include "base/timer/timer.h"
[email protected]2c434b32009-03-19 06:27:4719#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]b18943a2013-05-23 15:59:1520#include "chrome/browser/task_manager/resource_provider.h"
[email protected]ddeb0e8432012-12-21 07:27:5421#include "chrome/browser/ui/host_desktop.h"
[email protected]fb246af2012-08-18 03:11:4122#include "content/public/common/gpu_memory_stats.h"
[email protected]2255a9332013-06-17 05:12:3123#include "third_party/WebKit/public/web/WebCache.h"
initial.commit09911bf2008-07-26 23:55:2924
[email protected]b1de2c72013-02-06 02:45:4725class PrefRegistrySimple;
[email protected]0860b9b92009-05-11 18:49:1826class TaskManagerModel;
[email protected]2344ca52012-08-22 22:46:0527class TaskManagerModelGpuDataManagerObserver;
initial.commit09911bf2008-07-26 23:55:2928
[email protected]176aa482008-11-14 03:25:1529namespace base {
initial.commit09911bf2008-07-26 23:55:2930class ProcessMetrics;
31}
[email protected]1c321ee2012-05-21 03:02:3432
[email protected]7ed0e8c2012-07-19 23:17:0633namespace content {
34class WebContents;
35}
36
[email protected]1c321ee2012-05-21 03:02:3437namespace extensions {
38class Extension;
39}
40
[email protected]6280b5882012-06-05 21:56:4141namespace gfx {
42class ImageSkia;
43}
44
[email protected]8523ba52011-05-22 19:00:5845namespace net {
46class URLRequest;
47}
initial.commit09911bf2008-07-26 23:55:2948
initial.commit09911bf2008-07-26 23:55:2949// This class is a singleton.
[email protected]f9fdb072009-05-06 07:27:4050class TaskManager {
initial.commit09911bf2008-07-26 23:55:2951 public:
[email protected]b1de2c72013-02-06 02:45:4752 static void RegisterPrefs(PrefRegistrySimple* registry);
initial.commit09911bf2008-07-26 23:55:2953
[email protected]8f90afd72009-06-22 22:44:3854 // Returns true if the process at the specified index is the browser process.
55 bool IsBrowserProcess(int index) const;
initial.commit09911bf2008-07-26 23:55:2956
[email protected]8f90afd72009-06-22 22:44:3857 // Terminates the process at the specified index.
58 void KillProcess(int index);
initial.commit09911bf2008-07-26 23:55:2959
[email protected]8f90afd72009-06-22 22:44:3860 // Activates the browser tab associated with the process in the specified
61 // index.
62 void ActivateProcess(int index);
[email protected]b7937d5b2008-09-10 22:12:1963
initial.commit09911bf2008-07-26 23:55:2964 // These methods are invoked by the resource providers to add/remove resources
65 // to the Task Manager. Note that the resources are owned by the
66 // ResourceProviders and are not valid after StopUpdating() has been called
67 // on the ResourceProviders.
[email protected]b18943a2013-05-23 15:59:1568 void AddResource(task_manager::Resource* resource);
69 void RemoveResource(task_manager::Resource* resource);
initial.commit09911bf2008-07-26 23:55:2970
[email protected]9c5e4172009-05-27 08:46:2871 void OnWindowClosed();
72
[email protected]c43207e2010-11-15 18:09:5273 // Invoked when a change to a resource has occurred that should cause any
74 // observers to completely refresh themselves (for example, the creation of
75 // a background resource in a process). Results in all observers receiving
76 // OnModelChanged() events.
77 void ModelChanged();
78
[email protected]8f90afd72009-06-22 22:44:3879 // Returns the singleton instance (and initializes it if necessary).
80 static TaskManager* GetInstance();
81
82 TaskManagerModel* model() const { return model_.get(); }
83
[email protected]ddeb0e8432012-12-21 07:27:5484 void OpenAboutMemory(chrome::HostDesktopType desktop_type);
[email protected]8f0d1a22009-10-08 19:55:1485
initial.commit09911bf2008-07-26 23:55:2986 private:
[email protected]a918f872010-06-01 14:30:5187 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, Basic);
88 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, Resources);
89 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled);
[email protected]5ec892c2010-07-29 20:19:4990 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest, Init);
91 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest, Sort);
[email protected]c1b7d8cca2010-08-07 23:07:5892 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest,
93 SelectionAdaptsToSorting);
[email protected]1222cce2009-04-27 06:58:2794
initial.commit09911bf2008-07-26 23:55:2995 // Obtain an instance via GetInstance().
96 TaskManager();
[email protected]5d438dbad2009-04-30 08:59:3997 friend struct DefaultSingletonTraits<TaskManager>;
initial.commit09911bf2008-07-26 23:55:2998
99 ~TaskManager();
100
[email protected]0860b9b92009-05-11 18:49:18101 // The model used for gathering and processing task data. It is ref counted
102 // because it is passed as a parameter to MessageLoop::InvokeLater().
103 scoped_refptr<TaskManagerModel> model_;
initial.commit09911bf2008-07-26 23:55:29104
[email protected]bfac5ac2008-10-09 17:55:38105 DISALLOW_COPY_AND_ASSIGN(TaskManager);
initial.commit09911bf2008-07-26 23:55:29106};
107
[email protected]0860b9b92009-05-11 18:49:18108class TaskManagerModelObserver {
initial.commit09911bf2008-07-26 23:55:29109 public:
[email protected]0860b9b92009-05-11 18:49:18110 virtual ~TaskManagerModelObserver() {}
initial.commit09911bf2008-07-26 23:55:29111
[email protected]0860b9b92009-05-11 18:49:18112 // Invoked when the model has been completely changed.
113 virtual void OnModelChanged() = 0;
initial.commit09911bf2008-07-26 23:55:29114
[email protected]0860b9b92009-05-11 18:49:18115 // Invoked when a range of items has changed.
116 virtual void OnItemsChanged(int start, int length) = 0;
117
118 // Invoked when new items are added.
119 virtual void OnItemsAdded(int start, int length) = 0;
120
121 // Invoked when a range of items has been removed.
122 virtual void OnItemsRemoved(int start, int length) = 0;
[email protected]82916812012-02-21 04:14:17123
[email protected]350584cd2012-05-17 18:18:26124 // Invoked when a range of items is to be immediately removed. It differs
125 // from OnItemsRemoved by the fact that the item is still in the task manager,
126 // so it can be queried for and found.
127 virtual void OnItemsToBeRemoved(int start, int length) {}
128
[email protected]82916812012-02-21 04:14:17129 // Invoked when the initialization of the model has been finished and
130 // periodical updates is started. The first periodical update will be done
131 // in a few seconds. (depending on platform)
132 virtual void OnReadyPeriodicalUpdate() {}
[email protected]0860b9b92009-05-11 18:49:18133};
134
[email protected]b6eaebd72013-01-15 23:04:09135// The model used by TaskManager.
136//
[email protected]b18943a2013-05-23 15:59:15137// TaskManagerModel caches the values from all task_manager::Resources. This is
[email protected]b6eaebd72013-01-15 23:04:09138// done so the UI sees a consistant view of the resources until it is told a
139// value has been updated.
[email protected]8523ba52011-05-22 19:00:58140class TaskManagerModel : public base::RefCountedThreadSafe<TaskManagerModel> {
[email protected]0860b9b92009-05-11 18:49:18141 public:
[email protected]abd81a522012-03-02 16:12:45142 // (start, length)
143 typedef std::pair<int, int> GroupRange;
144
[email protected]0860b9b92009-05-11 18:49:18145 explicit TaskManagerModel(TaskManager* task_manager);
[email protected]0860b9b92009-05-11 18:49:18146
[email protected]a754453c2009-07-15 20:32:51147 void AddObserver(TaskManagerModelObserver* observer);
148 void RemoveObserver(TaskManagerModelObserver* observer);
[email protected]0860b9b92009-05-11 18:49:18149
150 // Returns number of registered resources.
151 int ResourceCount() const;
[email protected]9f5d3e182011-07-11 06:22:29152 // Returns number of registered groups.
153 int GroupCount() const;
[email protected]0860b9b92009-05-11 18:49:18154
[email protected]8a661f82010-10-19 21:47:11155 // Methods to return raw resource information.
[email protected]bb4ee2d2014-01-10 02:12:59156 int GetNaClDebugStubPort(int index) const;
[email protected]8a661f82010-10-19 21:47:11157 int64 GetNetworkUsage(int index) const;
158 double GetCPUUsage(int index) const;
[email protected]ac6d0652014-01-14 00:06:37159 int GetIdleWakeupsPerSecond(int index) const;
[email protected]b6eaebd72013-01-15 23:04:09160 base::ProcessId GetProcessId(int index) const;
[email protected]350584cd2012-05-17 18:18:26161 base::ProcessHandle GetProcess(int index) const;
[email protected]ef72ae02011-10-28 16:28:59162 int GetResourceUniqueId(int index) const;
[email protected]28989c32011-12-14 19:41:36163 // Returns the index of resource that has the given |unique_id|. Returns -1 if
164 // no resouce has the |unique_id|.
165 int GetResourceIndexByUniqueId(const int unique_id) const;
[email protected]8a661f82010-10-19 21:47:11166
[email protected]36cdba02013-01-12 20:16:40167 // Catchall method that calls off to the appropriate GetResourceXXX method
168 // based on |col_id|. |col_id| is an IDS_ value used to identify the column.
[email protected]0085863a2013-12-06 21:19:03169 base::string16 GetResourceById(int index, int col_id) const;
[email protected]36cdba02013-01-12 20:16:40170
[email protected]0860b9b92009-05-11 18:49:18171 // Methods to return formatted resource information.
[email protected]0085863a2013-12-06 21:19:03172 const base::string16& GetResourceTitle(int index) const;
173 const base::string16& GetResourceProfileName(int index) const;
[email protected]bb4ee2d2014-01-10 02:12:59174 base::string16 GetResourceNaClDebugStubPort(int index) const;
[email protected]0085863a2013-12-06 21:19:03175 base::string16 GetResourceNetworkUsage(int index) const;
176 base::string16 GetResourceCPUUsage(int index) const;
177 base::string16 GetResourcePrivateMemory(int index) const;
178 base::string16 GetResourceSharedMemory(int index) const;
179 base::string16 GetResourcePhysicalMemory(int index) const;
180 base::string16 GetResourceProcessId(int index) const;
181 base::string16 GetResourceGDIHandles(int index) const;
182 base::string16 GetResourceUSERHandles(int index) const;
183 base::string16 GetResourceWebCoreImageCacheSize(int index) const;
184 base::string16 GetResourceWebCoreScriptsCacheSize(int index) const;
185 base::string16 GetResourceWebCoreCSSCacheSize(int index) const;
186 base::string16 GetResourceVideoMemory(int index) const;
187 base::string16 GetResourceFPS(int index) const;
188 base::string16 GetResourceSqliteMemoryUsed(int index) const;
[email protected]ac6d0652014-01-14 00:06:37189 base::string16 GetResourceIdleWakeupsPerSecond(int index) const;
[email protected]0085863a2013-12-06 21:19:03190 base::string16 GetResourceGoatsTeleported(int index) const;
191 base::string16 GetResourceV8MemoryAllocatedSize(int index) const;
[email protected]0860b9b92009-05-11 18:49:18192
[email protected]8a661f82010-10-19 21:47:11193 // Gets the private memory (in bytes) that should be displayed for the passed
194 // resource index. Caches the result since this calculation can take time on
195 // some platforms.
196 bool GetPrivateMemory(int index, size_t* result) const;
197
198 // Gets the shared memory (in bytes) that should be displayed for the passed
199 // resource index. Caches the result since this calculation can take time on
200 // some platforms.
201 bool GetSharedMemory(int index, size_t* result) const;
202
203 // Gets the physical memory (in bytes) that should be displayed for the passed
204 // resource index.
205 bool GetPhysicalMemory(int index, size_t* result) const;
206
[email protected]f2937472013-03-18 21:48:34207 // On Windows, get the current and peak number of GDI handles in use.
208 void GetGDIHandles(int index, size_t* current, size_t* peak) const;
209
210 // On Windows, get the current and peak number of USER handles in use.
211 void GetUSERHandles(int index, size_t* current, size_t* peak) const;
212
[email protected]5d8c0b92011-07-21 07:53:32213 // Gets the statuses of webkit. Return false if the resource for the given row
214 // isn't a renderer.
215 bool GetWebCoreCacheStats(int index,
[email protected]a1221aea2013-11-07 01:31:30216 blink::WebCache::ResourceTypeStats* result) const;
[email protected]5d8c0b92011-07-21 07:53:32217
[email protected]fb246af2012-08-18 03:11:41218 // Gets the GPU memory allocated of the given page.
219 bool GetVideoMemory(int index,
220 size_t* video_memory,
221 bool* has_duplicates) const;
222
[email protected]5d8c0b92011-07-21 07:53:32223 // Gets the fps of the given page. Return false if the resource for the given
224 // row isn't a renderer.
225 bool GetFPS(int index, float* result) const;
226
227 // Gets the sqlite memory (in byte). Return false if the resource for the
228 // given row doesn't report information.
229 bool GetSqliteMemoryUsedBytes(int index, size_t* result) const;
230
[email protected]8a661f82010-10-19 21:47:11231 // Gets the amount of memory allocated for javascript. Returns false if the
232 // resource for the given row isn't a renderer.
233 bool GetV8Memory(int index, size_t* result) const;
234
[email protected]350584cd2012-05-17 18:18:26235 // Gets the amount of memory used for javascript. Returns false if the
236 // resource for the given row isn't a renderer.
237 bool GetV8MemoryUsed(int index, size_t* result) const;
238
[email protected]374bf592011-11-10 15:42:18239 // Returns true if resource for the given row can be activated.
240 bool CanActivate(int index) const;
241
[email protected]0f62bb2d2011-10-26 14:48:33242 // Returns true if resource for the given row can be inspected using developer
243 // tools.
244 bool CanInspect(int index) const;
245
246 // Invokes or reveals developer tools window for resource in the given row.
247 void Inspect(int index) const;
248
[email protected]8a661f82010-10-19 21:47:11249 // See design doc at http://go/at-teleporter for more information.
250 int GetGoatsTeleported(int index) const;
251
[email protected]9f5d3e182011-07-11 06:22:29252 // Returns true if the resource is first/last in its group (resources
[email protected]0860b9b92009-05-11 18:49:18253 // rendered by the same process are groupped together).
254 bool IsResourceFirstInGroup(int index) const;
[email protected]9f5d3e182011-07-11 06:22:29255 bool IsResourceLastInGroup(int index) const;
[email protected]0860b9b92009-05-11 18:49:18256
[email protected]c43207e2010-11-15 18:09:52257 // Returns true if the resource runs in the background (not visible to the
258 // user, e.g. extension background pages and BackgroundContents).
259 bool IsBackgroundResource(int index) const;
260
[email protected]0860b9b92009-05-11 18:49:18261 // Returns icon to be used for resource (for example a favicon).
[email protected]6280b5882012-06-05 21:56:41262 gfx::ImageSkia GetResourceIcon(int index) const;
[email protected]0860b9b92009-05-11 18:49:18263
[email protected]abd81a522012-03-02 16:12:45264 // Returns the group range of resource.
265 GroupRange GetGroupRangeForResource(int index) const;
[email protected]0860b9b92009-05-11 18:49:18266
[email protected]9f5d3e182011-07-11 06:22:29267 // Returns an index of groups to which the resource belongs.
268 int GetGroupIndexForResource(int index) const;
269
270 // Returns an index of resource which belongs to the |group_index|th group
271 // and which is the |index_in_group|th resource in group.
272 int GetResourceIndexForGroup(int group_index, int index_in_group) const;
273
[email protected]0860b9b92009-05-11 18:49:18274 // Compares values in column |col_id| and rows |row1|, |row2|.
275 // Returns -1 if value in |row1| is less than value in |row2|,
276 // 0 if they are equal, and 1 otherwise.
277 int CompareValues(int row1, int row2, int col_id) const;
278
[email protected]6bfb6e702012-04-05 17:18:22279 // Returns the unique child process ID generated by Chromium, not the OS
280 // process id. This is used to identify processes internally and for
281 // extensions. It is not meant to be displayed to the user.
282 int GetUniqueChildProcessId(int index) const;
283
[email protected]8a661f82010-10-19 21:47:11284 // Returns the type of the given resource.
[email protected]b18943a2013-05-23 15:59:15285 task_manager::Resource::Type GetResourceType(int index) const;
[email protected]8a661f82010-10-19 21:47:11286
[email protected]7ed0e8c2012-07-19 23:17:06287 // Returns WebContents of given resource or NULL if not applicable.
288 content::WebContents* GetResourceWebContents(int index) const;
initial.commit09911bf2008-07-26 23:55:29289
[email protected]e1725842009-10-20 06:40:15290 // Returns Extension of given resource or NULL if not applicable.
[email protected]1c321ee2012-05-21 03:02:34291 const extensions::Extension* GetResourceExtension(int index) const;
[email protected]e1725842009-10-20 06:40:15292
[email protected]b18943a2013-05-23 15:59:15293 void AddResource(task_manager::Resource* resource);
294 void RemoveResource(task_manager::Resource* resource);
initial.commit09911bf2008-07-26 23:55:29295
[email protected]0860b9b92009-05-11 18:49:18296 void StartUpdating();
297 void StopUpdating();
initial.commit09911bf2008-07-26 23:55:29298
[email protected]350584cd2012-05-17 18:18:26299 // Listening involves calling StartUpdating on all resource providers. This
300 // causes all of them to subscribe to notifications and enumerate current
301 // resources. It differs from StartUpdating that it doesn't start the
302 // Refresh timer. The end result is that we have a full view of resources, but
303 // don't spend unneeded time updating, unless we have a real need to.
304 void StartListening();
305 void StopListening();
306
[email protected]0860b9b92009-05-11 18:49:18307 void Clear(); // Removes all items.
308
[email protected]c43207e2010-11-15 18:09:52309 // Sends OnModelChanged() to all observers to inform them of significant
310 // changes to the model.
311 void ModelChanged();
312
[email protected]156402ab2013-09-04 21:12:31313 // Updates the values for all rows.
314 void Refresh();
315
[email protected]ec9773682009-09-25 17:59:03316 void NotifyResourceTypeStats(
[email protected]38b48a82009-11-11 01:51:32317 base::ProcessId renderer_id,
[email protected]a1221aea2013-11-07 01:31:30318 const blink::WebCache::ResourceTypeStats& stats);
[email protected]ec9773682009-09-25 17:59:03319
[email protected]872ae5b2011-05-26 20:20:50320 void NotifyFPS(base::ProcessId renderer_id,
321 int routing_id,
322 float fps);
323
[email protected]fb246af2012-08-18 03:11:41324 void NotifyVideoMemoryUsageStats(
325 const content::GPUVideoMemoryUsageStats& video_memory_usage_stats);
326
[email protected]38b48a82009-11-11 01:51:32327 void NotifyV8HeapStats(base::ProcessId renderer_id,
328 size_t v8_memory_allocated,
329 size_t v8_memory_used);
330
[email protected]8523ba52011-05-22 19:00:58331 void NotifyBytesRead(const net::URLRequest& request, int bytes_read);
332
[email protected]20f5f8a32013-08-20 01:50:58333 void RegisterOnDataReadyCallback(const base::Closure& callback);
334
335 void NotifyDataReady();
336
[email protected]0860b9b92009-05-11 18:49:18337 private:
[email protected]e6e6ba42009-11-07 01:56:19338 friend class base::RefCountedThreadSafe<TaskManagerModel>;
[email protected]c4a9d852013-09-26 17:10:36339 friend class TaskManagerNoShowBrowserTest;
[email protected]8a661f82010-10-19 21:47:11340 FRIEND_TEST_ALL_PREFIXES(ExtensionApiTest, ProcessesVsTaskManager);
[email protected]b6eaebd72013-01-15 23:04:09341 FRIEND_TEST_ALL_PREFIXES(TaskManagerTest, RefreshCalled);
342 FRIEND_TEST_ALL_PREFIXES(TaskManagerWindowControllerTest,
343 SelectionAdaptsToSorting);
[email protected]e6e6ba42009-11-07 01:56:19344
[email protected]bfac5ac2008-10-09 17:55:38345 enum UpdateState {
346 IDLE = 0, // Currently not updating.
347 TASK_PENDING, // An update task is pending.
348 STOPPING // A update task is pending and it should stop the update.
349 };
350
[email protected]a9bd323d2013-06-17 20:27:56351 // The delay between updates of the information (in ms).
352#if defined(OS_MACOSX)
353 // Match Activity Monitor's default refresh rate.
354 static const int kUpdateTimeMs = 2000;
355#else
356 static const int kUpdateTimeMs = 1000;
357#endif
358
[email protected]b6eaebd72013-01-15 23:04:09359 // Values cached per resource. Values are validated on demand. The is_XXX
360 // members indicate if a value is valid.
361 struct PerResourceValues {
362 PerResourceValues();
363 ~PerResourceValues();
364
[email protected]bb4ee2d2014-01-10 02:12:59365 bool is_nacl_debug_stub_port_valid;
366 int nacl_debug_stub_port;
367
[email protected]b6eaebd72013-01-15 23:04:09368 bool is_title_valid;
[email protected]0085863a2013-12-06 21:19:03369 base::string16 title;
[email protected]b6eaebd72013-01-15 23:04:09370
371 bool is_profile_name_valid;
[email protected]0085863a2013-12-06 21:19:03372 base::string16 profile_name;
[email protected]b6eaebd72013-01-15 23:04:09373
374 // No is_network_usage since default (0) is fine.
375 int64 network_usage;
376
377 bool is_process_id_valid;
378 base::ProcessId process_id;
379
380 bool is_goats_teleported_valid;
381 int goats_teleported;
382
383 bool is_webcore_stats_valid;
[email protected]a1221aea2013-11-07 01:31:30384 blink::WebCache::ResourceTypeStats webcore_stats;
[email protected]b6eaebd72013-01-15 23:04:09385
386 bool is_fps_valid;
387 float fps;
388
389 bool is_sqlite_memory_bytes_valid;
390 size_t sqlite_memory_bytes;
391
392 bool is_v8_memory_valid;
393 size_t v8_memory_allocated;
394 size_t v8_memory_used;
395 };
396
397 // Values cached per process. Values are validated on demand. The is_XXX
398 // members indicate if a value is valid.
399 struct PerProcessValues {
400 PerProcessValues();
401 ~PerProcessValues();
402
403 bool is_cpu_usage_valid;
404 double cpu_usage;
405
[email protected]ac6d0652014-01-14 00:06:37406 bool is_idle_wakeups_valid;
407 int idle_wakeups;
408
[email protected]b6eaebd72013-01-15 23:04:09409 bool is_private_and_shared_valid;
410 size_t private_bytes;
411 size_t shared_bytes;
412
413 bool is_physical_memory_valid;
414 size_t physical_memory;
415
416 bool is_video_memory_valid;
417 size_t video_memory;
418 bool video_memory_has_duplicates;
[email protected]f2937472013-03-18 21:48:34419
420 bool is_gdi_handles_valid;
421 size_t gdi_handles;
422 size_t gdi_handles_peak;
423
424 bool is_user_handles_valid;
425 size_t user_handles;
426 size_t user_handles_peak;
[email protected]b6eaebd72013-01-15 23:04:09427 };
428
[email protected]b18943a2013-05-23 15:59:15429 typedef std::vector<task_manager::Resource*> ResourceList;
430 typedef std::vector<scoped_refptr<task_manager::ResourceProvider> >
[email protected]b6eaebd72013-01-15 23:04:09431 ResourceProviderList;
432 typedef std::map<base::ProcessHandle, ResourceList*> GroupMap;
433 typedef std::map<base::ProcessHandle, base::ProcessMetrics*> MetricsMap;
[email protected]b18943a2013-05-23 15:59:15434 typedef std::map<task_manager::Resource*, int64> ResourceValueMap;
435 typedef std::map<task_manager::Resource*,
[email protected]b6eaebd72013-01-15 23:04:09436 PerResourceValues> PerResourceCache;
437 typedef std::map<base::ProcessHandle, PerProcessValues> PerProcessCache;
438
initial.commit09911bf2008-07-26 23:55:29439 // This struct is used to exchange information between the io and ui threads.
440 struct BytesReadParam {
[email protected]cdf682e2011-02-05 05:11:28441 BytesReadParam(int origin_pid,
[email protected]3b490c82014-01-03 00:17:47442 int child_id,
443 int route_id,
[email protected]76543b92009-08-31 17:27:45444 int byte_count)
[email protected]cdf682e2011-02-05 05:11:28445 : origin_pid(origin_pid),
[email protected]3b490c82014-01-03 00:17:47446 child_id(child_id),
447 route_id(route_id),
[email protected]76543b92009-08-31 17:27:45448 byte_count(byte_count) {}
initial.commit09911bf2008-07-26 23:55:29449
[email protected]cdf682e2011-02-05 05:11:28450 // The process ID that triggered the request. For plugin requests this
451 // will differ from the renderer process ID.
452 int origin_pid;
[email protected]76543b92009-08-31 17:27:45453
[email protected]3b490c82014-01-03 00:17:47454 // The child ID of the process this request was routed through.
455 int child_id;
[email protected]76543b92009-08-31 17:27:45456
[email protected]3b490c82014-01-03 00:17:47457 int route_id;
initial.commit09911bf2008-07-26 23:55:29458 int byte_count;
459 };
460
[email protected]b6eaebd72013-01-15 23:04:09461 ~TaskManagerModel();
initial.commit09911bf2008-07-26 23:55:29462
[email protected]b6eaebd72013-01-15 23:04:09463 // Callback from the timer to refresh. Invokes Refresh() as appropriate.
464 void RefreshCallback();
465
[email protected]fb246af2012-08-18 03:11:41466 void RefreshVideoMemoryUsageStats();
467
initial.commit09911bf2008-07-26 23:55:29468 // Returns the network usage (in bytes per seconds) for the specified
469 // resource. That's the value retrieved at the last timer's tick.
[email protected]b18943a2013-05-23 15:59:15470 int64 GetNetworkUsageForResource(task_manager::Resource* resource) const;
initial.commit09911bf2008-07-26 23:55:29471
initial.commit09911bf2008-07-26 23:55:29472 // Called on the UI thread when some bytes are read.
473 void BytesRead(BytesReadParam param);
474
[email protected]f173d152012-10-17 21:02:41475 void MultipleBytesRead(const std::vector<BytesReadParam>* params);
476
477 // Notifies the UI thread about all the bytes read. Allows for coalescing
478 // multiple bytes read into a single task for the UI thread. This is important
479 // for when downloading a lot of data on the IO thread, since posting a Task
480 // for each one is expensive.
481 void NotifyMultipleBytesRead();
482
[email protected]bfac5ac2008-10-09 17:55:38483 // Returns the network usage (in byte per second) that should be displayed for
484 // the passed |resource|. -1 means the information is not available for that
485 // resource.
[email protected]b18943a2013-05-23 15:59:15486 int64 GetNetworkUsage(task_manager::Resource* resource) const;
[email protected]bfac5ac2008-10-09 17:55:38487
488 // Returns the CPU usage (in %) that should be displayed for the passed
489 // |resource|.
[email protected]b18943a2013-05-23 15:59:15490 double GetCPUUsage(task_manager::Resource* resource) const;
[email protected]bfac5ac2008-10-09 17:55:38491
[email protected]ac6d0652014-01-14 00:06:37492 // Returns the idle wakeups that should be displayed for the passed
493 // |resource|.
494 int GetIdleWakeupsPerSecond(task_manager::Resource* resource) const;
495
[email protected]d0767cb542009-10-08 17:38:30496 // Given a number, this function returns the formatted string that should be
497 // displayed in the task manager's memory cell.
[email protected]0085863a2013-12-06 21:19:03498 base::string16 GetMemCellText(int64 number) const;
[email protected]2a5af8a2009-01-23 23:13:05499
[email protected]b6eaebd72013-01-15 23:04:09500 // Verifies the private and shared memory for |handle| is valid in
501 // |per_process_cache_|. Returns true if the data in |per_process_cache_| is
502 // valid.
503 bool CachePrivateAndSharedMemory(base::ProcessHandle handle) const;
504
505 // Verifies |webcore_stats| in |per_resource_cache_|, returning true on
506 // success.
507 bool CacheWebCoreStats(int index) const;
508
509 // Verifies |v8_memory_allocated| and |v8_memory_used| in
510 // |per_resource_cache_|. Returns true if valid, false if not valid.
511 bool CacheV8Memory(int index) const;
[email protected]98947a02010-05-11 17:46:08512
[email protected]0f4ffe842011-03-30 18:59:46513 // Adds a resource provider to be managed.
[email protected]b18943a2013-05-23 15:59:15514 void AddResourceProvider(task_manager::ResourceProvider* provider);
[email protected]0f4ffe842011-03-30 18:59:46515
[email protected]b6eaebd72013-01-15 23:04:09516 // Returns the PerResourceValues for the specified index.
517 PerResourceValues& GetPerResourceValues(int index) const;
518
519 // Returns the Resource for the specified index.
[email protected]b18943a2013-05-23 15:59:15520 task_manager::Resource* GetResource(int index) const;
[email protected]b6eaebd72013-01-15 23:04:09521
initial.commit09911bf2008-07-26 23:55:29522 // The list of providers to the task manager. They are ref counted.
523 ResourceProviderList providers_;
524
525 // The list of all the resources displayed in the task manager. They are owned
526 // by the ResourceProviders.
527 ResourceList resources_;
528
529 // A map to keep tracks of the grouped resources (they are grouped if they
530 // share the same process). The groups (the Resources vectors) are owned by
531 // the model (but the actual Resources are owned by the ResourceProviders).
532 GroupMap group_map_;
533
534 // A map to retrieve the process metrics for a process. The ProcessMetrics are
535 // owned by the model.
536 MetricsMap metrics_map_;
537
538 // A map that keeps track of the number of bytes read per process since last
539 // tick. The Resources are owned by the ResourceProviders.
540 ResourceValueMap current_byte_count_map_;
541
[email protected]fb246af2012-08-18 03:11:41542 // A map that contains the video memory usage for a process
543 content::GPUVideoMemoryUsageStats video_memory_usage_stats_;
[email protected]b6eaebd72013-01-15 23:04:09544
545 // Set to true when we've requested video stats and false once we get them.
[email protected]fb246af2012-08-18 03:11:41546 bool pending_video_memory_usage_stats_update_;
547
[email protected]2344ca52012-08-22 22:46:05548 // An observer waiting for video memory usage stats updates from the GPU
549 // process
550 scoped_ptr<TaskManagerModelGpuDataManagerObserver>
551 video_memory_usage_stats_observer_;
552
[email protected]a754453c2009-07-15 20:32:51553 ObserverList<TaskManagerModelObserver> observer_list_;
initial.commit09911bf2008-07-26 23:55:29554
[email protected]8a661f82010-10-19 21:47:11555 // How many calls to StartUpdating have been made without matching calls to
556 // StopUpdating.
557 int update_requests_;
558
[email protected]350584cd2012-05-17 18:18:26559 // How many calls to StartListening have been made without matching calls to
560 // StopListening.
561 int listen_requests_;
562
[email protected]bfac5ac2008-10-09 17:55:38563 // Whether we are currently in the process of updating.
564 UpdateState update_state_;
565
[email protected]96373d02010-04-21 01:16:14566 // A salt lick for the goats.
[email protected]abd81a522012-03-02 16:12:45567 uint64 goat_salt_;
[email protected]96373d02010-04-21 01:16:14568
[email protected]ef72ae02011-10-28 16:28:59569 // Resource identifier that is unique within single session.
570 int last_unique_id_;
571
[email protected]f173d152012-10-17 21:02:41572 // Buffer for coalescing BytesReadParam so we don't have to post a task on
573 // each NotifyBytesRead() call.
574 std::vector<BytesReadParam> bytes_read_buffer_;
575
[email protected]20f5f8a32013-08-20 01:50:58576 std::vector<base::Closure> on_data_ready_callbacks_;
577
[email protected]b6eaebd72013-01-15 23:04:09578 // All per-Resource values are stored here.
579 mutable PerResourceCache per_resource_cache_;
580
581 // All per-Process values are stored here.
582 mutable PerProcessCache per_process_cache_;
583
[email protected]0860b9b92009-05-11 18:49:18584 DISALLOW_COPY_AND_ASSIGN(TaskManagerModel);
initial.commit09911bf2008-07-26 23:55:29585};
586
[email protected]a5d1e1e2010-09-23 19:34:12587#endif // CHROME_BROWSER_TASK_MANAGER_TASK_MANAGER_H_