mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
!1010 CDP协议heapprofiler接口实现
Merge pull request !1010 from wwx1083752/master
This commit is contained in:
commit
9892e07bee
@ -26,12 +26,18 @@ namespace panda::ecmascript::tooling {
|
||||
HeapProfilerImpl::DispatcherImpl::DispatcherImpl(FrontEnd *frontend, std::unique_ptr<HeapProfilerImpl> heapprofiler)
|
||||
: DispatcherBase(frontend), heapprofiler_(std::move(heapprofiler))
|
||||
{
|
||||
dispatcherTable_["addInspectedHeapObject"] = &HeapProfilerImpl::DispatcherImpl::AddInspectedHeapObject;
|
||||
dispatcherTable_["collectGarbage"] = &HeapProfilerImpl::DispatcherImpl::CollectGarbage;
|
||||
dispatcherTable_["enable"] = &HeapProfilerImpl::DispatcherImpl::Enable;
|
||||
dispatcherTable_["disable"] = &HeapProfilerImpl::DispatcherImpl::Disable;
|
||||
dispatcherTable_["getHeapObjectId"] = &HeapProfilerImpl::DispatcherImpl::GetHeapObjectId;
|
||||
dispatcherTable_["getObjectByHeapObjectId"] = &HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId;
|
||||
dispatcherTable_["getSamplingProfile"] = &HeapProfilerImpl::DispatcherImpl::GetSamplingProfile;
|
||||
dispatcherTable_["startSampling"] = &HeapProfilerImpl::DispatcherImpl::StartSampling;
|
||||
dispatcherTable_["startTrackingHeapObjects"] = &HeapProfilerImpl::DispatcherImpl::StartTrackingHeapObjects;
|
||||
dispatcherTable_["stopSampling"] = &HeapProfilerImpl::DispatcherImpl::StopSampling;
|
||||
dispatcherTable_["stopTrackingHeapObjects"] = &HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects;
|
||||
dispatcherTable_["takeHeapSnapshot"] = &HeapProfilerImpl::DispatcherImpl::TakeHeapSnapshot;
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request)
|
||||
@ -46,6 +52,25 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request)
|
||||
}
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::AddInspectedHeapObject(const DispatchRequest &request)
|
||||
{
|
||||
std::unique_ptr<AddInspectedHeapObjectParams> params =
|
||||
AddInspectedHeapObjectParams::Create(request.GetEcmaVM(), request.GetParams());
|
||||
if (params == nullptr) {
|
||||
SendResponse(request, DispatchResponse::Fail("HeapProfiler got wrong params"), nullptr);
|
||||
return;
|
||||
}
|
||||
DispatchResponse response = heapprofiler_->AddInspectedHeapObject(std::move(params));
|
||||
std::unique_ptr<PtBaseReturns> result = std::make_unique<PtBaseReturns>();
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::CollectGarbage(const DispatchRequest &request)
|
||||
{
|
||||
DispatchResponse response = heapprofiler_->CollectGarbage();
|
||||
SendResponse(request, response, nullptr);
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::Enable(const DispatchRequest &request)
|
||||
{
|
||||
DispatchResponse response = heapprofiler_->Enable();
|
||||
@ -58,6 +83,45 @@ void HeapProfilerImpl::DispatcherImpl::Disable(const DispatchRequest &request)
|
||||
SendResponse(request, response, nullptr);
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::GetHeapObjectId(const DispatchRequest &request)
|
||||
{
|
||||
std::unique_ptr<GetHeapObjectIdParams> params =
|
||||
GetHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParams());
|
||||
if (params == nullptr) {
|
||||
SendResponse(request, DispatchResponse::Fail("HeapProfiler got wrong params"), nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
HeapSnapshotObjectId objectId;
|
||||
DispatchResponse response = heapprofiler_->GetHeapObjectId(std::move(params), &objectId);
|
||||
std::unique_ptr<GetHeapObjectIdReturns> result = std::make_unique<GetHeapObjectIdReturns>(std::move(objectId));
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId(const DispatchRequest &request)
|
||||
{
|
||||
std::unique_ptr<GetObjectByHeapObjectIdParams> params =
|
||||
GetObjectByHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParams());
|
||||
if (params == nullptr) {
|
||||
SendResponse(request, DispatchResponse::Fail("HeapProfiler got wrong params"), nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<RemoteObject> remoteObjectResult;
|
||||
DispatchResponse response = heapprofiler_->GetObjectByHeapObjectId(std::move(params), &remoteObjectResult);
|
||||
std::unique_ptr<GetObjectByHeapObjectIdReturns> result =
|
||||
std::make_unique<GetObjectByHeapObjectIdReturns>(std::move(remoteObjectResult));
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::GetSamplingProfile(const DispatchRequest &request)
|
||||
{
|
||||
std::unique_ptr<SamplingHeapProfile> profile;
|
||||
DispatchResponse response = heapprofiler_->GetSamplingProfile(&profile);
|
||||
// The return value type of GetSamplingProfile is the same as of StopSampling.
|
||||
std::unique_ptr<StopSamplingReturns> result = std::make_unique<StopSamplingReturns>(std::move(profile));
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
void HeapProfilerImpl::DispatcherImpl::StartSampling(const DispatchRequest &request)
|
||||
{
|
||||
@ -107,19 +171,70 @@ void HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects(const DispatchReq
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::Enable()
|
||||
void HeapProfilerImpl::DispatcherImpl::TakeHeapSnapshot(const DispatchRequest &request)
|
||||
{
|
||||
std::unique_ptr<StopTrackingHeapObjectsParams> params =
|
||||
StopTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParams());
|
||||
if (params == nullptr) {
|
||||
SendResponse(request, DispatchResponse::Fail("HeapProfiler got wrong params"), nullptr);
|
||||
return;
|
||||
}
|
||||
DispatchResponse response = heapprofiler_->TakeHeapSnapshot(std::move(params));
|
||||
std::unique_ptr<PtBaseReturns> result = std::make_unique<PtBaseReturns>();
|
||||
SendResponse(request, response, std::move(result));
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::AddInspectedHeapObject(
|
||||
[[maybe_unused]] std::unique_ptr<AddInspectedHeapObjectParams> params)
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "AddInspectedHeapObject not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::CollectGarbage()
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "CollectGarbage not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::Enable()
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "Enable not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::Disable()
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "Disable not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::GetHeapObjectId([[maybe_unused]] std::unique_ptr<GetHeapObjectIdParams> params,
|
||||
HeapSnapshotObjectId *objectId)
|
||||
{
|
||||
ASSERT(objectId != nullptr);
|
||||
*objectId = 0;
|
||||
LOG(ERROR, DEBUGGER) << "GetHeapObjectId not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::GetObjectByHeapObjectId(
|
||||
[[maybe_unused]] std::unique_ptr<GetObjectByHeapObjectIdParams> params,
|
||||
[[maybe_unused]] std::unique_ptr<RemoteObject> *remoteObjectResult)
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectId not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::GetSamplingProfile([[maybe_unused]]std::unique_ptr<SamplingHeapProfile> *profile)
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "GetSamplingProfile not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::StartSampling([[maybe_unused]]std::unique_ptr<StartSamplingParams> params)
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "StartSampling not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
@ -132,6 +247,7 @@ DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects(
|
||||
|
||||
DispatchResponse HeapProfilerImpl::StopSampling([[maybe_unused]]std::unique_ptr<SamplingHeapProfile> *profile)
|
||||
{
|
||||
LOG(ERROR, DEBUGGER) << "StopSampling not support now."
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
@ -140,4 +256,10 @@ DispatchResponse HeapProfilerImpl::StopTrackingHeapObjects(
|
||||
{
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
|
||||
DispatchResponse HeapProfilerImpl::TakeHeapSnapshot(
|
||||
[[maybe_unused]] std::unique_ptr<StopTrackingHeapObjectsParams> params)
|
||||
{
|
||||
return DispatchResponse::Ok();
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling
|
||||
|
@ -27,24 +27,38 @@ public:
|
||||
explicit HeapProfilerImpl(std::unique_ptr<JSBackend> backend) : backend_(std::move(backend)) {}
|
||||
~HeapProfilerImpl() = default;
|
||||
|
||||
DispatchResponse AddInspectedHeapObject(std::unique_ptr<AddInspectedHeapObjectParams> params);
|
||||
DispatchResponse CollectGarbage();
|
||||
DispatchResponse Enable();
|
||||
DispatchResponse Disable();
|
||||
DispatchResponse GetHeapObjectId(std::unique_ptr<GetHeapObjectIdParams> params, HeapSnapshotObjectId *objectId);
|
||||
DispatchResponse GetObjectByHeapObjectId(std::unique_ptr<GetObjectByHeapObjectIdParams> params,
|
||||
std::unique_ptr<RemoteObject> *remoteObjectResult);
|
||||
DispatchResponse GetSamplingProfile(std::unique_ptr<SamplingHeapProfile> *profile);
|
||||
DispatchResponse StartSampling(std::unique_ptr<StartSamplingParams> params);
|
||||
DispatchResponse StartTrackingHeapObjects(std::unique_ptr<StartTrackingHeapObjectsParams> params);
|
||||
DispatchResponse StopSampling(std::unique_ptr<SamplingHeapProfile> *profile);
|
||||
DispatchResponse StopTrackingHeapObjects (std::unique_ptr<StopTrackingHeapObjectsParams> params);
|
||||
DispatchResponse StopTrackingHeapObjects(std::unique_ptr<StopTrackingHeapObjectsParams> params);
|
||||
// The params type of TakeHeapSnapshot is the same as of StopTrackingHeapObjects.
|
||||
DispatchResponse TakeHeapSnapshot(std::unique_ptr<StopTrackingHeapObjectsParams> params);
|
||||
|
||||
class DispatcherImpl final : public DispatcherBase {
|
||||
public:
|
||||
DispatcherImpl(FrontEnd *frontend, std::unique_ptr<HeapProfilerImpl> heapprofiler);
|
||||
~DispatcherImpl() override = default;
|
||||
void Dispatch(const DispatchRequest &request) override;
|
||||
void AddInspectedHeapObject(const DispatchRequest &request);
|
||||
void CollectGarbage(const DispatchRequest &request);
|
||||
void Enable(const DispatchRequest &request);
|
||||
void Disable(const DispatchRequest &request);
|
||||
void GetHeapObjectId(const DispatchRequest &request);
|
||||
void GetObjectByHeapObjectId(const DispatchRequest &request);
|
||||
void GetSamplingProfile(const DispatchRequest &request);
|
||||
void StartSampling(const DispatchRequest &request);
|
||||
void StartTrackingHeapObjects(const DispatchRequest &request);
|
||||
void StopSampling(const DispatchRequest &request);
|
||||
void StopTrackingHeapObjects(const DispatchRequest &request);
|
||||
void TakeHeapSnapshot(const DispatchRequest &request);
|
||||
|
||||
private:
|
||||
NO_COPY_SEMANTIC(DispatcherImpl);
|
||||
|
@ -848,7 +848,6 @@ std::unique_ptr<StopTrackingHeapObjectsParams> StopTrackingHeapObjectsParams::Cr
|
||||
return paramsObject;
|
||||
}
|
||||
|
||||
|
||||
Local<ObjectRef> StopTrackingHeapObjectsParams::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> params = NewObject(ecmaVm);
|
||||
@ -862,4 +861,138 @@ Local<ObjectRef> StopTrackingHeapObjectsParams::ToObject(const EcmaVM *ecmaVm)
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::unique_ptr<AddInspectedHeapObjectParams> AddInspectedHeapObjectParams::Create(const EcmaVM *ecmaVm,
|
||||
const Local<JSValueRef> ¶ms)
|
||||
{
|
||||
ASSERT(ecmaVm);
|
||||
if (params.IsEmpty()) {
|
||||
LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create params is nullptr";
|
||||
return nullptr;
|
||||
}
|
||||
CString error;
|
||||
auto paramsObject = std::make_unique<AddInspectedHeapObjectParams>();
|
||||
|
||||
Local<JSValueRef> result = Local<ObjectRef>(params)->Get(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "heapObjectId")));
|
||||
if (!result.IsEmpty() && !result->IsUndefined()) {
|
||||
if (result->IsString()) {
|
||||
paramsObject->heapObjectId_ = DebuggerApi::StringToInt(result);
|
||||
} else {
|
||||
error += "'heapObjectId' should be a String;";
|
||||
}
|
||||
} else {
|
||||
error += "should contain 'heapObjectId';";
|
||||
}
|
||||
|
||||
if (!error.empty()) {
|
||||
LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create " << error;
|
||||
return nullptr;
|
||||
}
|
||||
return paramsObject;
|
||||
}
|
||||
|
||||
Local<ObjectRef> AddInspectedHeapObjectParams::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> params = NewObject(ecmaVm);
|
||||
|
||||
params->Set(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "heapObjectId")),
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, std::to_string(heapObjectId_).c_str())));
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::unique_ptr<GetHeapObjectIdParams> GetHeapObjectIdParams::Create(const EcmaVM *ecmaVm,
|
||||
const Local<JSValueRef> ¶ms)
|
||||
{
|
||||
ASSERT(ecmaVm);
|
||||
if (params.IsEmpty()) {
|
||||
LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create params is nullptr";
|
||||
return nullptr;
|
||||
}
|
||||
CString error;
|
||||
auto paramsObject = std::make_unique<GetHeapObjectIdParams>();
|
||||
|
||||
Local<JSValueRef> result = Local<ObjectRef>(params)->Get(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectId")));
|
||||
if (!result.IsEmpty() && !result->IsUndefined()) {
|
||||
if (result->IsString()) {
|
||||
paramsObject->objectId_ = DebuggerApi::StringToInt(result);
|
||||
} else {
|
||||
error += "'objectId' should be a String;";
|
||||
}
|
||||
} else {
|
||||
error += "should contain 'objectId';";
|
||||
}
|
||||
|
||||
if (!error.empty()) {
|
||||
LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create " << error;
|
||||
return nullptr;
|
||||
}
|
||||
return paramsObject;
|
||||
}
|
||||
|
||||
Local<ObjectRef> GetHeapObjectIdParams::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> params = NewObject(ecmaVm);
|
||||
|
||||
params->Set(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectId")),
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_).c_str())));
|
||||
return params;
|
||||
}
|
||||
|
||||
std::unique_ptr<GetObjectByHeapObjectIdParams> GetObjectByHeapObjectIdParams::Create(const EcmaVM *ecmaVm,
|
||||
const Local<JSValueRef> ¶ms)
|
||||
{
|
||||
ASSERT(ecmaVm);
|
||||
if (params.IsEmpty()) {
|
||||
LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create params is nullptr";
|
||||
return nullptr;
|
||||
}
|
||||
CString error;
|
||||
auto paramsObject = std::make_unique<GetObjectByHeapObjectIdParams>();
|
||||
|
||||
Local<JSValueRef> result = Local<ObjectRef>(params)->Get(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectId")));
|
||||
if (!result.IsEmpty() && !result->IsUndefined()) {
|
||||
if (result->IsString()) {
|
||||
paramsObject->objectId_ = DebuggerApi::StringToInt(result);
|
||||
} else {
|
||||
error += "'objectId' should be a String;";
|
||||
}
|
||||
} else {
|
||||
error += "should contain 'objectId';";
|
||||
}
|
||||
|
||||
result = Local<ObjectRef>(params)->Get(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectGroup")));
|
||||
if (!result.IsEmpty() && !result->IsUndefined()) {
|
||||
if (result->IsString()) {
|
||||
paramsObject->objectGroup_ = DebuggerApi::ToCString(result);
|
||||
} else {
|
||||
error += "'objectGroup' should be a String;";
|
||||
}
|
||||
}
|
||||
|
||||
if (!error.empty()) {
|
||||
LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create " << error;
|
||||
return nullptr;
|
||||
}
|
||||
return paramsObject;
|
||||
}
|
||||
|
||||
Local<ObjectRef> GetObjectByHeapObjectIdParams::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> params = NewObject(ecmaVm);
|
||||
|
||||
params->Set(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectId")),
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_).c_str())));
|
||||
params->Set(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "objectGroup")),
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, objectGroup_->c_str())));
|
||||
return params;
|
||||
}
|
||||
} // namespace panda::ecmascript::tooling
|
||||
|
@ -749,5 +749,76 @@ private:
|
||||
std::optional<bool> treatGlobalObjectsAsRoots_ {};
|
||||
std::optional<bool> captureNumericValue_ {};
|
||||
};
|
||||
|
||||
class AddInspectedHeapObjectParams : public PtBaseParams {
|
||||
public:
|
||||
AddInspectedHeapObjectParams() = default;
|
||||
~AddInspectedHeapObjectParams() override = default;
|
||||
|
||||
static std::unique_ptr<AddInspectedHeapObjectParams> Create(const EcmaVM *ecmaVm, const Local<JSValueRef> ¶ms);
|
||||
Local<ObjectRef> ToObject(const EcmaVM *ecmaVm) override;
|
||||
|
||||
HeapSnapshotObjectId GetHeapObjectId() const
|
||||
{
|
||||
return heapObjectId_;
|
||||
}
|
||||
|
||||
private:
|
||||
NO_COPY_SEMANTIC(AddInspectedHeapObjectParams);
|
||||
NO_MOVE_SEMANTIC(AddInspectedHeapObjectParams);
|
||||
|
||||
HeapSnapshotObjectId heapObjectId_ {};
|
||||
};
|
||||
|
||||
class GetHeapObjectIdParams : public PtBaseParams {
|
||||
public:
|
||||
GetHeapObjectIdParams() = default;
|
||||
~GetHeapObjectIdParams() override = default;
|
||||
|
||||
static std::unique_ptr<GetHeapObjectIdParams> Create(const EcmaVM *ecmaVm, const Local<JSValueRef> ¶ms);
|
||||
Local<ObjectRef> ToObject(const EcmaVM *ecmaVm) override;
|
||||
|
||||
RemoteObjectId GetObjectId() const
|
||||
{
|
||||
return objectId_;
|
||||
}
|
||||
|
||||
private:
|
||||
NO_COPY_SEMANTIC(GetHeapObjectIdParams);
|
||||
NO_MOVE_SEMANTIC(GetHeapObjectIdParams);
|
||||
|
||||
RemoteObjectId objectId_ {};
|
||||
};
|
||||
|
||||
class GetObjectByHeapObjectIdParams : public PtBaseParams {
|
||||
public:
|
||||
GetObjectByHeapObjectIdParams() = default;
|
||||
~GetObjectByHeapObjectIdParams() override = default;
|
||||
|
||||
static std::unique_ptr<GetObjectByHeapObjectIdParams> Create(const EcmaVM *ecmaVm, const Local<JSValueRef> ¶ms);
|
||||
Local<ObjectRef> ToObject(const EcmaVM *ecmaVm) override;
|
||||
|
||||
HeapSnapshotObjectId GetObjectId() const
|
||||
{
|
||||
return objectId_;
|
||||
}
|
||||
|
||||
const CString &GetObjectGroup() const
|
||||
{
|
||||
return objectGroup_.value();
|
||||
}
|
||||
|
||||
bool HasObjectGroup() const
|
||||
{
|
||||
return objectGroup_.has_value();
|
||||
}
|
||||
|
||||
private:
|
||||
NO_COPY_SEMANTIC(GetObjectByHeapObjectIdParams);
|
||||
NO_MOVE_SEMANTIC(GetObjectByHeapObjectIdParams);
|
||||
|
||||
HeapSnapshotObjectId objectId_ {};
|
||||
std::optional<CString> objectGroup_ {};
|
||||
};
|
||||
} // namespace panda::ecmascript::tooling
|
||||
#endif
|
@ -247,6 +247,30 @@ Local<ObjectRef> StopSamplingReturns::ToObject(const EcmaVM *ecmaVm)
|
||||
return result;
|
||||
}
|
||||
|
||||
Local<ObjectRef> GetHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> result = NewObject(ecmaVm);
|
||||
|
||||
result->Set(ecmaVm,
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "heapSnapshotObjectId")),
|
||||
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, std::to_string(heapSnapshotObjectId_).c_str())));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Local<ObjectRef> GetObjectByHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> result = NewObject(ecmaVm);
|
||||
|
||||
if (remoteObjectResult_ != nullptr) {
|
||||
Local<ObjectRef> remoteObjectResult = remoteObjectResult_->ToObject(ecmaVm);
|
||||
result->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "result")),
|
||||
Local<JSValueRef>(remoteObjectResult));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Local<ObjectRef> StopReturns::ToObject(const EcmaVM *ecmaVm)
|
||||
{
|
||||
Local<ObjectRef> result = NewObject(ecmaVm);
|
||||
|
@ -265,6 +265,40 @@ private:
|
||||
std::unique_ptr<SamplingHeapProfile> profile_ {};
|
||||
};
|
||||
|
||||
class GetHeapObjectIdReturns : public PtBaseReturns {
|
||||
public:
|
||||
explicit GetHeapObjectIdReturns(HeapSnapshotObjectId heapSnapshotObjectId)
|
||||
: heapSnapshotObjectId_(std::move(heapSnapshotObjectId))
|
||||
{}
|
||||
~GetHeapObjectIdReturns() override = default;
|
||||
|
||||
Local<ObjectRef> ToObject(const EcmaVM *ecmaVm) override;
|
||||
|
||||
private:
|
||||
GetHeapObjectIdReturns() = default;
|
||||
NO_COPY_SEMANTIC(GetHeapObjectIdReturns);
|
||||
NO_MOVE_SEMANTIC(GetHeapObjectIdReturns);
|
||||
|
||||
HeapSnapshotObjectId heapSnapshotObjectId_ {};
|
||||
};
|
||||
|
||||
class GetObjectByHeapObjectIdReturns : public PtBaseReturns {
|
||||
public:
|
||||
explicit GetObjectByHeapObjectIdReturns(std::unique_ptr<RemoteObject> remoteObjectResult)
|
||||
: remoteObjectResult_(std::move(remoteObjectResult))
|
||||
{}
|
||||
~GetObjectByHeapObjectIdReturns() override = default;
|
||||
|
||||
Local<ObjectRef> ToObject(const EcmaVM *ecmaVm) override;
|
||||
|
||||
private:
|
||||
GetObjectByHeapObjectIdReturns() = default;
|
||||
NO_COPY_SEMANTIC(GetObjectByHeapObjectIdReturns);
|
||||
NO_MOVE_SEMANTIC(GetObjectByHeapObjectIdReturns);
|
||||
|
||||
std::unique_ptr<RemoteObject> remoteObjectResult_ {};
|
||||
};
|
||||
|
||||
class StopReturns : public PtBaseReturns {
|
||||
public:
|
||||
explicit StopReturns(std::unique_ptr<Profile> profile) : profile_(std::move(profile)) {}
|
||||
|
@ -90,6 +90,7 @@ using CallFrameId = uint32_t;
|
||||
using ScriptId = uint32_t;
|
||||
|
||||
// Runtime.RemoteObjectId
|
||||
|
||||
using RemoteObjectId = uint32_t;
|
||||
|
||||
// Runtime.ExecutionContextId
|
||||
@ -1474,6 +1475,10 @@ private:
|
||||
std::optional<std::unique_ptr<RemoteObject>> returnValue_ {};
|
||||
};
|
||||
|
||||
// ========== Heapprofiler types begin
|
||||
|
||||
using HeapSnapshotObjectId = uint32_t;
|
||||
|
||||
class SamplingHeapProfileSample final : public PtBaseTypes {
|
||||
public:
|
||||
SamplingHeapProfileSample() = default;
|
||||
|
@ -279,4 +279,197 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsToObjectTest)
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
ASSERT_TRUE(result->IsTrue());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, AddInspectedHeapObjectParamsCreateTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<AddInspectedHeapObjectParams> objectData;
|
||||
|
||||
// abnormal params of null msg
|
||||
msg = CString() + R"({})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unexist key params
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test"})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of null params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unknown params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["heapObjectId":10]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":10}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["heapObjectId":true]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":true}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["heapObjectId":“10”]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":"10"}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
EXPECT_EQ((int)objectData->GetHeapObjectId(), 10);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, AddInspectedHeapObjectParamsToObjectTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<AddInspectedHeapObjectParams> objectData;
|
||||
Local<StringRef> tmpStr;
|
||||
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":"10"}})";
|
||||
objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
Local<ObjectRef> object = objectData->ToObject(ecmaVm);
|
||||
|
||||
tmpStr = StringRef::NewFromUtf8(ecmaVm, "heapObjectId");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
Local<JSValueRef> result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
EXPECT_EQ(DebuggerApi::ToCString(result), "10");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsCreateTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<GetHeapObjectIdParams> objectData;
|
||||
|
||||
// abnormal params of null msg
|
||||
msg = CString() + R"({})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unexist key params
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test"})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of null params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unknown params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":10]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":true]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":true}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":“10”]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
EXPECT_EQ((int)objectData->GetObjectId(), 10);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsToObjectTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<GetHeapObjectIdParams> objectData;
|
||||
Local<StringRef> tmpStr;
|
||||
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})";
|
||||
objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
Local<ObjectRef> object = objectData->ToObject(ecmaVm);
|
||||
|
||||
tmpStr = StringRef::NewFromUtf8(ecmaVm, "objectId");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
Local<JSValueRef> result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
EXPECT_EQ(DebuggerApi::ToCString(result), "10");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, GetObjectByHeapObjectIdParamsCreateTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<GetObjectByHeapObjectIdParams> objectData;
|
||||
|
||||
// abnormal params of null msg
|
||||
msg = CString() + R"({})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unexist key params
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test"})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of null params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of unknown params.sub-key
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":10]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":true]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":10}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
EXPECT_EQ(objectData, nullptr);
|
||||
|
||||
// abnormal params of params.sub-key=["objectId":“10”]
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
EXPECT_EQ((int)objectData->GetObjectId(), 10);
|
||||
ASSERT_FALSE(objectData->HasObjectGroup());
|
||||
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":"groupname"}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
EXPECT_EQ((int)objectData->GetObjectId(), 10);
|
||||
EXPECT_EQ(objectData->GetObjectGroup(), "groupname");
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerParamsTest, GetObjectByHeapObjectIdParamsToObjectTest)
|
||||
{
|
||||
CString msg;
|
||||
std::unique_ptr<GetObjectByHeapObjectIdParams> objectData;
|
||||
Local<StringRef> tmpStr;
|
||||
|
||||
msg = CString() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":"groupname"}})";
|
||||
objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParams());
|
||||
ASSERT_NE(objectData, nullptr);
|
||||
Local<ObjectRef> object = objectData->ToObject(ecmaVm);
|
||||
|
||||
tmpStr = StringRef::NewFromUtf8(ecmaVm, "objectId");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
Local<JSValueRef> result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
EXPECT_EQ(DebuggerApi::ToCString(result), "10");
|
||||
|
||||
tmpStr = StringRef::NewFromUtf8(ecmaVm, "objectGroup");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
EXPECT_EQ(DebuggerApi::ToCString(result), "groupname");
|
||||
}
|
||||
} // namespace panda::test
|
||||
|
@ -259,6 +259,36 @@ HWTEST_F_L0(DebuggerReturnsTest, StopSamplingReturnsToObjectTest)
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerReturnsTest, GetHeapObjectIdReturnsToObjectTest)
|
||||
{
|
||||
std::unique_ptr<GetHeapObjectIdReturns> getHeapObjectIdReturns = std::make_unique<GetHeapObjectIdReturns>(10);
|
||||
ASSERT_NE(getHeapObjectIdReturns, nullptr);
|
||||
|
||||
Local<ObjectRef> object = getHeapObjectIdReturns->ToObject(ecmaVm);
|
||||
Local<StringRef> tmpStr = StringRef::NewFromUtf8(ecmaVm, "heapSnapshotObjectId");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
|
||||
Local<JSValueRef> result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
EXPECT_EQ(CString("10"), DebuggerApi::ToCString(result));
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerReturnsTest, GetObjectByHeapObjectIdReturnsToObjectTest)
|
||||
{
|
||||
std::unique_ptr<RemoteObject> remoteObjectResult = std::make_unique<RemoteObject>();
|
||||
std::unique_ptr<GetObjectByHeapObjectIdReturns> getObjectByHeapObjectIdReturns =
|
||||
std::make_unique<GetObjectByHeapObjectIdReturns>(std::move(remoteObjectResult));
|
||||
ASSERT_NE(getObjectByHeapObjectIdReturns, nullptr);
|
||||
|
||||
Local<ObjectRef> object = getObjectByHeapObjectIdReturns->ToObject(ecmaVm);
|
||||
Local<StringRef> tmpStr = StringRef::NewFromUtf8(ecmaVm, "result");
|
||||
ASSERT_TRUE(object->Has(ecmaVm, tmpStr));
|
||||
|
||||
Local<JSValueRef> result = object->Get(ecmaVm, tmpStr);
|
||||
ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined());
|
||||
ASSERT_EQ(std::move(remoteObjectResult), nullptr);
|
||||
}
|
||||
|
||||
HWTEST_F_L0(DebuggerReturnsTest, StopReturnsToObjectTest)
|
||||
{
|
||||
std::unique_ptr<Profile> profile = std::make_unique<Profile>();
|
||||
|
Loading…
Reference in New Issue
Block a user