!1130 change profiler types

Merge pull request !1130 from buzhuyu/master
This commit is contained in:
openharmony_ci 2022-04-26 08:12:06 +00:00 committed by Gitee
commit 4b8b35b2f4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 155 additions and 89 deletions

View File

@ -101,7 +101,8 @@ void JSBackend::NotifyPaused(std::optional<JSPtLocation> location, PauseReason r
std::unique_ptr<Paused> paused = std::make_unique<Paused>();
paused->SetCallFrames(std::move(callFrames)).SetReason(reason).SetHitBreakpoints(std::move(hitBreakpoints));
if (reason == EXCEPTION && exception->IsError()) {
paused->SetData(exception);
std::unique_ptr<RemoteObject> tmpException = RemoteObject::FromTagged(ecmaVm_, exception);
paused->SetData(std::move(tmpException));
}
frontend_->SendNotification(ecmaVm_, std::move(paused));

View File

@ -24,7 +24,7 @@
namespace panda::ecmascript::tooling {
class ProfilerImpl final {
public:
explicit ProfilerImpl(JSBackend *backend) : backend_(backend) {}
explicit ProfilerImpl() {}
~ProfilerImpl() = default;
DispatchResponse Disable();
@ -67,9 +67,7 @@ public:
private:
NO_COPY_SEMANTIC(ProfilerImpl);
NO_MOVE_SEMANTIC(ProfilerImpl);
std::unique_ptr<JSBackend> backend_ {nullptr};
NO_MOVE_SEMANTIC(ProfilerImpl);
};
} // namespace panda::ecmascript::tooling
#endif

View File

@ -123,7 +123,12 @@ std::unique_ptr<Paused> Paused::Create(const EcmaVM *ecmaVm, const Local<JSValue
result = Local<ObjectRef>(params)->Get(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "data")));
if (!result.IsEmpty() && !result->IsUndefined()) {
if (result->IsObject()) {
paused->data_ = Local<ObjectRef>(result);
std::unique_ptr<RemoteObject> obj = RemoteObject::Create(ecmaVm, result);
if (obj == nullptr) {
error += "'data' format error;";
} else {
paused->data_ = std::move(obj);
}
} else {
error += "'data' should a Object;";
}
@ -172,7 +177,7 @@ Local<ObjectRef> Paused::ToObject(const EcmaVM *ecmaVm)
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, reason_.c_str())));
if (data_) {
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "data")),
Local<JSValueRef>(data_.value()));
Local<JSValueRef>(data_.value()->ToObject(ecmaVm)));
}
if (hitBreakpoints_) {
len = hitBreakpoints_->size();
@ -851,9 +856,11 @@ Local<ObjectRef> ConsoleProfileFinished::ToObject(const EcmaVM *ecmaVm)
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "profile")),
Local<JSValueRef>(profile_->ToObject(ecmaVm)));
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "title")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, title_.c_str())));
if (title_) {
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "title")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, title_->c_str())));
}
Local<ObjectRef> object = NewObject(ecmaVm);
object->Set(ecmaVm,
@ -928,9 +935,11 @@ Local<ObjectRef> ConsoleProfileStarted::ToObject(const EcmaVM *ecmaVm)
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "location")),
Local<JSValueRef>(location_->ToObject(ecmaVm)));
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "title")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, title_.c_str())));
if (title_) {
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "title")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, title_->c_str())));
}
Local<ObjectRef> object = NewObject(ecmaVm);
object->Set(ecmaVm,

View File

@ -159,14 +159,17 @@ public:
return "";
}
Local<ObjectRef> GetData() const
RemoteObject *GetData() const
{
return data_.value_or(Local<ObjectRef>());
if (data_) {
return data_->get();
}
return nullptr;
}
Paused &SetData(const Local<ObjectRef> &data)
Paused &SetData(std::unique_ptr<RemoteObject> data)
{
data_ = data;
data_ = std::move(data);
return *this;
}
@ -197,7 +200,7 @@ private:
CVector<std::unique_ptr<CallFrame>> callFrames_ {};
CString reason_ {};
std::optional<Local<ObjectRef>> data_ {};
std::optional<std::unique_ptr<RemoteObject>> data_ {};
std::optional<CVector<BreakpointId>> hitBreakpoints_ {};
};
@ -802,7 +805,7 @@ public:
const CString &GetTitle() const
{
return title_;
return title_.value();
}
ConsoleProfileFinished &SetTitle(const CString &title)
@ -811,6 +814,11 @@ public:
return *this;
}
bool HasTitle() const
{
return title_.has_value();
}
private:
NO_COPY_SEMANTIC(ConsoleProfileFinished);
NO_MOVE_SEMANTIC(ConsoleProfileFinished);
@ -818,7 +826,7 @@ private:
CString id_ {};
std::unique_ptr<Location> location_ {nullptr};
std::unique_ptr<Profile> profile_ {nullptr};
CString title_ {};
std::optional<CString> title_ {};
};
class ConsoleProfileStarted final : public PtBaseEvents {
@ -856,7 +864,7 @@ public:
const CString &GetTitle() const
{
return title_;
return title_.value();
}
ConsoleProfileStarted &SetTitle(const CString &title)
@ -865,13 +873,18 @@ public:
return *this;
}
bool HasTitle() const
{
return title_.has_value();
}
private:
NO_COPY_SEMANTIC(ConsoleProfileStarted);
NO_MOVE_SEMANTIC(ConsoleProfileStarted);
CString id_ {};
std::unique_ptr<Location> location_ {nullptr};
CString title_ {};
std::optional<CString> title_ {};
};
class PreciseCoverageDeltaUpdate final : public PtBaseEvents {

View File

@ -2056,7 +2056,7 @@ std::unique_ptr<ProfileNode> ProfileNode::Create(const EcmaVM *ecmaVm, const Loc
std::unique_ptr<int32_t> pChildren;
Local<JSValueRef> resultValue = Local<ObjectRef>(array)->Get(ecmaVm, key->ToString(ecmaVm));
*pChildren = resultValue->Int32Value(ecmaVm);
profileNode->children_.emplace_back(std::move(pChildren));
profileNode->children_->emplace_back(std::move(pChildren));
}
} else {
error += "'children' should be an Array;";
@ -2074,7 +2074,7 @@ std::unique_ptr<ProfileNode> ProfileNode::Create(const EcmaVM *ecmaVm, const Loc
key = IntegerRef::New(ecmaVm, i);
Local<JSValueRef> resultValue = Local<ObjectRef>(array)->Get(ecmaVm, key->ToString(ecmaVm));
std::unique_ptr<PositionTickInfo> positionTick = PositionTickInfo::Create(ecmaVm, resultValue);
profileNode->positionTicks_.emplace_back(std::move(positionTick));
profileNode->positionTicks_->emplace_back(std::move(positionTick));
}
} else {
error += "'positionTicks' should be an Array;";
@ -2108,29 +2108,39 @@ Local<ObjectRef> ProfileNode::ToObject(const EcmaVM *ecmaVm)
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "callFrame")),
Local<JSValueRef>(callFrame_->ToObject(ecmaVm)));
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "hitCount")),
IntegerRef::New(ecmaVm, hitCount_));
size_t childrenLen = children_.size();
Local<ArrayRef> childrenValues = ArrayRef::New(ecmaVm, childrenLen);
for (size_t i = 0; i < childrenLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(children_[i]));
childrenValues->Set(ecmaVm, i, elem);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "children")), childrenValues);
size_t positionTickLen = positionTicks_.size();
Local<ArrayRef> positionValues = ArrayRef::New(ecmaVm, positionTickLen);
for (size_t i = 0; i < positionTickLen; i++) {
Local<ObjectRef> positionTick = positionTicks_[i]->ToObject(ecmaVm);
positionValues->Set(ecmaVm, i, positionTick);
if (hitCount_) {
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "hitCount")),
IntegerRef::New(ecmaVm, hitCount_.value()));
}
if (children_) {
size_t childrenLen = children_->size();
Local<ArrayRef> childrenValues = ArrayRef::New(ecmaVm, childrenLen);
for (size_t i = 0; i < childrenLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(children_.value()[i]));
childrenValues->Set(ecmaVm, i, elem);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "children")), childrenValues);
}
if (positionTicks_) {
size_t positionTickLen = positionTicks_->size();
Local<ArrayRef> positionValues = ArrayRef::New(ecmaVm, positionTickLen);
for (size_t i = 0; i < positionTickLen; i++) {
Local<ObjectRef> positionTick = positionTicks_.value()[i]->ToObject(ecmaVm);
positionValues->Set(ecmaVm, i, positionTick);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "positionTicks")), positionValues);
}
if (deoptReason_) {
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "deoptReason")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, deoptReason_->c_str())));
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "positionTicks")), positionValues);
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "deoptReason")),
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, deoptReason_.c_str())));
return params;
}
@ -2193,7 +2203,7 @@ std::unique_ptr<Profile> Profile::Create(const EcmaVM *ecmaVm, const Local<JSVal
std::unique_ptr<int32_t> pSamples;
Local<JSValueRef> resultValue = Local<ObjectRef>(array)->Get(ecmaVm, key->ToString(ecmaVm));
*pSamples = resultValue->Int32Value(ecmaVm);
profile->samples_.emplace_back(std::move(pSamples));
profile->samples_->emplace_back(std::move(pSamples));
}
} else {
error += "'samples' should be an Array;";
@ -2212,7 +2222,7 @@ std::unique_ptr<Profile> Profile::Create(const EcmaVM *ecmaVm, const Local<JSVal
std::unique_ptr<int32_t> pTime;
Local<JSValueRef> resultValue = Local<ObjectRef>(array)->Get(ecmaVm, key->ToString(ecmaVm));
*pTime = resultValue->Int32Value(ecmaVm);
profile->timeDeltas_.emplace_back(std::move(pTime));
profile->timeDeltas_->emplace_back(std::move(pTime));
}
} else {
error += "'timeDeltas' should be an Array;";
@ -2243,22 +2253,27 @@ Local<ObjectRef> Profile::ToObject(const EcmaVM *ecmaVm)
nodeValues->Set(ecmaVm, i, profileNode);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "nodes")), nodeValues);
size_t samplesLen = samples_.size();
Local<ArrayRef> sampleValues = ArrayRef::New(ecmaVm, samplesLen);
for (size_t i = 0; i < samplesLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(samples_[i]));
sampleValues->Set(ecmaVm, i, elem);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "samples")), sampleValues);
size_t tdLen = timeDeltas_.size();
Local<ArrayRef> timeValues = ArrayRef::New(ecmaVm, tdLen);
for (size_t i = 0; i < tdLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(timeDeltas_[i]));
timeValues->Set(ecmaVm, i, elem);
if (samples_) {
size_t samplesLen = samples_->size();
Local<ArrayRef> sampleValues = ArrayRef::New(ecmaVm, samplesLen);
for (size_t i = 0; i < samplesLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(samples_.value()[i]));
sampleValues->Set(ecmaVm, i, elem);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "samples")), sampleValues);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "timeDeltas")), timeValues);
if (timeDeltas_) {
size_t tdLen = timeDeltas_->size();
Local<ArrayRef> timeValues = ArrayRef::New(ecmaVm, tdLen);
for (size_t i = 0; i < tdLen; i++) {
Local<IntegerRef> elem = IntegerRef::New(ecmaVm, *(timeDeltas_.value()[i]));
timeValues->Set(ecmaVm, i, elem);
}
params->Set(ecmaVm, Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "timeDeltas")), timeValues);
}
return params;
}
@ -2394,7 +2409,7 @@ Local<ObjectRef> FunctionCoverage::ToObject(const EcmaVM *ecmaVm)
if (isBlockCoverage_) {
params->Set(ecmaVm,
Local<JSValueRef>(StringRef::NewFromUtf8(ecmaVm, "isBlockCoverage")),
BooleanRef::New(ecmaVm, isBlockCoverage_.value()));
BooleanRef::New(ecmaVm, isBlockCoverage_));
}
return params;
}

View File

@ -1740,7 +1740,7 @@ public:
int32_t GetHitCount() const
{
return hitCount_;
return hitCount_.value();
}
ProfileNode &SetHitCount(size_t hitCount)
@ -1749,9 +1749,17 @@ public:
return *this;
}
bool HasHitCount() const
{
return hitCount_.has_value();
}
const CVector<std::unique_ptr<int32_t>> *GetChildren() const
{
return &children_;
if (children_) {
return &children_.value();
}
return nullptr;
}
ProfileNode &SetChildren(CVector<std::unique_ptr<int32_t>> children)
@ -1760,9 +1768,17 @@ public:
return *this;
}
bool HasChildren() const
{
return children_.has_value();
}
const CVector<std::unique_ptr<PositionTickInfo>> *GetPositionTicks() const
{
return &positionTicks_;
if (positionTicks_) {
return &positionTicks_.value();
}
return nullptr;
}
ProfileNode &SetPositionTicks(CVector<std::unique_ptr<PositionTickInfo>> positionTicks)
@ -1771,9 +1787,14 @@ public:
return *this;
}
bool HasPositionTicks() const
{
return positionTicks_.has_value();
}
const CString &GetDeoptReason() const
{
return deoptReason_;
return deoptReason_.value();
}
ProfileNode &SetDeoptReason(const CString &deoptReason)
@ -1782,15 +1803,20 @@ public:
return *this;
}
bool HasDeoptReason() const
{
return deoptReason_.has_value();
}
private:
NO_COPY_SEMANTIC(ProfileNode);
NO_MOVE_SEMANTIC(ProfileNode);
size_t id_ {0};
std::unique_ptr<RuntimeCallFrame> callFrame_ {nullptr};
size_t hitCount_ {0};
CVector<std::unique_ptr<int32_t>> children_ {};
CVector<std::unique_ptr<PositionTickInfo>> positionTicks_ {};
CString deoptReason_ {};
std::optional<size_t> hitCount_ {0};
std::optional<CVector<std::unique_ptr<int32_t>>> children_ {};
std::optional<CVector<std::unique_ptr<PositionTickInfo>>> positionTicks_ {};
std::optional<CString> deoptReason_ {};
};
// Profiler.Profile
@ -1829,7 +1855,7 @@ public:
return &nodes_;
}
Profile &SetPositionTicks(CVector<std::unique_ptr<ProfileNode>> nodes)
Profile &SetNodes(CVector<std::unique_ptr<ProfileNode>> nodes)
{
nodes_ = std::move(nodes);
return *this;
@ -1837,7 +1863,10 @@ public:
const CVector<std::unique_ptr<int32_t>> *GetSamples() const
{
return &samples_;
if (samples_) {
return &samples_.value();
}
return nullptr;
}
Profile &SetSamples(CVector<std::unique_ptr<int32_t>> samples)
@ -1846,9 +1875,17 @@ public:
return *this;
}
bool HasSamples() const
{
return samples_.has_value();
}
const CVector<std::unique_ptr<int32_t>> *GetTimeDeltas() const
{
return &timeDeltas_;
if (timeDeltas_) {
return &timeDeltas_.value();
}
return nullptr;
}
Profile &SetTimeDeltas(CVector<std::unique_ptr<int32_t>> timeDeltas)
@ -1857,6 +1894,11 @@ public:
return *this;
}
bool HasTimeDeltas() const
{
return timeDeltas_.has_value();
}
private:
NO_COPY_SEMANTIC(Profile);
NO_MOVE_SEMANTIC(Profile);
@ -1864,8 +1906,8 @@ private:
size_t startTime_ {0};
size_t endTime_ {0};
CVector<std::unique_ptr<ProfileNode>> nodes_ {};
CVector<std::unique_ptr<int32_t>> samples_ {};
CVector<std::unique_ptr<int32_t>> timeDeltas_ {};
std::optional<CVector<std::unique_ptr<int32_t>>> samples_ {};
std::optional<CVector<std::unique_ptr<int32_t>>> timeDeltas_ {};
};
// Profiler.Coverage
@ -1952,7 +1994,7 @@ public:
bool GetIsBlockCoverage() const
{
return isBlockCoverage_.value_or(false);
return isBlockCoverage_;
}
FunctionCoverage &SetisBlockCoverage(bool isBlockCoverage)
@ -1967,7 +2009,7 @@ private:
CString functionName_ {};
CVector<std::unique_ptr<Coverage>> ranges_ {};
std::optional<bool> isBlockCoverage_ {};
bool isBlockCoverage_ {};
};
// Profiler.ScriptCoverage

