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

Side by Side Diff: chrome/browser/task_manager/child_process_resource_provider.cc

Issue 972083002: Report utility process JS memory in task manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-pac-oop
Patch Set: Clean up. Created 5 years, 8 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
« no previous file with comments | « no previous file | chrome/utility/BUILD.gn » ('j') | chrome/utility/chrome_content_utility_client.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/task_manager/child_process_resource_provider.h" 5 #include "chrome/browser/task_manager/child_process_resource_provider.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "chrome/browser/task_manager/resource_provider.h" 11 #include "chrome/browser/task_manager/resource_provider.h"
12 #include "chrome/browser/task_manager/task_manager.h" 12 #include "chrome/browser/task_manager/task_manager.h"
13 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
14 #include "components/nacl/common/nacl_process_type.h" 14 #include "components/nacl/common/nacl_process_type.h"
15 #include "content/public/browser/browser_child_process_host_iterator.h" 15 #include "content/public/browser/browser_child_process_host_iterator.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/child_process_data.h" 17 #include "content/public/browser/child_process_data.h"
18 #include "content/public/browser/process_resource_usage.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image_skia.h" 22 #include "ui/gfx/image/image_skia.h"
22 23
23 using content::BrowserChildProcessHostIterator; 24 using content::BrowserChildProcessHostIterator;
24 using content::BrowserThread; 25 using content::BrowserThread;
26 using content::ProcessResourceUsage;
25 using content::WebContents; 27 using content::WebContents;
26 28
27 namespace task_manager { 29 namespace task_manager {
28 30
29 class ChildProcessResource : public Resource { 31 class ChildProcessResource : public Resource {
30 public: 32 public:
31 ChildProcessResource(int process_type, 33 ChildProcessResource(
32 const base::string16& name, 34 int process_type,
33 base::ProcessHandle handle, 35 const base::string16& name,
34 int unique_process_id); 36 base::ProcessHandle handle,
37 int unique_process_id,
38 const scoped_refptr<ProcessResourceUsage>& resource_usage);
35 ~ChildProcessResource() override; 39 ~ChildProcessResource() override;
36 40
37 // Resource methods: 41 // Resource methods:
38 base::string16 GetTitle() const override; 42 base::string16 GetTitle() const override;
39 base::string16 GetProfileName() const override; 43 base::string16 GetProfileName() const override;
40 gfx::ImageSkia GetIcon() const override; 44 gfx::ImageSkia GetIcon() const override;
41 base::ProcessHandle GetProcess() const override; 45 base::ProcessHandle GetProcess() const override;
42 int GetUniqueChildProcessId() const override; 46 int GetUniqueChildProcessId() const override;
43 Type GetType() const override; 47 Type GetType() const override;
44 bool SupportNetworkUsage() const override; 48 bool SupportNetworkUsage() const override;
45 void SetSupportNetworkUsage() override; 49 void SetSupportNetworkUsage() override;
50 void Refresh() override;
51 bool ReportsV8MemoryStats() const override;
52 size_t GetV8MemoryAllocated() const override;
53 size_t GetV8MemoryUsed() const override;
46 54
47 // Returns the pid of the child process. 55 // Returns the pid of the child process.
48 int process_id() const { return pid_; } 56 int process_id() const { return pid_; }
49 57
50 private: 58 private:
51 // Returns a localized title for the child process. For example, a plugin 59 // Returns a localized title for the child process. For example, a plugin
52 // process would be "Plugin: Flash" when name is "Flash". 60 // process would be "Plugin: Flash" when name is "Flash".
53 base::string16 GetLocalizedTitle() const; 61 base::string16 GetLocalizedTitle() const;
54 62
55 int process_type_; 63 int process_type_;
56 base::string16 name_; 64 base::string16 name_;
57 base::ProcessHandle handle_; 65 base::ProcessHandle handle_;
58 int pid_; 66 int pid_;
59 int unique_process_id_; 67 int unique_process_id_;
60 mutable base::string16 title_; 68 mutable base::string16 title_;
61 bool network_usage_support_; 69 bool network_usage_support_;
70 scoped_refptr<ProcessResourceUsage> resource_usage_;
62 71
63 // The icon painted for the child processs. 72 // The icon painted for the child processs.
64 // TODO(jcampan): we should have plugin specific icons for well-known 73 // TODO(jcampan): we should have plugin specific icons for well-known
65 // plugins. 74 // plugins.
66 static gfx::ImageSkia* default_icon_; 75 static gfx::ImageSkia* default_icon_;
67 76
68 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); 77 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource);
69 }; 78 };
70 79
71 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; 80 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL;
72 81
73 ChildProcessResource::ChildProcessResource( 82 ChildProcessResource::ChildProcessResource(
74 int process_type, 83 int process_type,
75 const base::string16& name, 84 const base::string16& name,
76 base::ProcessHandle handle, 85 base::ProcessHandle handle,
77 int unique_process_id) 86 int unique_process_id,
87 const scoped_refptr<ProcessResourceUsage>& resource_usage)
78 : process_type_(process_type), 88 : process_type_(process_type),
79 name_(name), 89 name_(name),
80 handle_(handle), 90 handle_(handle),
81 unique_process_id_(unique_process_id), 91 unique_process_id_(unique_process_id),
82 network_usage_support_(false) { 92 network_usage_support_(false),
93 resource_usage_(resource_usage) {
ncarter (slow) 2015/05/01 21:37:58 Can you come up with a TaskManagerBrowserTest for
83 // We cache the process id because it's not cheap to calculate, and it won't 94 // We cache the process id because it's not cheap to calculate, and it won't
84 // be available when we get the plugin disconnected notification. 95 // be available when we get the plugin disconnected notification.
85 pid_ = base::GetProcId(handle); 96 pid_ = base::GetProcId(handle);
86 if (!default_icon_) { 97 if (!default_icon_) {
87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 98 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
88 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); 99 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON);
89 // TODO(jabdelmalek): use different icon for web workers. 100 // TODO(jabdelmalek): use different icon for web workers.
90 } 101 }
91 } 102 }
92 103
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 case content::PROCESS_TYPE_MAX: 204 case content::PROCESS_TYPE_MAX:
194 NOTREACHED(); 205 NOTREACHED();
195 break; 206 break;
196 case content::PROCESS_TYPE_UNKNOWN: 207 case content::PROCESS_TYPE_UNKNOWN:
197 NOTREACHED() << "Need localized name for child process type."; 208 NOTREACHED() << "Need localized name for child process type.";
198 } 209 }
199 210
200 return title; 211 return title;
201 } 212 }
202 213
214 void ChildProcessResource::Refresh() {
215 if (resource_usage_)
216 resource_usage_->Refresh();
217 }
218
219 bool ChildProcessResource::ReportsV8MemoryStats() const {
220 if (resource_usage_)
221 return resource_usage_->ReportsV8MemoryStats();
222 return false;
223 }
224
225 size_t ChildProcessResource::GetV8MemoryAllocated() const {
226 if (resource_usage_)
227 return resource_usage_->GetV8MemoryAllocated();
228 return 0;
229 }
230
231 size_t ChildProcessResource::GetV8MemoryUsed() const {
232 if (resource_usage_)
233 return resource_usage_->GetV8MemoryUsed();
234 return 0;
235 }
236
203 //////////////////////////////////////////////////////////////////////////////// 237 ////////////////////////////////////////////////////////////////////////////////
204 // ChildProcessResourceProvider class 238 // ChildProcessResourceProvider class
205 //////////////////////////////////////////////////////////////////////////////// 239 ////////////////////////////////////////////////////////////////////////////////
206 240
207 ChildProcessResourceProvider:: 241 ChildProcessResourceProvider::
208 ChildProcessResourceProvider(TaskManager* task_manager) 242 ChildProcessResourceProvider(TaskManager* task_manager)
209 : task_manager_(task_manager), 243 : task_manager_(task_manager),
210 updating_(false) { 244 updating_(false) {
211 } 245 }
212 246
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 DCHECK(pid_iter != pid_to_resources_.end()); 322 DCHECK(pid_iter != pid_to_resources_.end());
289 if (pid_iter != pid_to_resources_.end()) 323 if (pid_iter != pid_to_resources_.end())
290 pid_to_resources_.erase(pid_iter); 324 pid_to_resources_.erase(pid_iter);
291 325
292 // Finally, delete the resource. 326 // Finally, delete the resource.
293 delete resource; 327 delete resource;
294 } 328 }
295 329
296 void ChildProcessResourceProvider::AddToTaskManager( 330 void ChildProcessResourceProvider::AddToTaskManager(
297 const content::ChildProcessData& child_process_data) { 331 const content::ChildProcessData& child_process_data) {
298 ChildProcessResource* resource = 332 ChildProcessResource* resource = new ChildProcessResource(
299 new ChildProcessResource( 333 child_process_data.process_type, child_process_data.name,
300 child_process_data.process_type, 334 child_process_data.handle, child_process_data.id,
301 child_process_data.name, 335 child_process_data.process_resource_usage);
302 child_process_data.handle,
303 child_process_data.id);
304 resources_[child_process_data.handle] = resource; 336 resources_[child_process_data.handle] = resource;
305 pid_to_resources_[resource->process_id()] = resource; 337 pid_to_resources_[resource->process_id()] = resource;
306 task_manager_->AddResource(resource); 338 task_manager_->AddResource(resource);
307 } 339 }
308 340
309 // The ChildProcessData::Iterator has to be used from the IO thread. 341 // The ChildProcessData::Iterator has to be used from the IO thread.
310 void ChildProcessResourceProvider::RetrieveChildProcessData() { 342 void ChildProcessResourceProvider::RetrieveChildProcessData() {
311 std::vector<content::ChildProcessData> child_processes; 343 std::vector<content::ChildProcessData> child_processes;
312 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) { 344 for (BrowserChildProcessHostIterator iter; !iter.Done(); ++iter) {
313 // Only add processes which are already started, since we need their handle. 345 // Only add processes which are already started, since we need their handle.
(...skipping 13 matching lines...) Expand all
327 // This is called on the UI thread. 359 // This is called on the UI thread.
328 void ChildProcessResourceProvider::ChildProcessDataRetreived( 360 void ChildProcessResourceProvider::ChildProcessDataRetreived(
329 const std::vector<content::ChildProcessData>& child_processes) { 361 const std::vector<content::ChildProcessData>& child_processes) {
330 for (size_t i = 0; i < child_processes.size(); ++i) 362 for (size_t i = 0; i < child_processes.size(); ++i)
331 AddToTaskManager(child_processes[i]); 363 AddToTaskManager(child_processes[i]);
332 364
333 task_manager_->model()->NotifyDataReady(); 365 task_manager_->model()->NotifyDataReady();
334 } 366 }
335 367
336 } // namespace task_manager 368 } // namespace task_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/utility/BUILD.gn » ('j') | chrome/utility/chrome_content_utility_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698