diff --git a/frameworks/core/components_ng/base/ui_node.cpp b/frameworks/core/components_ng/base/ui_node.cpp index 53a5787912c915f78cd1fe1cb30533724341d8f8..34e5eedbf4e9b6059dcd76d0452e89ff31f3f8ca 100644 --- a/frameworks/core/components_ng/base/ui_node.cpp +++ b/frameworks/core/components_ng/base/ui_node.cpp @@ -1154,6 +1154,28 @@ void UINode::DumpTree(int32_t depth, bool hasJson) } } +bool UINode::DumpTreeByComponentName(const std::string& name) +{ + if (auto customNode = DynamicCast(this)) { + const std::string& tag = customNode->GetCustomTag(); + if (tag.size() >= name.size() && StringUtils::StartWith(tag, name)) { + DumpTree(0); + return true; + } + } + for (const auto& item : GetChildren()) { + if (item->DumpTreeByComponentName(name)) { + return true; + } + } + for (const auto& [item, index, branch] : disappearingChildren_) { + if (item->DumpTreeByComponentName(name)) { + return true; + } + } + return false; +} + void UINode::DumpTreeJsonForDiff(std::unique_ptr& json) { auto currentNode = JsonUtil::Create(true); diff --git a/frameworks/core/components_ng/base/ui_node.h b/frameworks/core/components_ng/base/ui_node.h index 1480f245db355e5c3e14f0fe1fc6f05d329a8d03..363bb7bcc667a94dc4cbcd789f376e730c07104b 100644 --- a/frameworks/core/components_ng/base/ui_node.h +++ b/frameworks/core/components_ng/base/ui_node.h @@ -254,6 +254,7 @@ public: virtual bool IsContextTransparent(); bool DumpTreeById(int32_t depth, const std::string& id, bool hasJson = false); + bool DumpTreeByComponentName(const std::string& name); const std::string& GetTag() const { diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 0db0cc10ddae8c275f23412b5ea211143a3c6880..3ad460febe454ba98db23122fe0f191ad7cb8edb 100755 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -3546,7 +3546,11 @@ bool PipelineContext::OnDumpInfo(const std::vector& params) const StylusDetectorDefault::GetInstance()->ExecuteCommand(params); } else if (params[0] == "-simplify") { LOGI("start collect simplify dump info"); - rootNode_->DumpTree(0); + if (params.size() >= 3 && params[1] == "-compname") { + rootNode_->DumpTreeByComponentName(params[2]); + } else { + rootNode_->DumpTree(0); + } DumpLog::GetInstance().OutPutByCompress(); LOGI("end collect simplify dump info"); } else if (params[0] == "-resource") { @@ -3565,6 +3569,9 @@ bool PipelineContext::OnDumpInfo(const std::vector& params) const DumpForceColor(params); } else if (params[0] == "-bindaicaller" && params.size() >= PARAM_NUM) { OnDumpBindAICaller(params); + } else if (params[0] == "-compname" && params.size() >= PARAM_NUM) { + rootNode_->DumpTreeByComponentName(params[1]); + DumpLog::GetInstance().OutPutDefault(); } return true; } diff --git a/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp b/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp index da35777049a31fe5f9f75f18eb631eaa20b4a2ac..dd5aae742f211f648faae12c70d459fe6d7f7a12 100644 --- a/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp +++ b/test/unittest/core/pipeline/pipeline_context_test_ng_two.cpp @@ -2560,6 +2560,26 @@ HWTEST_F(PipelineContextTestNg, PipelineContextTestNg406, TestSize.Level1) EXPECT_TRUE(context_->windowModal_ != WindowModal::CONTAINER_MODAL); } +/** + * @tc.name: PipelineContextTestNg407 + * @tc.desc: Test OnDumpInfo. + * @tc.type: FUNC + */ +HWTEST_F(PipelineContextTestNg, PipelineContextTestNg407, TestSize.Level1) +{ + /** + * @tc.steps1: Call the function OnDumpInfo. + * @tc.expected: Test that the member window_ is empty. + */ + ASSERT_NE(context_, nullptr); + std::vector params; + params.push_back("-simplify"); + params.push_back("-compname"); + params.push_back("test"); + auto ret = context_->OnDumpInfo(params); + EXPECT_TRUE(ret); +} + /** * @tc.name: FlushMouseEventForHover001 * @tc.desc: Test FlushMouseEventForHover.