!566 hiperf采集过滤非debug应用

Merge pull request !566 from yuyanqing/master
This commit is contained in:
openharmony_ci 2024-08-24 13:02:51 +00:00 committed by Gitee
commit 25663337ab
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 70 additions and 0 deletions

View File

@ -203,6 +203,7 @@ ohos_source_set("hiperf_platform_common") {
"faultloggerd:libunwinder_static",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
"samgr:samgr_proxy",
]
if (bundle_framework_enable) {

View File

@ -22,6 +22,7 @@
"hilog",
"napi",
"samgr",
"ipc",
"c_utils",
"bundle_framework",
"faultloggerd",

View File

@ -334,6 +334,9 @@ pid_t GetAppPackagePid(const std::string &appPackage, const pid_t oldPid, const
bool IsRestarted(const std::string &appPackage);
void CollectPidsByAppname(std::set<pid_t> &pids, const std::string &appPackage);
bool CheckAppIsRunning (std::vector<pid_t> &selectPids, const std::string &appPackage, int checkAppMs);
bool IsExistDebugByApp(const std::string& bundleName);
bool IsExistDebugByPid(const std::vector<pid_t> pids);
bool IsDebugableApp(const std::string& bundleName);
bool IsSupportNonDebuggableApp();
const std::string GetUserType();
bool IsArkJsFile(const std::string& filepath);

View File

@ -257,6 +257,9 @@ bool SubCommandRecord::GetOptions(std::vector<std::string> &args)
if (!Option::GetOptionValue(args, "--app", appPackage_)) {
return false;
}
if (!IsExistDebugByApp(appPackage_)) {
return false;
}
if (!Option::GetOptionValue(args, "--chkms", checkAppMs_)) {
return false;
}
@ -269,6 +272,9 @@ bool SubCommandRecord::GetOptions(std::vector<std::string> &args)
if (!Option::GetOptionValue(args, "-p", selectPids_)) {
return false;
}
if (!IsExistDebugByPid(selectPids_)) {
return false;
}
if (!Option::GetOptionValue(args, "-t", selectTids_)) {
return false;
}

View File

@ -99,6 +99,9 @@ bool SubCommandStat::ParseOption(std::vector<std::string> &args)
HLOGD("get option --app failed");
return false;
}
if (!IsExistDebugByApp(appPackage_)) {
return false;
}
if (!Option::GetOptionValue(args, "--chkms", checkAppMs_)) {
return false;
}
@ -106,6 +109,9 @@ bool SubCommandStat::ParseOption(std::vector<std::string> &args)
HLOGD("get option -p failed");
return false;
}
if (!IsExistDebugByPid(selectPids_)) {
return false;
}
if (!Option::GetOptionValue(args, "-t", selectTids_)) {
HLOGD("get option -t failed");
return false;

View File

@ -25,6 +25,16 @@
#endif
#include "hiperf_hilog.h"
#if defined(is_ohos) && is_ohos && defined(BUNDLE_FRAMEWORK_ENABLE)
#include "application_info.h"
#include "bundle_mgr_proxy.h"
#endif
#if defined(is_ohos) && is_ohos
#include "iservice_registry.h"
#include "system_ability_definition.h"
using namespace OHOS;
using namespace OHOS::AppExecFwk;
#endif
using namespace std::chrono;
namespace OHOS {
@ -650,6 +660,49 @@ bool CheckAppIsRunning (std::vector<pid_t> &selectPids, const std::string &appPa
return true;
}
bool IsExistDebugByApp(const std::string& bundleName)
{
if (!IsSupportNonDebuggableApp() && !bundleName.empty() && !IsDebugableApp(bundleName)) {
HLOGE("--app option only support debug aplication.");
printf("--app option only support debug aplication\n");
return false;
}
return true;
}
bool IsExistDebugByPid(const std::vector<pid_t> pids)
{
CHECK_TRUE(pids.empty(), true, 1, "IsExistDebugByPid: pids is empty.");
for (auto pid : pids) {
CHECK_TRUE(pid <= 0, false, LOG_TYPE_PRINTF, "Invalid -p value '%d', the pid should be larger than 0\n", pid);
std::string bundleName = GetProcessName(pid);
if (!IsSupportNonDebuggableApp() && !IsDebugableApp(bundleName)) {
HLOGE("-p option only support debug aplication for %s", bundleName.c_str());
printf("-p option only support debug aplication\n");
return false;
}
}
return true;
}
bool IsDebugableApp(const std::string& bundleName)
{
#if defined(is_ohos) && is_ohos && defined(BUNDLE_FRAMEWORK_ENABLE)
CHECK_TRUE(bundleName.empty(), false, LOG_TYPE_PRINTF, "bundleName is empty!\n");
sptr<ISystemAbilityManager> sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
CHECK_TRUE(sam == nullptr, false, LOG_TYPE_PRINTF, "GetSystemAbilityManager failed!\n");
sptr<IRemoteObject> remoteObject = sam->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
CHECK_TRUE(remoteObject == nullptr, false, LOG_TYPE_PRINTF, "Get BundleMgr SA failed!\n");
sptr<BundleMgrProxy> proxy = iface_cast<BundleMgrProxy>(remoteObject);
CHECK_TRUE(proxy == nullptr, false, LOG_TYPE_PRINTF, "iface_cast failed!\n");
int uid = proxy->GetUidByDebugBundleName(bundleName, Constants::ANY_USERID);
CHECK_TRUE(uid < 0, false, 1, "Get application info failed, bundleName:%s, uid is %d.", bundleName.c_str(), uid);
return true;
#else
return false;
#endif
}
bool IsSupportNonDebuggableApp()
{
// root first