Skip to content

Commit 8c3e6c8

Browse files
author
Daniel Shaulov
committed
perf: Use exec_comm instead of comm when printing
Process names are much clearer as the first line in a flamegraph If we ever want to upstream this, it needs to be a separate option
1 parent c800a56 commit 8c3e6c8

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

tools/perf/builtin-script.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,11 @@ static int perf_sample__fprintf_start(struct perf_sample *sample,
635635

636636
if (PRINT_FIELD(COMM)) {
637637
if (latency_format)
638-
printed += fprintf(fp, "%8.8s ", thread__comm_str(thread));
638+
printed += fprintf(fp, "%8.8s ", thread__exec_comm_str(thread));
639639
else if (PRINT_FIELD(IP) && evsel__has_callchain(evsel) && symbol_conf.use_callchain)
640-
printed += fprintf(fp, "%s ", thread__comm_str(thread));
640+
printed += fprintf(fp, "%s ", thread__exec_comm_str(thread));
641641
else
642-
printed += fprintf(fp, "%16s ", thread__comm_str(thread));
642+
printed += fprintf(fp, "%16s ", thread__exec_comm_str(thread));
643643
}
644644

645645
if (PRINT_FIELD(PID) && PRINT_FIELD(TID))

tools/perf/util/thread.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,27 @@ const char *thread__comm_str(struct thread *thread)
308308
return str;
309309
}
310310

311+
static const char *__thread__exec_comm_str(const struct thread *thread)
312+
{
313+
const struct comm *comm = thread__exec_comm(thread);
314+
315+
if (!comm)
316+
return NULL;
317+
318+
return comm__str(comm);
319+
}
320+
321+
const char *thread__exec_comm_str(struct thread *thread)
322+
{
323+
const char *str;
324+
325+
down_read(&thread->comm_lock);
326+
str = __thread__exec_comm_str(thread);
327+
up_read(&thread->comm_lock);
328+
329+
return str;
330+
}
331+
311332
/* CHECKME: it should probably better return the max comm len from its comm list */
312333
int thread__comm_len(struct thread *thread)
313334
{

tools/perf/util/thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int thread__comm_len(struct thread *thread);
9090
struct comm *thread__comm(const struct thread *thread);
9191
struct comm *thread__exec_comm(const struct thread *thread);
9292
const char *thread__comm_str(struct thread *thread);
93+
const char *thread__exec_comm_str(struct thread *thread);
9394
int thread__insert_map(struct thread *thread, struct map *map);
9495
int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp, bool do_maps_clone);
9596
size_t thread__fprintf(struct thread *thread, FILE *fp);

0 commit comments

Comments
 (0)