Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ReactCommon/hermes/inspector/chrome/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Connection::Impl : public inspector::InspectorObserver,
const m::heapProfiler::GetObjectByHeapObjectIdRequest &req) override;
void handle(const m::heapProfiler::GetHeapObjectIdRequest &req) override;
void handle(const m::runtime::EvaluateRequest &req) override;
void handle(const m::runtime::GetHeapUsageRequest &req) override;
void handle(const m::runtime::GetPropertiesRequest &req) override;
void handle(const m::runtime::RunIfWaitingForDebuggerRequest &req) override;

Expand Down Expand Up @@ -1030,6 +1031,23 @@ Connection::Impl::makePropsFromValue(
return result;
}

void Connection::Impl::handle(const m::runtime::GetHeapUsageRequest &req) {
auto resp = std::make_shared<m::runtime::GetHeapUsageResponse>();
resp->id = req.id;

inspector_
->executeIfEnabled(
"Runtime.getHeapUsage",
[this, req, resp](const debugger::ProgramState &state) {
auto heapInfo = getRuntime().instrumentation().getHeapInfo(false);
resp->usedSize = heapInfo["hermes_allocatedBytes"];
resp->totalSize = heapInfo["hermes_heapSize"];
})
.via(executor_.get())
.thenValue([this, resp](auto &&) { sendResponseToClient(*resp); })
.thenError<std::exception>(sendErrorToClient(req.id));
}

