Adapt hm server pid for callchain useronly

Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
This commit is contained in:
Chen Zhongjin 2024-01-10 19:07:40 +08:00
parent 5ec63a7d49
commit f1ea60628c
4 changed files with 25 additions and 13 deletions

View File

@ -236,6 +236,7 @@ public:
PerfRecordSampleData data_ = {};
uint64_t sampleType_ = SAMPLE_TYPE;
uint64_t skipKernel_ = 0;
uint64_t skipPid_ = 0;
// extend
// hold the new ips memory (after unwind)
// used for data_.ips replace (ReplaceWithCallStack)

View File

@ -398,7 +398,8 @@ bool PerfRecordSample::GetBinary(std::vector<uint8_t> &buf) const
}
PushToBinary(sampleType_ & PERF_SAMPLE_SERVER_PID, p, data_.server_nr);
if (data_.server_nr > 0) {
std::copy(data_.server_pids, data_.server_pids + data_.server_nr, reinterpret_cast<u64 *>(p));
std::copy(data_.server_pids + skipPid_, data_.server_pids + data_.server_nr + skipPid_,
reinterpret_cast<u64 *>(p));
p += data_.server_nr * sizeof(u64);
}
PushToBinary(sampleType_ & PERF_SAMPLE_STACK_USER, p, data_.stack_size);
@ -989,6 +990,10 @@ void PerfRecordSwitchCpuWide::DumpData(int indent) const
pid_t PerfRecordSample::GetUstackServerPid()
{
if (!data_.server_nr) {
return data_.pid;
}
size_t curr_server = 0;
// ip_nr == 1...nr: server_pid of data_.ips[nr]
for (size_t i = 1; i < data_.nr; i++) {
@ -998,7 +1003,9 @@ pid_t PerfRecordSample::GetUstackServerPid()
}
}
// ip_nr == nr + 1: server_pid of ustack
curr_server++;
if (curr_server > 0) {
curr_server++;
}
if (curr_server >= data_.server_nr) {
HLOGE("ustack server pid nr %zu out of range", curr_server);
return data_.pid;
@ -1031,15 +1038,6 @@ pid_t PerfRecordSample::GetServerPidof(unsigned int ip_nr)
}
serverPidMap_.emplace_back(data_.server_pids[curr_server]);
}
// ip_nr == nr + 1: server_pid of ustack
curr_server++;
if (data_.stack_size) {
if (curr_server >= data_.server_nr) {
HLOGE("ustack server pid nr %zu out of range", curr_server);
} else {
serverPidMap_.emplace_back(data_.server_pids[curr_server]);
}
}
}
// return server pid

View File

@ -867,10 +867,12 @@ bool SubCommandRecord::PrepareVirtualRuntime()
virtualRuntime_.SetNeedKernelCallChain(!callChainUserOnly_);
virtualRuntime_.UpdateKernelSpaceMaps();
virtualRuntime_.UpdateKernelModulesSpaceMaps();
if (isHM_) {
virtualRuntime_.UpdateServiceSpaceMaps();
}
}
if (isHM_) {
virtualRuntime_.UpdateServiceSpaceMaps();
virtualRuntime_.UpdateDevhostSpaceMaps();
}
if (dedupStack_) {
@ -1640,9 +1642,11 @@ bool SubCommandRecord::FinishWriteRecordFile()
if (!callChainUserOnly_) {
virtualRuntime_.UpdateKernelSymbols();
virtualRuntime_.UpdateKernelModulesSymbols();
if (isHM_) {
virtualRuntime_.UpdateServiceSymbols();
}
}
if (isHM_) {
virtualRuntime_.UpdateServiceSymbols();
virtualRuntime_.UpdateDevhostSymbols();
}
#endif

View File

@ -521,8 +521,12 @@ void VirtualRuntime::NeedDropKernelCallChain(PerfRecordSample &sample)
}
u64 skip = 0;
u64 skip_pid = 0;
u64 *ips = sample.data_.ips;
for (; skip < sample.data_.nr; skip++) {
if (ips[skip] == PERF_CONTEXT_KERNEL) {
skip_pid++;
}
if (ips[skip] == PERF_CONTEXT_USER) {
break;
}
@ -530,6 +534,11 @@ void VirtualRuntime::NeedDropKernelCallChain(PerfRecordSample &sample)
sample.skipKernel_ = skip;
sample.data_.nr -= skip;
sample.header.size -= sizeof(u64) * skip;
if (sample.data_.server_nr > 0) {
sample.skipPid_ = skip_pid;
sample.data_.server_nr -= skip_pid;
sample.header.size -= sizeof(u64) * skip_pid;
}
}
void VirtualRuntime::UnwindFromRecord(PerfRecordSample &recordSample)