dump优化

Signed-off-by: xuzheheng <xuzheheng2@h-partners.com>
This commit is contained in:
xuzheheng
2026-01-29 11:10:33 +08:00
parent 5604b39554
commit c3619079fa
6 changed files with 87 additions and 38 deletions
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2025 Huawei Device Co., Ltd.
* Copyright (c) 2023-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -2567,8 +2567,6 @@ private:
void DataDumpSysStateInner(
const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
ErrCode ProcessMultiParam(std::vector<std::string>& argsStr, std::string& result);
void ShowHelp(std::string& result);
void ShowIllegalInfomation(std::string& result);
int Dump(const std::vector<std::u16string>& args, std::string& result);
// multi user
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2024-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -118,6 +118,13 @@ public:
* @return The pair of the dump result and the dump key.
*/
static std::pair<bool, DumpUtils::DumpsysKey> DumpsysMap(std::string argString);
/**
* ShowHelp, display help information for dump tool.
*
* @param result The result string to be filled with help information.
*/
static void ShowHelp(std::string& result);
};
} // namespace AAFwk
} // namespace OHOS
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2025 Huawei Device Co., Ltd.
* Copyright (c) 2023-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -179,7 +179,7 @@ namespace {
constexpr const char* ARGS_USER_ID = "-u";
constexpr const char* ARGS_CLIENT = "-c";
constexpr const char* ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help.";
constexpr const char* ILLEGAL_INFORMATION = "The arguments are illegal and you can enter '-h' for help.";
constexpr int32_t NEW_RULE_VALUE_SIZE = 6;
constexpr int32_t APP_ALIVE_TIME_MS = 1000; // Allow background startup within 1 second after application startup
@@ -11166,7 +11166,7 @@ int AbilityManagerService::Dump(const std::vector<std::u16string>& args, std::st
ErrCode errCode = ERR_OK;
auto size = args.size();
if (size == 0) {
ShowHelp(result);
DumpUtils::ShowHelp(result);
return errCode;
}
@@ -11176,11 +11176,11 @@ int AbilityManagerService::Dump(const std::vector<std::u16string>& args, std::st
}
if (argsStr[0] == "-h") {
ShowHelp(result);
DumpUtils::ShowHelp(result);
} else {
errCode = ProcessMultiParam(argsStr, result);
if (errCode == ERR_AAFWK_HIDUMP_INVALID_ARGS) {
ShowIllegalInfomation(result);
result.append(ILLEGAL_INFORMATION);
}
}
return errCode;
@@ -11234,32 +11234,6 @@ ErrCode AbilityManagerService::ProcessMultiParam(std::vector<std::string>& argsS
return ERR_OK;
}
void AbilityManagerService::ShowHelp(std::string& result)
{
result.append("Usage:\n")
.append("-h ")
.append("help text for the tool\n")
.append("-a [-c | -u {UserId}] ")
.append("dump all ability infomation in the system or all ability infomation of client/UserId\n")
.append("-l ")
.append("dump all mission list information in the system\n")
.append("-i {AbilityRecordId} ")
.append("dump an ability infomation by ability record id\n")
.append("-e ")
.append("dump all extension infomation in the system(FA: ServiceAbilityRecords, Stage: ExtensionRecords)\n")
.append("-p [PendingWantRecordId] ")
.append("dump all pendingwant record infomation in the system\n")
.append("-r ")
.append("dump all process in the system\n")
.append("-d ")
.append("dump all data ability infomation in the system");
}
void AbilityManagerService::ShowIllegalInfomation(std::string& result)
{
result.append(ILLEGAL_INFOMATION);
}
int AbilityManagerService::DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "dumpAbilityInfoDone begin");
+22 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2024-2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -112,5 +112,26 @@ std::pair<bool, DumpUtils::DumpsysKey> DumpUtils::DumpsysMap(std::string argStri
}
return result;
}
void DumpUtils::ShowHelp(std::string& result)
{
result.append("Usage:\n")
.append("-h ")
.append("help text for the tool\n")
.append("-a [-c | -u {UserId}] ")
.append("dump all ability information in the system or all ability information of client/UserId\n")
.append("-l ")
.append("dump all mission list information in the system\n")
.append("-i {AbilityRecordId} ")
.append("dump an ability information by ability record id\n")
.append("-e ")
.append("dump all extension information in the system(FA: ServiceAbilityRecords, Stage: ExtensionRecords)\n")
.append("-p [PendingWantRecordId] ")
.append("dump all pendingwant record information in the system\n")
.append("-r ")
.append("dump all process in the system\n")
.append("-d ")
.append("dump all data ability information in the system");
}
} // namespace AAFwk
} // namespace OHOS
@@ -76,8 +76,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
abilityms->Dump(intParam, args);
abilityms->Dump(args, stringParam);
abilityms->ProcessMultiParam(info, stringParam);
abilityms->ShowHelp(stringParam);
abilityms->ShowIllegalInfomation(stringParam);
abilityms->DumpAbilityInfoDone(info, token);
abilityms->SetMissionLabel(token, stringParam);
std::shared_ptr<OHOS::Media::PixelMap> icon;
@@ -311,5 +311,56 @@ HWTEST_F(DumpUtilsTest, DumpMap_003, TestSize.Level1)
EXPECT_FALSE(result.first);
TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest DumpMap_003 end");
}
/*
* Feature: DumpUtils
* Function: ShowHelp
* SubFunction: NA
* FunctionPoints: DumpUtils ShowHelp
*/
HWTEST_F(DumpUtilsTest, ShowHelp_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_001 start");
std::string result;
DumpUtils::ShowHelp(result);
// Check that help text contains expected content
EXPECT_FALSE(result.empty());
EXPECT_NE(result.find("Usage:"), std::string::npos);
EXPECT_NE(result.find("-h"), std::string::npos);
EXPECT_NE(result.find("help text for the tool"), std::string::npos);
EXPECT_NE(result.find("-a"), std::string::npos);
EXPECT_NE(result.find("-l"), std::string::npos);
EXPECT_NE(result.find("-i"), std::string::npos);
EXPECT_NE(result.find("-e"), std::string::npos);
EXPECT_NE(result.find("-p"), std::string::npos);
EXPECT_NE(result.find("-r"), std::string::npos);
EXPECT_NE(result.find("-d"), std::string::npos);
// Verify that "information" is spelled correctly (not "infomation")
EXPECT_EQ(result.find("infomation"), std::string::npos);
EXPECT_NE(result.find("information"), std::string::npos);
TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_001 end");
}
/*
* Feature: DumpUtils
* Function: ShowHelp
* SubFunction: NA
* FunctionPoints: DumpUtils ShowHelp
*/
HWTEST_F(DumpUtilsTest, ShowHelp_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_002 start");
std::string result = "Initial content\n";
DumpUtils::ShowHelp(result);
// Check that help text is appended to existing content
EXPECT_NE(result.find("Initial content"), std::string::npos);
EXPECT_NE(result.find("Usage:"), std::string::npos);
TAG_LOGI(AAFwkTag::TEST, "DumpUtilsTest ShowHelp_002 end");
}
} // namespace AAFwk
} // namespace OHOS