From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753671AbcD0PiA (ORCPT ); Wed, 27 Apr 2016 11:38:00 -0400 Received: from terminus.zytor.com ([198.137.202.10]:51350 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753419AbcD0Ph5 (ORCPT ); Wed, 27 Apr 2016 11:37:57 -0400 Date: Wed, 27 Apr 2016 08:37:31 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: tglx@linutronix.de, milian.wolff@kdab.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, wangnan0@huawei.com, jolsa@kernel.org, dsahern@gmail.com, acme@redhat.com, mingo@kernel.org, hpa@zytor.com, bp@suse.de, namhyung@kernel.org Reply-To: tglx@linutronix.de, milian.wolff@kdab.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, wangnan0@huawei.com, dsahern@gmail.com, acme@redhat.com, jolsa@kernel.org, mingo@kernel.org, hpa@zytor.com, bp@suse.de, namhyung@kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf thread: Introduce method to set comm from /proc/pid/self Git-Commit-ID: 2f3027ac28bf6bc3ac7eb851eab06f2a38af5caa X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 2f3027ac28bf6bc3ac7eb851eab06f2a38af5caa Gitweb: http://git.kernel.org/tip/2f3027ac28bf6bc3ac7eb851eab06f2a38af5caa Author: Arnaldo Carvalho de Melo AuthorDate: Tue, 26 Apr 2016 12:32:50 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 26 Apr 2016 13:15:00 -0300 perf thread: Introduce method to set comm from /proc/pid/self Will be used for lazy comm loading in 'perf trace'. Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Jiri Olsa Cc: Milian Wolff Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-7ogbkuoka1y2qsmcckqxvl5m@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread.c | 19 +++++++++++++++++++ tools/perf/util/thread.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index de2036d..45fcb71 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -10,6 +10,8 @@ #include "comm.h" #include "unwind.h" +#include + int thread__init_map_groups(struct thread *thread, struct machine *machine) { struct thread *leader; @@ -153,6 +155,23 @@ int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp, return 0; } +int thread__set_comm_from_proc(struct thread *thread) +{ + char path[64]; + char *comm = NULL; + size_t sz; + int err = -1; + + if (!(snprintf(path, sizeof(path), "%d/task/%d/comm", + thread->pid_, thread->tid) >= (int)sizeof(path)) && + procfs__read_str(path, &comm, &sz) == 0) { + comm[sz - 1] = '\0'; + err = thread__set_comm(thread, comm, 0); + } + + return err; +} + const char *thread__comm_str(const struct thread *thread) { const struct comm *comm = thread__comm(thread); diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index e214207..45fba13 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -71,6 +71,8 @@ static inline int thread__set_comm(struct thread *thread, const char *comm, return __thread__set_comm(thread, comm, timestamp, false); } +int thread__set_comm_from_proc(struct thread *thread); + int thread__comm_len(struct thread *thread); struct comm *thread__comm(const struct thread *thread); struct comm *thread__exec_comm(const struct thread *thread);