From 791bfbbc367be25a4ecb8b9fd86d83233b9d26d6 Mon Sep 17 00:00:00 2001 From: lijuan124 Date: Thu, 24 Jul 2025 20:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8C=89CustomNodeName=20dum?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lijuan124 --- .../core/components_ng/base/ui_node.cpp | 22 +++++++++++++++++++ frameworks/core/components_ng/base/ui_node.h | 1 + .../core/pipeline_ng/pipeline_context.cpp | 9 +++++++- .../pipeline/pipeline_context_test_ng_two.cpp | 20 +++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/base/ui_node.cpp b/frameworks/core/components_ng/base/ui_node.cpp index 53a5787912c..34e5eedbf4e 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 1480f245db3..363bb7bcc66 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 0db0cc10dda..3ad460febe4 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 da35777049a..dd5aae742f2 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. -- Gitee