Commit f5ee8af9 authored by Peter Kvitek's avatar Peter Kvitek Committed by Commit Bot

Introduced SystemInfo.getProcessInfo API.

Process handle and cumulative CPU usage is returned for browser and all
renderer processes.

BUG: 899823

Change-Id: I6d44630df3ea9ef80bed17f30367dad929ecaa17
Reviewed-on: https://chromium-review.googlesource.com/c/1303074
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarAlexei Filippov <alph@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604001}
parent 7275f3a6
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "content/browser/devtools/protocol/system_info_handler.h" #include "content/browser/devtools/protocol/system_info_handler.h"
#include <stdint.h> #include <stdint.h>
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
...@@ -16,7 +15,9 @@ ...@@ -16,7 +15,9 @@
#include "content/browser/gpu/compositor_util.h" #include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_process_host.h" #include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/browser_child_process_host.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/render_process_host.h"
#include "gpu/config/gpu_feature_type.h" #include "gpu/config/gpu_feature_type.h"
#include "gpu/config/gpu_info.h" #include "gpu/config/gpu_info.h"
#include "gpu/config/gpu_switches.h" #include "gpu/config/gpu_switches.h"
...@@ -232,5 +233,65 @@ void SystemInfoHandler::GetInfo(std::unique_ptr<GetInfoCallback> callback) { ...@@ -232,5 +233,65 @@ void SystemInfoHandler::GetInfo(std::unique_ptr<GetInfoCallback> callback) {
new SystemInfoHandlerGpuObserver(std::move(callback)); new SystemInfoHandlerGpuObserver(std::move(callback));
} }
namespace {
std::unique_ptr<base::ProcessMetrics> CreateProcessMetrics(
base::ProcessHandle handle) {
#if defined(OS_MACOSX)
return base::ProcessMetrics::CreateProcessMetrics(
handle, content::BrowserChildProcessHost::GetPortProvider());
#else
return base::ProcessMetrics::CreateProcessMetrics(handle);
#endif
}
std::unique_ptr<protocol::SystemInfo::ProcessInfo> MakeProcessInfo(
const base::Process& process,
const String& process_type) {
std::unique_ptr<base::ProcessMetrics> pm =
CreateProcessMetrics(process.Handle());
base::TimeDelta cpu_usage = pm->GetCumulativeCPUUsage();
return SystemInfo::ProcessInfo::Create()
.SetId(process.Pid())
.SetType(process_type)
.SetCpuTime(cpu_usage.InSecondsF())
.Build();
}
void AddBrowserProcessInfo(
protocol::Array<protocol::SystemInfo::ProcessInfo>* process_info) {
process_info->addItem(
MakeProcessInfo(base::Process::Current(),
protocol::SystemInfo::ProcessTypeEnum::Browser));
}
void AddRendererProcessInfo(
protocol::Array<protocol::SystemInfo::ProcessInfo>* process_info) {
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
RenderProcessHost* host = it.GetCurrentValue();
if (host->GetProcess().IsValid()) {
process_info->addItem(MakeProcessInfo(
host->GetProcess(), protocol::SystemInfo::ProcessTypeEnum::Renderer));
}
}
}
} // namespace
Response SystemInfoHandler::GetProcessInfo(
std::unique_ptr<protocol::Array<protocol::SystemInfo::ProcessInfo>>*
process_info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
*process_info = protocol::Array<SystemInfo::ProcessInfo>::create();
AddBrowserProcessInfo(process_info->get());
AddRendererProcessInfo(process_info->get());
return Response::OK();
}
} // namespace protocol } // namespace protocol
} // namespace content } // namespace content
...@@ -26,6 +26,9 @@ class SystemInfoHandler : public DevToolsDomainHandler, ...@@ -26,6 +26,9 @@ class SystemInfoHandler : public DevToolsDomainHandler,
void Wire(UberDispatcher* dispatcher) override; void Wire(UberDispatcher* dispatcher) override;
void GetInfo(std::unique_ptr<GetInfoCallback> callback) override; void GetInfo(std::unique_ptr<GetInfoCallback> callback) override;
Response GetProcessInfo(
std::unique_ptr<protocol::Array<protocol::SystemInfo::ProcessInfo>>*
process_info) override;
private: private:
friend class SystemInfoHandlerGpuObserver; friend class SystemInfoHandlerGpuObserver;
......
...@@ -33,7 +33,9 @@ constexpr size_t kLayoutTestMaxMessageChunkSize = ...@@ -33,7 +33,9 @@ constexpr size_t kLayoutTestMaxMessageChunkSize =
DevToolsProtocolTestBindings::DevToolsProtocolTestBindings( DevToolsProtocolTestBindings::DevToolsProtocolTestBindings(
WebContents* devtools) WebContents* devtools)
: WebContentsObserver(devtools), : WebContentsObserver(devtools),
agent_host_(DevToolsAgentHost::CreateForDiscovery()) { agent_host_(DevToolsAgentHost::CreateForBrowser(
nullptr,
DevToolsAgentHost::CreateServerSocketCallback())) {
agent_host_->AttachClient(this); agent_host_->AttachClient(this);
} }
......
Tests ProcessInfo retrieval
Process:{
cpuTime : <number>
id : <number>
type : browser
}
Process:{
cpuTime : <number>
id : <number>
type : renderer
}
(async function(testRunner) {
var {page, session, dp} = await testRunner
.startBlank('Tests ProcessInfo retrieval');
response = await testRunner.browserP().SystemInfo.getProcessInfo();
// The number of renderer processes varies, so log only the very first one.
seenRenderer = false;
for (process of response.result.processInfo) {
if (process.type === "renderer") {
if (!seenRenderer) {
seenRenderer = true;
} else {
continue;
}
}
testRunner.log(process, 'Process:', ['id', 'cpuTime']);
}
testRunner.completeTest();
})
...@@ -5901,6 +5901,23 @@ experimental domain SystemInfo ...@@ -5901,6 +5901,23 @@ experimental domain SystemInfo
# An optional array of GPU driver bug workarounds. # An optional array of GPU driver bug workarounds.
array of string driverBugWorkarounds array of string driverBugWorkarounds
# Specifies process type.
type ProcessType extends string
enum
browser
renderer
# Represents process info.
type ProcessInfo extends object
properties
# Specifies process type.
ProcessType type
# Specifies process id.
integer id
# Specifies cumulative CPU usage in seconds across all threads of the
# process since the process start.
number cpuTime
# Returns information about the system. # Returns information about the system.
command getInfo command getInfo
returns returns
...@@ -5916,6 +5933,12 @@ experimental domain SystemInfo ...@@ -5916,6 +5933,12 @@ experimental domain SystemInfo
# supported. # supported.
string commandLine string commandLine
# Returns information about all running processes.
command getProcessInfo
returns
# An array of process info blocks.
array of ProcessInfo processInfo
# Supports additional targets discovery and allows to attach to them. # Supports additional targets discovery and allows to attach to them.
domain Target domain Target
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment