Skip to content

Commit

Permalink
fix(perf): support dom time for performance api
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao authored and hippy-actions[bot] committed Aug 4, 2023
1 parent d7b7ec4 commit f35f899
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions dom/include/dom/dom_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class DomManager : public std::enable_shared_from_this<DomManager> {
static byte_string GetSnapShot(const std::shared_ptr<RootNode>& root_node);
bool SetSnapShot(const std::shared_ptr<RootNode>& root_node, const byte_string& buffer);

void RecordDomStartTimePoint();
void RecordDomEndTimePoint();
inline auto GetDomStartTimePoint() { return dom_start_time_point_; }
inline auto GetDomEndTimePoint() { return dom_end_time_point_; }

private:
friend class DomNode;

Expand All @@ -140,6 +145,9 @@ class DomManager : public std::enable_shared_from_this<DomManager> {
std::unordered_map<uint32_t, std::shared_ptr<BaseTimer>> timer_map_;
std::shared_ptr<TaskRunner> task_runner_;
std::shared_ptr<Worker> worker_;

footstone::TimePoint dom_start_time_point_;
footstone::TimePoint dom_end_time_point_;
};

} // namespace dom
Expand Down
12 changes: 12 additions & 0 deletions dom/src/dom/dom_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,17 @@ bool DomManager::SetSnapShot(const std::shared_ptr<RootNode>& root_node, const b
return true;
}

void DomManager::RecordDomStartTimePoint() {
if (dom_start_time_point_.ToEpochDelta() == TimeDelta::Zero()) {
dom_start_time_point_ = footstone::TimePoint::SystemNow();
}
}

void DomManager::RecordDomEndTimePoint() {
if (dom_end_time_point_.ToEpochDelta() == TimeDelta::Zero()) {
dom_end_time_point_ = footstone::TimePoint::SystemNow();
}
}

} // namespace dom
} // namespace hippy
4 changes: 4 additions & 0 deletions dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ void RootNode::SyncWithRenderManager(const std::shared_ptr<RenderManager>& rende
FlushDomOperations(render_manager);
FlushEventOperations(render_manager);
DoAndFlushLayout(render_manager);
auto dom_manager = dom_manager_.lock();
if (dom_manager) {
dom_manager->RecordDomEndTimePoint();
}
render_manager->EndBatch(GetWeakSelf());
}

Expand Down
1 change: 1 addition & 0 deletions dom/src/dom/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void SceneBuilder::Create(const std::weak_ptr<DomManager>& weak_dom_manager,
std::vector<std::shared_ptr<DomInfo>>&& nodes) {
auto dom_manager = weak_dom_manager.lock();
if (dom_manager) {
dom_manager->RecordDomStartTimePoint();
dom_manager->CreateDomNodes(root_node, std::move(nodes));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class PerformanceNavigationTiming : public PerformanceEntry {
DEFINE_SET_AND_GET_METHOD(HippyJsEngineInitEnd, TimePoint, hippy_js_engine_init_end_)
DEFINE_SET_AND_GET_METHOD(HippyRunApplicationStart, TimePoint, hippy_run_application_start_)
DEFINE_SET_AND_GET_METHOD(HippyRunApplicationEnd, TimePoint, hippy_run_application_end_)
DEFINE_SET_AND_GET_METHOD(HippyDomStart, TimePoint, hippy_dom_start_)
DEFINE_SET_AND_GET_METHOD(HippyDomEnd, TimePoint, hippy_dom_end_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameStart, TimePoint, hippy_first_frame_start_)
DEFINE_SET_AND_GET_METHOD(HippyFirstFrameEnd, TimePoint, hippy_first_frame_end_)
#undef DEFINE_SET_AND_GET_METHOD
Expand All @@ -80,6 +82,8 @@ class PerformanceNavigationTiming : public PerformanceEntry {
std::vector<BundleInfo> bundle_info_array_;
TimePoint hippy_run_application_start_;
TimePoint hippy_run_application_end_;
TimePoint hippy_dom_start_;
TimePoint hippy_dom_end_;
TimePoint hippy_first_frame_start_;
TimePoint hippy_first_frame_end_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ std::shared_ptr<ClassTemplate<PerformanceNavigationTiming>> RegisterPerformanceN
ADD_PROPERTY(hippy_js_engine_init_end, "hippyJsEngineInitEnd", GetHippyJsEngineInitEnd)
ADD_PROPERTY(hippy_run_application_start, "hippyRunApplicationStart", GetHippyRunApplicationStart)
ADD_PROPERTY(hippy_run_application_end, "hippyRunApplicationEnd", GetHippyRunApplicationEnd)
ADD_PROPERTY(hippy_dom_start, "hippyDomStart", GetHippyDomStart)
ADD_PROPERTY(hippy_dom_end, "hippyDomEnd", GetHippyDomEnd)
ADD_PROPERTY(hippy_first_frame_start, "hippyFirstFrameStart", GetHippyFirstFrameStart)
ADD_PROPERTY(hippy_first_frame_end, "hippyFirstFrameEnd", GetHippyFirstFrameEnd)
#undef ADD_PROPERTY
Expand Down
7 changes: 6 additions & 1 deletion driver/js/src/scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ void Scope::LoadInstance(const std::shared_ptr<HippyValue>& value) {
DEFINE_AND_CHECK_SELF(Scope)
// perfromance start time
auto entry = self->GetPerformance()->PerformanceNavigation("hippyInit");
entry->SetHippyFirstFrameStart(footstone::TimePoint::SystemNow());
entry->SetHippyRunApplicationStart(footstone::TimePoint::SystemNow());

std::shared_ptr<Ctx> context = weak_context.lock();
Expand Down Expand Up @@ -561,6 +560,12 @@ void Scope::LoadInstance(const std::shared_ptr<HippyValue>& value) {

// perfromance end time
entry->SetHippyRunApplicationEnd(footstone::TimePoint::SystemNow());
auto dom_manager = self->GetDomManager().lock();
if (dom_manager) {
entry->SetHippyDomStart(dom_manager->GetDomStartTimePoint());
entry->SetHippyDomEnd(dom_manager->GetDomEndTimePoint());
entry->SetHippyFirstFrameStart(dom_manager->GetDomEndTimePoint());
}
};
auto runner = GetTaskRunner();
if (footstone::Worker::IsTaskRunning() && runner == footstone::runner::TaskRunner::GetCurrentTaskRunner()) {
Expand Down

0 comments on commit f35f899

Please sign in to comment.