View File

@ -141,7 +141,7 @@ Dispatcher::Dispatcher(FrontEnd *front)
dispatchers_["HeapProfiler"] =
std::make_unique<HeapProfilerImpl::DispatcherImpl>(front, std::make_unique<HeapProfilerImpl>(front));
dispatchers_["Profiler"] =
std::make_unique<ProfilerImpl::DispatcherImpl>(front, std::make_unique<ProfilerImpl>(backend.get()));
std::make_unique<ProfilerImpl::DispatcherImpl>(front, std::make_unique<ProfilerImpl>());
dispatchers_["Debugger"] =
std::make_unique<DebuggerImpl::DispatcherImpl>(front, std::make_unique<DebuggerImpl>(std::move(backend)));
}

View File

@ -2234,12 +2234,6 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest)
EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
EXPECT_EQ(profileNode->GetHitCount(), 15);
const CVector<std::unique_ptr<int32_t>> *children = profileNode->GetChildren();
ASSERT_NE(children, nullptr);
EXPECT_EQ((int)children->size(), 0);
const CVector<std::unique_ptr<PositionTickInfo>> *positionTicks = profileNode->GetPositionTicks();
ASSERT_NE(positionTicks, nullptr);
EXPECT_EQ((int)positionTicks->size(), 0);
EXPECT_EQ(profileNode->GetDeoptReason(), "yyy");
}
@ -2353,12 +2347,6 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileCreateTest)
const CVector<std::unique_ptr<ProfileNode>> *profileNode = profile->GetNodes();
ASSERT_NE(profileNode, nullptr);
EXPECT_EQ((int)profileNode->size(), 0);
const CVector<std::unique_ptr<int32_t>> *samples = profile->GetSamples();
ASSERT_NE(samples, nullptr);
EXPECT_EQ((int)samples->size(), 0);
const CVector<std::unique_ptr<int32_t>> *timeDeltas = profile->GetTimeDeltas();
ASSERT_NE(timeDeltas, nullptr);
EXPECT_EQ((int)timeDeltas->size(), 0);
}
HWTEST_F_L0(DebuggerTypesTest, ProfileToObjectTest)