linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anubhav Shelat <ashelat@redhat.com>
To: mpetlan@redhat.com, acme@kernel.org, namhyung@kernel.org,
	irogers@google.com, linux-perf-users@vger.kernel.org
Cc: peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	adrian.hunter@intel.com, kan.liang@linux.intel.com,
	dapeng1.mi@linux.intel.com, james.clark@linaro.org,
	Anubhav Shelat <ashelat@redhat.com>
Subject: [PATCH] perf sched timehist: decode process names of processes in zombie state
Date: Wed,  9 Jul 2025 10:31:20 -0400	[thread overview]
Message-ID: <20250709143119.91147-2-ashelat@redhat.com> (raw)

Previously when running perf trace timehist --state, when recording
processes in the zombie state the process name would not be decoded
properly and appears with just the PID:

1140057.412177 [0006]  Mutter Input Th[3139/3104]          0.956      0.019      0.041      S
1140057.412222 [0012]  :1248612[1248612]                   0.000      0.000      0.332      Z
1140057.412275 [0004]  <idle>                              0.052      0.052      0.953      I
1140057.412284 [0008]  <idle>                              0.070      0.070      0.932      I
1140057.412333 [0004]  KMS thread[3126/3104]               0.953      0.112      0.058      S

Now some extra processing has been added to decode the process name:

1140057.412177 [0006]  Mutter Input Th[3139/3104]          0.956      0.019      0.041      S
1140057.412222 [0012]  sleep[1248612]                      0.000      0.000      0.332      Z
1140057.412275 [0004]  <idle>                              0.052      0.052      0.953      I
1140057.412284 [0008]  <idle>                              0.070      0.070      0.932      I
1140057.412333 [0004]  KMS thread[3126/3104]               0.953      0.112      0.058      S

Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
---
 tools/perf/builtin-sched.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 26ece6e9bfd1..e1a931341bc8 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2023,11 +2023,15 @@ static int comm_width = 30;
 static char *timehist_get_commstr(struct thread *thread)
 {
 	static char str[32];
-	const char *comm = thread__comm_str(thread);
+	char *comm = (char *) thread__comm_str(thread);
+	char *empty = (char *) "";
 	pid_t tid = thread__tid(thread);
 	pid_t pid = thread__pid(thread);
 	int n;
 
+	if (*comm == ':')
+		comm = empty;
+
 	if (pid == 0)
 		n = scnprintf(str, sizeof(str), "%s", comm);
 
@@ -2147,6 +2151,8 @@ static void timehist_print_sample(struct perf_sched *sched,
 	struct thread_runtime *tr = thread__priv(thread);
 	const char *next_comm = evsel__strval(evsel, sample, "next_comm");
 	const u32 next_pid = evsel__intval(evsel, sample, "next_pid");
+	const char *prev_comm = evsel__strval(evsel, sample, "prev_comm");
+	char *comm_str = timehist_get_commstr(thread);
 	u32 max_cpus = sched->max_cpu.cpu + 1;
 	char tstr[64];
 	char nstr[30];
@@ -2173,8 +2179,15 @@ static void timehist_print_sample(struct perf_sched *sched,
 		}
 		printf(" ");
 	}
-
-	printf(" %-*s ", comm_width, timehist_get_commstr(thread));
+	
+	/* if a process is in zombie state commstr will start with a '[' and 
+	 * we need to do extra processing to decode the process name */
+	if (*comm_str == '[') {
+		printf(" %s", evsel__strval(evsel, sample, "prev_comm"));
+		printf("%-*s ", comm_width - (int) strlen(prev_comm), comm_str);
+	}
+	else
+		printf(" %-*s ", comm_width, comm_str);
 
 	if (sched->show_prio)
 		printf(" %-*s ", MAX_PRIO_STR_LEN, timehist_get_priostr(evsel, thread, sample));
-- 
2.50.0


             reply	other threads:[~2025-07-09 14:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 14:31 Anubhav Shelat [this message]
2025-07-11 20:02 ` [PATCH] perf sched timehist: decode process names of processes in zombie state Namhyung Kim
2025-07-15 15:59   ` Anubhav Shelat
2025-07-16 19:36     ` Namhyung Kim
2025-07-16 20:38       ` Anubhav Shelat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709143119.91147-2-ashelat@redhat.com \
    --to=ashelat@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).