Blob Blame History Raw
From ad56e8a5a722df2ac2a5b3ea0822fd78f9a6fe51 Mon Sep 17 00:00:00 2001
From: Nick-nizhen <74173686+Nick-nizhen@users.noreply.github.com>
Date: Thu, 27 May 2021 13:21:59 +0800
Subject: [PATCH] Update cpudist.py

When calculating the ONCPU  time, prev has left the CPU already. It is not necessary to judge whether the process state is TASK_RUNNING or not.
---
 tools/cpudist.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/tools/cpudist.py b/tools/cpudist.py
index eb04f590..b5a6a978 100755
--- a/tools/cpudist.py
+++ b/tools/cpudist.py
@@ -100,19 +100,13 @@ int sched_switch(struct pt_regs *ctx, struct task_struct *prev)
     u64 pid_tgid = bpf_get_current_pid_tgid();
     u32 tgid = pid_tgid >> 32, pid = pid_tgid;
 
+    u32 prev_pid = prev->pid;
+    u32 prev_tgid = prev->tgid;
 #ifdef ONCPU
-    if (prev->state == TASK_RUNNING) {
+    update_hist(prev_tgid, prev_pid, ts);
 #else
-    if (1) {
+    store_start(prev_tgid, prev_pid, ts);
 #endif
-        u32 prev_pid = prev->pid;
-        u32 prev_tgid = prev->tgid;
-#ifdef ONCPU
-        update_hist(prev_tgid, prev_pid, ts);
-#else
-        store_start(prev_tgid, prev_pid, ts);
-#endif
-    }
 
 BAIL:
 #ifdef ONCPU
-- 
2.31.1