Commit 767b8edd authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[inspector] Add Runtime.getIsolateId & Runtime.getHeapUsage commands

BUG=chromium:823874

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I1df9347ead62dc84150f5549c29815600609c55b
Reviewed-on: https://chromium-review.googlesource.com/972181
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52085}
parent 5724b958
......@@ -2593,6 +2593,35 @@
}
]
},
{
"name": "getIsolateId",
"description": "Returns the isolate id.",
"experimental": true,
"returns": [
{
"name": "id",
"description": "The isolate id.",
"type": "string"
}
]
},
{
"name": "getHeapUsage",
"description": "Returns the JavaScript heap usage.\nIt is the total usage of the corresponding isolate not scoped to a particular Runtime.",
"experimental": true,
"returns": [
{
"name": "usedSize",
"description": "Used heap size in bytes.",
"type": "number"
},
{
"name": "totalSize",
"description": "Allocated heap size in bytes.",
"type": "number"
}
]
},
{
"name": "getProperties",
"description": "Returns properties of a given object. Object group of the result is inherited from the target\nobject.",
......
......@@ -1195,6 +1195,21 @@ domain Runtime
# Exception details.
optional ExceptionDetails exceptionDetails
# Returns the isolate id.
experimental command getIsolateId
returns
# The isolate id.
string id
# Returns the JavaScript heap usage.
# It is the total usage of the corresponding isolate not scoped to a particular Runtime.
experimental command getHeapUsage
returns
# Used heap size in bytes.
number usedSize
# Allocated heap size in bytes.
number totalSize
# Returns properties of a given object. Object group of the result is inherited from the target
# object.
command getProperties
......
......@@ -30,6 +30,7 @@
#include "src/inspector/v8-runtime-agent-impl.h"
#include "src/base/platform/platform.h"
#include "src/debug/debug-interface.h"
#include "src/inspector/injected-script.h"
#include "src/inspector/inspected-context.h"
......@@ -609,6 +610,23 @@ Response V8RuntimeAgentImpl::globalLexicalScopeNames(
return Response::OK();
}
Response V8RuntimeAgentImpl::getIsolateId(String16* outIsolateId) {
char buf[40];
std::snprintf(buf, sizeof(buf), "%d.%p", v8::base::OS::GetCurrentProcessId(),
m_inspector->isolate());
*outIsolateId = buf;
return Response::OK();
}
Response V8RuntimeAgentImpl::getHeapUsage(double* out_usedSize,
double* out_totalSize) {
v8::HeapStatistics stats;
m_inspector->isolate()->GetHeapStatistics(&stats);
*out_usedSize = stats.used_heap_size();
*out_totalSize = stats.total_heap_size();
return Response::OK();
}
void V8RuntimeAgentImpl::terminateExecution(
std::unique_ptr<TerminateExecutionCallback> callback) {
m_inspector->debugger()->terminateExecution(std::move(callback));
......
......@@ -104,6 +104,8 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
Response globalLexicalScopeNames(
Maybe<int> executionContextId,
std::unique_ptr<protocol::Array<String16>>* outNames) override;
Response getIsolateId(String16* outIsolateId) override;
Response getHeapUsage(double* out_usedSize, double* out_totalSize) override;
void terminateExecution(
std::unique_ptr<TerminateExecutionCallback> callback) override;
......
Checks that Runtime.getHeapUsage works
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const {session, contextGroup, Protocol} = InspectorTest.start('Checks that Runtime.getHeapUsage works');
(async function test() {
const heapUsage = await Protocol.Runtime.getHeapUsage();
const usedSize = heapUsage.result["usedSize"];
const totalSize = heapUsage.result["totalSize"];
console.assert(usedSize > 0);
console.assert(totalSize > 0);
console.assert(totalSize >= usedSize);
InspectorTest.completeTest();
})();
Checks that Runtime.getIsolateId works
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const {session, contextGroup, Protocol} = InspectorTest.start('Checks that Runtime.getIsolateId works');
(async function test() {
const id = await Protocol.Runtime.getIsolateId();
console.assert(typeof id === 'string');
console.assert(id.length > 0);
InspectorTest.completeTest();
})();
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