From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbbERAtb (ORCPT ); Sun, 17 May 2015 20:49:31 -0400 Received: from LGEMRELSE6Q.lge.com ([156.147.1.121]:54720 "EHLO lgemrelse6q.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752086AbbERAlN (ORCPT ); Sun, 17 May 2015 20:41:13 -0400 X-Original-SENDERIP: 10.177.220.203 X-Original-MAILFROM: namhyung@kernel.org From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , David Ahern , Adrian Hunter , Andi Kleen , Frederic Weisbecker , Stephane Eranian Subject: [PATCH 10/40] perf tools: Introduce thread__comm(_str)_by_time() helpers Date: Mon, 18 May 2015 09:30:25 +0900 Message-Id: <1431909055-21442-11-git-send-email-namhyung@kernel.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: <1431909055-21442-1-git-send-email-namhyung@kernel.org> References: <1431909055-21442-1-git-send-email-namhyung@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When data file indexing is enabled, it processes all task, comm and mmap events first and then goes to the sample events. So all it sees is the last comm of a thread although it has information at the time of sample. Sort thread's comm by time so that it can find appropriate comm at the sample time. The thread__comm_by_time() will mostly work even if PERF_SAMPLE_TIME bit is off since in that case, sample->time will be -1 so it'll take the last comm anyway. Cc: Frederic Weisbecker Signed-off-by: Namhyung Kim --- tools/perf/util/thread.c | 33 ++++++++++++++++++++++++++++++++- tools/perf/util/thread.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 16c28a37a9e4..962558024415 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -123,6 +123,21 @@ struct comm *thread__exec_comm(const struct thread *thread) return last; } +struct comm *thread__comm_by_time(const struct thread *thread, u64 timestamp) +{ + struct comm *comm; + + list_for_each_entry(comm, &thread->comm_list, list) { + if (timestamp >= comm->start) + return comm; + } + + if (list_empty(&thread->comm_list)) + return NULL; + + return list_last_entry(&thread->comm_list, struct comm, list); +} + int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, bool exec) { @@ -138,7 +153,13 @@ int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, new = comm__new(str, timestamp, exec); if (!new) return -ENOMEM; - list_add(&new->list, &thread->comm_list); + + /* sort by time */ + list_for_each_entry(curr, &thread->comm_list, list) { + if (timestamp >= curr->start) + break; + } + list_add_tail(&new->list, &curr->list); if (exec) unwind__flush_access(thread); @@ -159,6 +180,16 @@ const char *thread__comm_str(const struct thread *thread) return comm__str(comm); } +const char *thread__comm_str_by_time(const struct thread *thread, u64 timestamp) +{ + const struct comm *comm = thread__comm_by_time(thread, timestamp); + + if (!comm) + return NULL; + + return comm__str(comm); +} + /* CHECKME: it should probably better return the max comm len from its comm list */ int thread__comm_len(struct thread *thread) { diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index f33c48cfdaa0..903cfaf2628d 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -68,7 +68,9 @@ static inline int thread__set_comm(struct thread *thread, const char *comm, int thread__comm_len(struct thread *thread); struct comm *thread__comm(const struct thread *thread); struct comm *thread__exec_comm(const struct thread *thread); +struct comm *thread__comm_by_time(const struct thread *thread, u64 timestamp); const char *thread__comm_str(const struct thread *thread); +const char *thread__comm_str_by_time(const struct thread *thread, u64 timestamp); void thread__insert_map(struct thread *thread, struct map *map); int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp); size_t thread__fprintf(struct thread *thread, FILE *fp); -- 2.4.0