libkperf/0012-UT-SpeProcCollectSubProc.patch

45 lines
1.7 KiB
Diff
Raw Normal View History

From 065ba5f7493b1d27fd5320c99b597e2d96fb3396 Mon Sep 17 00:00:00 2001
From: glx <ganli2012@gmail.com>
Date: Tue, 29 Oct 2024 11:25:00 +0800
Subject: [PATCH 12/20] =?UTF-8?q?=E4=BF=AE=E5=A4=8DUT=E7=94=A8=E4=BE=8BSpe?=
=?UTF-8?q?ProcCollectSubProc=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
问题:
UT用例SpeProcCollectSubProc报错。
原因:
用例SpeProcCollectSubProc执行过程启动应用开始采集应用fork进程校验子进程是否被采集到。
子进程未被采集到因为UpdateProcMap函数里未找到子进程的父进程所以子进程没有被添加到procMap。
解决方法:
对于fork子进程的场景父进程应该是ppid而不是pid可以把ppid传入到UpdateProcMap。
---
pmu/spe.cpp | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/pmu/spe.cpp b/pmu/spe.cpp
index 99b7a89..4d964fb 100644
--- a/pmu/spe.cpp
+++ b/pmu/spe.cpp
@@ -372,7 +372,13 @@ void Spe::CoreDummyData(struct SpeCoreContext *context, struct ContextSwitchData
if (header->type == PERF_RECORD_FORK) {
struct PerfRecordFork *sample = (struct PerfRecordFork *)header;
DBG_PRINT("Fork pid: %d tid: %d\n", sample->pid, sample->tid);
- UpdateProcMap(sample->pid, sample->tid);
+ if (sample->pid == sample->tid) {
+ // A new process is forked and the parent pid is ppid.
+ UpdateProcMap(sample->ppid, sample->tid);
+ } else {
+ // A new thread is created and the parent pid is pid(process id).
+ UpdateProcMap(sample->pid, sample->tid);
+ }
dataTail += header->size;
continue;
}
--
2.43.0