!217 hiperf支持user模式非root模式->不支持-a参数和采集调用栈不包含kernel符号

Merge pull request !217 from 孙帅元/master
This commit is contained in:
openharmony_ci 2023-02-01 06:23:14 +00:00 committed by Gitee
commit e0f2ac90fa
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 18 additions and 1 deletions

View File

@ -146,6 +146,11 @@ bool SubCommandRecord::GetOptions(std::vector<std::string> &args)
if (!Option::GetOptionValue(args, "-a", targetSystemWide_)) {
return false;
}
if (targetSystemWide_ && !IsRoot()) {
HLOGD("-a option needs root privilege for system wide profiling.");
printf("-a option needs root privilege for system wide profiling.\n");
return false;
}
if (!Option::GetOptionValue(args, "--exclude-hiperf", excludeHiperf_)) {
return false;
}

View File

@ -58,6 +58,11 @@ bool SubCommandStat::ParseOption(std::vector<std::string> &args)
HLOGD("get option -a failed");
return false;
}
if (targetSystemWide_ && !IsRoot()) {
HLOGD("-a option needs root privilege for system wide profiling.");
printf("-a option needs root privilege for system wide profiling.\n");
return false;
}
if (!Option::GetOptionValue(args, "-c", selectCpus_)) {
HLOGD("get option -c failed");
return false;

View File

@ -952,6 +952,11 @@ public:
bool hasChangeKptr = false;
std::string oldKptrRestrict = ReadFileToString(KPTR_RESTRICT);
if (oldKptrRestrict.front() != '0') {
if (!IsRoot()) {
HLOGD("user mode do not load kernel syms");
printf("Hiperf is not running as root mode. Do not need load kernel syms\n");
return false;
}
printf("/proc/sys/kernel/kptr_restrict is NOT 0, will try set it to 0.\n");
hasChangeKptr = WriteStringToFile(KPTR_RESTRICT, "0");
if (!hasChangeKptr) {
@ -999,7 +1004,9 @@ public:
if (onRecording_) {
const auto startTime = std::chrono::steady_clock::now();
if (!LoadKernelSyms()) {
printf("parse kalsyms failed.\n");
if (IsRoot()) {
printf("parse kalsyms failed.\n");
}
return false;
} else {
const auto thisTime = std::chrono::steady_clock::now();