void Connection::Impl::handle(const m::runtime::GetPropertiesRequest &req) {
auto resp = std::make_shared<m::runtime::GetPropertiesResponse>();
resp->id = req.id;
Expand Down
53 changes: 52 additions & 1 deletion ReactCommon/hermes/inspector/chrome/MessageTypes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.
// @generated SignedSource<<522f29c54f207a4f7b5c33af07cf64d0>>
// @generated <<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>

#include "MessageTypes.h"

Expand Down Expand Up @@ -61,6 +61,7 @@ std::unique_ptr<Request> Request::fromJsonThrowOnError(const std::string &str) {
{"HeapProfiler.takeHeapSnapshot",
makeUnique<heapProfiler::TakeHeapSnapshotRequest>},
{"Runtime.evaluate", makeUnique<runtime::EvaluateRequest>},
{"Runtime.getHeapUsage", makeUnique<runtime::GetHeapUsageRequest>},
{"Runtime.getProperties", makeUnique<runtime::GetPropertiesRequest>},
{"Runtime.runIfWaitingForDebugger",
makeUnique<runtime::RunIfWaitingForDebuggerRequest>},
Expand Down Expand Up @@ -487,12 +488,19 @@ debugger::ResumeRequest::ResumeRequest(const dynamic &obj)
: Request("Debugger.resume") {
assign(id, obj, "id");
assign(method, obj, "method");

dynamic params = obj.at("params");
assign(terminateOnResume, params, "terminateOnResume");
}

dynamic debugger::ResumeRequest::toDynamic() const {
dynamic params = dynamic::object;
put(params, "terminateOnResume", terminateOnResume);

dynamic obj = dynamic::object;
put(obj, "id", id);
put(obj, "method", method);
put(obj, "params", std::move(params));
return obj;
}

Expand Down Expand Up @@ -881,12 +889,14 @@ heapProfiler::StopTrackingHeapObjectsRequest::StopTrackingHeapObjectsRequest(
dynamic params = obj.at("params");
assign(reportProgress, params, "reportProgress");
assign(treatGlobalObjectsAsRoots, params, "treatGlobalObjectsAsRoots");
assign(captureNumericValue, params, "captureNumericValue");
}

dynamic heapProfiler::StopTrackingHeapObjectsRequest::toDynamic() const {
dynamic params = dynamic::object;
put(params, "reportProgress", reportProgress);
put(params, "treatGlobalObjectsAsRoots", treatGlobalObjectsAsRoots);
put(params, "captureNumericValue", captureNumericValue);

dynamic obj = dynamic::object;
put(obj, "id", id);
Expand All @@ -912,12 +922,14 @@ heapProfiler::TakeHeapSnapshotRequest::TakeHeapSnapshotRequest(
dynamic params = obj.at("params");
assign(reportProgress, params, "reportProgress");
assign(treatGlobalObjectsAsRoots, params, "treatGlobalObjectsAsRoots");
assign(captureNumericValue, params, "captureNumericValue");
}

dynamic heapProfiler::TakeHeapSnapshotRequest::toDynamic() const {
dynamic params = dynamic::object;
put(params, "reportProgress", reportProgress);
put(params, "treatGlobalObjectsAsRoots", treatGlobalObjectsAsRoots);
put(params, "captureNumericValue", captureNumericValue);

dynamic obj = dynamic::object;
put(obj, "id", id);
Expand Down Expand Up @@ -971,6 +983,26 @@ void runtime::EvaluateRequest::accept(RequestHandler &handler) const {
handler.handle(*this);
}

runtime::GetHeapUsageRequest::GetHeapUsageRequest()
: Request("Runtime.getHeapUsage") {}

runtime::GetHeapUsageRequest::GetHeapUsageRequest(const dynamic &obj)
: Request("Runtime.getHeapUsage") {
assign(id, obj, "id");
assign(method, obj, "method");
}

dynamic runtime::GetHeapUsageRequest::toDynamic() const {
dynamic obj = dynamic::object;
put(obj, "id", id);
put(obj, "method", method);
return obj;
}

void runtime::GetHeapUsageRequest::accept(RequestHandler &handler) const {
handler.handle(*this);
}

runtime::GetPropertiesRequest::GetPropertiesRequest()
: Request("Runtime.getProperties") {}

Expand Down Expand Up @@ -1206,6 +1238,25 @@ dynamic runtime::EvaluateResponse::toDynamic() const {
return obj;
}

runtime::GetHeapUsageResponse::GetHeapUsageResponse(const dynamic &obj) {
assign(id, obj, "id");

dynamic res = obj.at("result");
assign(usedSize, res, "usedSize");
assign(totalSize, res, "totalSize");
}

dynamic runtime::GetHeapUsageResponse::toDynamic() const {
dynamic res = dynamic::object;
put(res, "usedSize", usedSize);
put(res, "totalSize", totalSize);

dynamic obj = dynamic::object;
put(obj, "id", id);
put(obj, "result", std::move(res));
return obj;
}

runtime::GetPropertiesResponse::GetPropertiesResponse(const dynamic &obj) {
assign(id, obj, "id");

Expand Down
27 changes: 26 additions & 1 deletion ReactCommon/hermes/inspector/chrome/MessageTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2004-present Facebook. All Rights Reserved.
// @generated SignedSource<<a541d174394c8959b9fb6a7c575e7040>>
// @generated <<SignedSource::*O*zOeWoEQle#+L!plEphiEmie@IsG>>

#pragma once

Expand Down Expand Up @@ -56,6 +56,8 @@ struct ExceptionDetails;
struct ExecutionContextCreatedNotification;
struct ExecutionContextDescription;
using ExecutionContextId = int;
struct GetHeapUsageRequest;
struct GetHeapUsageResponse;
struct GetPropertiesRequest;
struct GetPropertiesResponse;
struct InternalPropertyDescriptor;
Expand Down Expand Up @@ -123,6 +125,7 @@ struct RequestHandler {
const heapProfiler::StopTrackingHeapObjectsRequest &req) = 0;
virtual void handle(const heapProfiler::TakeHeapSnapshotRequest &req) = 0;
virtual void handle(const runtime::EvaluateRequest &req) = 0;
virtual void handle(const runtime::GetHeapUsageRequest &req) = 0;
virtual void handle(const runtime::GetPropertiesRequest &req) = 0;
virtual void handle(const runtime::RunIfWaitingForDebuggerRequest &req) = 0;
};
Expand Down Expand Up @@ -157,6 +160,7 @@ struct NoopRequestHandler : public RequestHandler {
const heapProfiler::StopTrackingHeapObjectsRequest &req) override {}
void handle(const heapProfiler::TakeHeapSnapshotRequest &req) override {}
void handle(const runtime::EvaluateRequest &req) override {}
void handle(const runtime::GetHeapUsageRequest &req) override {}
void handle(const runtime::GetPropertiesRequest &req) override {}
void handle(const runtime::RunIfWaitingForDebuggerRequest &req) override {}
};
Expand Down Expand Up @@ -385,6 +389,8 @@ struct debugger::ResumeRequest : public Request {

folly::dynamic toDynamic() const override;
void accept(RequestHandler &handler) const override;

folly::Optional<bool> terminateOnResume;
};

struct debugger::SetBreakpointRequest : public Request {
Expand Down Expand Up @@ -533,6 +539,7 @@ struct heapProfiler::StopTrackingHeapObjectsRequest : public Request {

folly::Optional<bool> reportProgress;
folly::Optional<bool> treatGlobalObjectsAsRoots;
folly::Optional<bool> captureNumericValue;
};

struct heapProfiler::TakeHeapSnapshotRequest : public Request {
Expand All @@ -544,6 +551,7 @@ struct heapProfiler::TakeHeapSnapshotRequest : public Request {

folly::Optional<bool> reportProgress;
folly::Optional<bool> treatGlobalObjectsAsRoots;
folly::Optional<bool> captureNumericValue;
};

struct runtime::EvaluateRequest : public Request {
Expand All @@ -563,6 +571,14 @@ struct runtime::EvaluateRequest : public Request {
folly::Optional<bool> awaitPromise;
};

struct runtime::GetHeapUsageRequest : public Request {
GetHeapUsageRequest();
explicit GetHeapUsageRequest(const folly::dynamic &obj);

folly::dynamic toDynamic() const override;
void accept(RequestHandler &handler) const override;
};

struct runtime::GetPropertiesRequest : public Request {
GetPropertiesRequest();
explicit GetPropertiesRequest(const folly::dynamic &obj);
Expand Down Expand Up @@ -667,6 +683,15 @@ struct runtime::EvaluateResponse : public Response {
folly::Optional<runtime::ExceptionDetails> exceptionDetails;
};

struct runtime::GetHeapUsageResponse : public Response {
GetHeapUsageResponse() = default;
explicit GetHeapUsageResponse(const folly::dynamic &obj);
folly::dynamic toDynamic() const override;

double usedSize{};
double totalSize{};
};

struct runtime::GetPropertiesResponse : public Response {
GetPropertiesResponse() = default;
explicit GetPropertiesResponse(const folly::dynamic &obj);
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/hermes/inspector/tools/message_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ HeapProfiler.getHeapObjectId
Runtime.consoleAPICalled
Runtime.evaluate
Runtime.executionContextCreated
Runtime.getHeapUsage
Runtime.getProperties
Runtime.runIfWaitingForDebugger
2 changes: 1 addition & 1 deletion ReactCommon/hermes/inspector/tools/msggen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "jest"
},
"dependencies": {
"devtools-protocol": "0.0.730699",
"devtools-protocol": "0.0.959523",
"yargs": "^14.2.0"
},
"devDependencies": {
Expand Down
17 changes: 15 additions & 2 deletions ReactCommon/hermes/inspector/tools/msggen/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const proto = mergeDomains(standard, custom);
function parseDomains(
domainObjs: Array<any>,
ignoreExperimental: boolean,
includeExperimental: Set<string>,
): Descriptor {
const desc = {
types: [],
Expand All @@ -59,7 +60,12 @@ function parseDomains(
}

for (const commandObj of obj.commands || []) {
const command = Command.create(domain, commandObj, ignoreExperimental);
const command = Command.create(
domain,
commandObj,
!includeExperimental.has(`${domain}.${commandObj.name}`) &&
ignoreExperimental,
);
if (command) {
desc.commands.push(command);
}
Expand Down Expand Up @@ -199,18 +205,25 @@ function main() {
.boolean('e')
.alias('e', 'ignore-experimental')
.describe('e', 'ignore experimental commands, props, and types')
.alias('i', 'include-experimental')
.describe('experiment commands to include')
.alias('r', 'roots')
.describe('r', 'path to a file listing root types, events, and commands')
.nargs('r', 1)
.demandCommand(2, 2).argv;

const ignoreExperimental = !!args.e;
const includeExperimental = new Set(args.i != null ? args.i.split(',') : []);
const [headerPath, implPath] = args._;

const headerStream = fs.createWriteStream(headerPath);
const implStream = fs.createWriteStream(implPath);

const desc = parseDomains(proto.domains, ignoreExperimental);
const desc = parseDomains(
proto.domains,
ignoreExperimental,
includeExperimental,
);
const graph = buildGraph(desc);
const roots = parseRoots(desc, String(args.roots));

Expand Down
8 changes: 4 additions & 4 deletions ReactCommon/hermes/inspector/tools/msggen/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2434,10 +2434,10 @@ detect-newline@^3.0.0:
resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651"
integrity sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==

devtools-protocol@0.0.730699:
version "0.0.730699"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.730699.tgz#4d18f6a9b7fb7cf3f1ffe73bfe14aad66cf3b2ef"
integrity sha512-dprBpuPzVIIXXL6GevzhvWe2wg836h3d5hY+n6IzzHbKLsUh6QlVmcIy15za0J3MhDFbmEH60s6uYsrw/tgBbw==
devtools-protocol@0.0.959523:
version "0.0.959523"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.959523.tgz#a7ce62c6b88876081fe5bec866f70e467bc021ba"
integrity sha512-taOcAND/oJA5FhJD2I3RA+I8RPdrpPJWwvMBPzTq7Sugev1xTOG3lgtlSfkh5xkjTYw0Ti2CRQq016goFHMoPQ==

diff-sequences@^26.6.2:
version "26.6.2"
Expand Down
11 changes: 6 additions & 5 deletions ReactCommon/hermes/inspector/tools/run_msggen
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

set -e

DIR=$(dirname "${BASH_SOURCE[0]}")
DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
cd "${DIR}/msggen"

yarn install
yarn build

FBSOURCE=$(hg root)
MSGTYPES_PATH="${FBSOURCE}/xplat/js/react-native-github/ReactCommon/hermes/inspector/tools/message_types.txt"
HEADER_PATH="${FBSOURCE}/xplat/js/react-native-github/ReactCommon/hermes/inspector/chrome/MessageTypes.h"
CPP_PATH="${FBSOURCE}/xplat/js/react-native-github/ReactCommon/hermes/inspector/chrome/MessageTypes.cpp"
MSGTYPES_PATH="${DIR}/message_types.txt"
HEADER_PATH="${DIR}/../chrome/MessageTypes.h"
CPP_PATH="${DIR}/../chrome/MessageTypes.cpp"

node bin/index.js \
--ignore-experimental \
--include-experimental=Runtime.getHeapUsage \
--roots "$MSGTYPES_PATH" \
"$HEADER_PATH" "$CPP_PATH"

clang-format -i --style=file "$HEADER_PATH"
clang-format -i --style=file "$CPP_PATH"

FBSOURCE=$(hg root)
"${FBSOURCE}/tools/signedsource" sign "$HEADER_PATH"
"${FBSOURCE}/tools/signedsource" sign "$CPP_PATH"