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

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: Redesign. Created 5 years, 7 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 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/memory/weak_ptr.h"
10 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
11 #include "chrome/browser/task_manager/resource_provider.h" 12 #include "chrome/browser/task_manager/resource_provider.h"
12 #include "chrome/browser/task_manager/task_manager.h" 13 #include "chrome/browser/task_manager/task_manager.h"
13 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
14 #include "components/nacl/common/nacl_process_type.h" 15 #include "components/nacl/common/nacl_process_type.h"
16 #include "content/public/browser/browser_child_process_host.h"
15 #include "content/public/browser/browser_child_process_host_iterator.h" 17 #include "content/public/browser/browser_child_process_host_iterator.h"
16 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/child_process_data.h" 19 #include "content/public/browser/child_process_data.h"
20 #include "content/public/browser/process_resource_usage.h"
21 #include "content/public/common/service_registry.h"
18 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
22 26
23 using content::BrowserChildProcessHostIterator; 27 using content::BrowserChildProcessHostIterator;
24 using content::BrowserThread; 28 using content::BrowserThread;
29 using content::ProcessResourceUsage;
25 using content::WebContents; 30 using content::WebContents;
26 31
27 namespace task_manager { 32 namespace task_manager {
28 33
29 class ChildProcessResource : public Resource { 34 class ChildProcessResource : public Resource {
30 public: 35 public:
31 ChildProcessResource(int process_type, 36 ChildProcessResource(int process_type,
32 const base::string16& name, 37 const base::string16& name,
33 base::ProcessHandle handle, 38 base::ProcessHandle handle,
34 int unique_process_id); 39 int unique_process_id);
35 ~ChildProcessResource() override; 40 ~ChildProcessResource() override;
36 41
37 // Resource methods: 42 // Resource methods:
38 base::string16 GetTitle() const override; 43 base::string16 GetTitle() const override;
39 base::string16 GetProfileName() const override; 44 base::string16 GetProfileName() const override;
40 gfx::ImageSkia GetIcon() const override; 45 gfx::ImageSkia GetIcon() const override;
41 base::ProcessHandle GetProcess() const override; 46 base::ProcessHandle GetProcess() const override;
42 int GetUniqueChildProcessId() const override; 47 int GetUniqueChildProcessId() const override;
43 Type GetType() const override; 48 Type GetType() const override;
44 bool SupportNetworkUsage() const override; 49 bool SupportNetworkUsage() const override;
45 void SetSupportNetworkUsage() override; 50 void SetSupportNetworkUsage() override;
51 void Refresh() override;
52 bool ReportsV8MemoryStats() const override;
53 size_t GetV8MemoryAllocated() const override;
54 size_t GetV8MemoryUsed() const override;
46 55
47 // Returns the pid of the child process. 56 // Returns the pid of the child process.
48 int process_id() const { return pid_; } 57 int process_id() const { return pid_; }
49 58
50 private: 59 private:
51 // Returns a localized title for the child process. For example, a plugin 60 // Returns a localized title for the child process. For example, a plugin
52 // process would be "Plugin: Flash" when name is "Flash". 61 // process would be "Plugin: Flash" when name is "Flash".
53 base::string16 GetLocalizedTitle() const; 62 base::string16 GetLocalizedTitle() const;
54 63
64 static void GetProcessUsageOnIOThread(
65 int id, base::WeakPtr<ChildProcessResource> weak_ptr);
66
67 void OnGetProcessUsageDone(
68 mojo::InterfacePtrInfo<content::ResourceUsageReporter> info);
69
55 int process_type_; 70 int process_type_;
56 base::string16 name_; 71 base::string16 name_;
57 base::ProcessHandle handle_; 72 base::ProcessHandle handle_;
58 int pid_; 73 int pid_;
59 int unique_process_id_; 74 int unique_process_id_;
60 mutable base::string16 title_; 75 mutable base::string16 title_;
61 bool network_usage_support_; 76 bool network_usage_support_;
77 scoped_ptr<ProcessResourceUsage> resource_usage_;
62 78
63 // The icon painted for the child processs. 79 // The icon painted for the child processs.
64 // TODO(jcampan): we should have plugin specific icons for well-known 80 // TODO(jcampan): we should have plugin specific icons for well-known
65 // plugins. 81 // plugins.
66 static gfx::ImageSkia* default_icon_; 82 static gfx::ImageSkia* default_icon_;
67 83
84 base::WeakPtrFactory<ChildProcessResource> weak_factory_;
85
68 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource); 86 DISALLOW_COPY_AND_ASSIGN(ChildProcessResource);
69 }; 87 };
70 88
71 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL; 89 gfx::ImageSkia* ChildProcessResource::default_icon_ = NULL;
72 90
91 // static
92 void ChildProcessResource::GetProcessUsageOnIOThread(
afakhry 2015/05/06 17:16:27 What do you think of moving the functionality of:
ncarter (slow) 2015/05/07 20:12:44 GetProcessUsageInfo probably can move into Process
Anand Mistry (off Chromium) 2015/05/11 05:41:31 Apart from PostTaskAndReplyWithResult, I'm going t
ncarter (slow) 2015/05/11 20:35:39 I'm fine with the compromise you've struck. My ini
93 int id, base::WeakPtr<ChildProcessResource> weak_ptr) {
94 DCHECK_CURRENTLY_ON(BrowserThread::IO);
95 content::BrowserChildProcessHost* host =
96 content::BrowserChildProcessHost::Get(id);
97 if (!host)
98 return;
99
100 content::ServiceRegistry* registry = host->GetServiceRegistry();
101 if (!registry)
102 return;
103
104 content::ResourceUsageReporterPtr service;
105 registry->ConnectToRemoteService(&service);
106 auto interface_info = service.PassInterface();
107 BrowserThread::PostTask(
108 BrowserThread::UI, FROM_HERE,
109 base::Bind(
110 &ChildProcessResource::OnGetProcessUsageDone,
111 weak_ptr, base::Passed(&interface_info)));
112 }
113
73 ChildProcessResource::ChildProcessResource( 114 ChildProcessResource::ChildProcessResource(
74 int process_type, 115 int process_type,
75 const base::string16& name, 116 const base::string16& name,
76 base::ProcessHandle handle, 117 base::ProcessHandle handle,
77 int unique_process_id) 118 int unique_process_id)
78 : process_type_(process_type), 119 : process_type_(process_type),
79 name_(name), 120 name_(name),
80 handle_(handle), 121 handle_(handle),
81 unique_process_id_(unique_process_id), 122 unique_process_id_(unique_process_id),
82 network_usage_support_(false) { 123 network_usage_support_(false),
124 weak_factory_(this) {
83 // We cache the process id because it's not cheap to calculate, and it won't 125 // 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. 126 // be available when we get the plugin disconnected notification.
85 pid_ = base::GetProcId(handle); 127 pid_ = base::GetProcId(handle);
86 if (!default_icon_) { 128 if (!default_icon_) {
87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 129 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
88 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON); 130 default_icon_ = rb.GetImageSkiaNamed(IDR_PLUGINS_FAVICON);
89 // TODO(jabdelmalek): use different icon for web workers. 131 // TODO(jabdelmalek): use different icon for web workers.
90 } 132 }
133 BrowserThread::PostTask(
ncarter (slow) 2015/05/07 20:12:43 It might work well to structure this as a PostTask
Anand Mistry (off Chromium) 2015/05/11 05:41:31 Done. Aside: Many of Mojo's types are move-only,
ncarter (slow) 2015/05/11 20:35:40 Great to know, thanks!
134 BrowserThread::IO, FROM_HERE,
135 base::Bind(
136 &ChildProcessResource::GetProcessUsageOnIOThread,
137 unique_process_id, weak_factory_.GetWeakPtr()));
91 } 138 }
92 139
93 ChildProcessResource::~ChildProcessResource() { 140 ChildProcessResource::~ChildProcessResource() {
94 } 141 }
95 142
143 void ChildProcessResource::OnGetProcessUsageDone(
144 mojo::InterfacePtrInfo<content::ResourceUsageReporter> info) {
ncarter (slow) 2015/05/07 20:12:43 Just curious -- do we expect that this approach wi
Anand Mistry (off Chromium) 2015/05/11 05:41:31 Yes. I see no reason why this wouldn't work. Creat
ncarter (slow) 2015/05/11 20:35:40 Excellent.
145 DCHECK_CURRENTLY_ON(BrowserThread::UI);
146 if (info.is_valid()) {
147 content::ResourceUsageReporterPtr service;
148 service.Bind(info.Pass());
149 resource_usage_ = content::ProcessResourceUsage::Create(service.Pass());
150 }
151 }
152
96 // Resource methods: 153 // Resource methods:
97 base::string16 ChildProcessResource::GetTitle() const { 154 base::string16 ChildProcessResource::GetTitle() const {
98 if (title_.empty()) 155 if (title_.empty())
99 title_ = GetLocalizedTitle(); 156 title_ = GetLocalizedTitle();
100 157
101 return title_; 158 return title_;
102 } 159 }
103 160
104 base::string16 ChildProcessResource::GetProfileName() const { 161 base::string16 ChildProcessResource::GetProfileName() const {
105 return base::string16(); 162 return base::string16();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 case content::PROCESS_TYPE_MAX: 250 case content::PROCESS_TYPE_MAX:
194 NOTREACHED(); 251 NOTREACHED();
195 break; 252 break;
196 case content::PROCESS_TYPE_UNKNOWN: 253 case content::PROCESS_TYPE_UNKNOWN:
197 NOTREACHED() << "Need localized name for child process type."; 254 NOTREACHED() << "Need localized name for child process type.";
198 } 255 }
199 256
200 return title; 257 return title;
201 } 258 }
202 259
260 void ChildProcessResource::Refresh() {
261 if (resource_usage_)
262 resource_usage_->Refresh();
afakhry 2015/05/06 17:16:27 Is it possible if you add a callback of type: void
ncarter (slow) 2015/05/07 20:12:43 amistry has addressed this to my satisfaction in a
263 }
264
265 bool ChildProcessResource::ReportsV8MemoryStats() const {
266 if (resource_usage_)
ncarter (slow) 2015/05/07 20:12:43 It's not clear if a |resource_usage_| will be succ
Anand Mistry (off Chromium) 2015/05/11 05:41:31 If the process host has a ServiceRegistry, then ye
ncarter (slow) 2015/05/11 20:35:40 Acknowledged.
267 return resource_usage_->ReportsV8MemoryStats();
268 return false;
269 }
270
271 size_t ChildProcessResource::GetV8MemoryAllocated() const {
272 if (resource_usage_)
273 return resource_usage_->GetV8MemoryAllocated();
274 return 0;
275 }
276
277 size_t ChildProcessResource::GetV8MemoryUsed() const {
278 if (resource_usage_)
279 return resource_usage_->GetV8MemoryUsed();
280 return 0;
281 }
282
203 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
204 // ChildProcessResourceProvider class 284 // ChildProcessResourceProvider class
205 //////////////////////////////////////////////////////////////////////////////// 285 ////////////////////////////////////////////////////////////////////////////////
206 286
207 ChildProcessResourceProvider:: 287 ChildProcessResourceProvider::
208 ChildProcessResourceProvider(TaskManager* task_manager) 288 ChildProcessResourceProvider(TaskManager* task_manager)
209 : task_manager_(task_manager), 289 : task_manager_(task_manager),
210 updating_(false) { 290 updating_(false) {
211 } 291 }
212 292
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // This is called on the UI thread. 407 // This is called on the UI thread.
328 void ChildProcessResourceProvider::ChildProcessDataRetreived( 408 void ChildProcessResourceProvider::ChildProcessDataRetreived(
329 const std::vector<content::ChildProcessData>& child_processes) { 409 const std::vector<content::ChildProcessData>& child_processes) {
330 for (size_t i = 0; i < child_processes.size(); ++i) 410 for (size_t i = 0; i < child_processes.size(); ++i)
331 AddToTaskManager(child_processes[i]); 411 AddToTaskManager(child_processes[i]);
332 412
333 task_manager_->model()->NotifyDataReady(); 413 task_manager_->model()->NotifyDataReady();
334 } 414 }
335 415
336 } // namespace task_manager 416 } // namespace task_manager
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_utility.gypi » ('j') | content/public/browser/browser_child_process_host.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698