aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/thread.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-04-26 11:32:50 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-26 12:15:00 -0400
commit2f3027ac28bf6bc3ac7eb851eab06f2a38af5caa (patch)
treebc2b421ada54138ea0da15e5c035fb1f82d76487 /tools/perf/util/thread.c
parent4bd112df3eea4db63fe90fb4e83c48d3f3bd6512 (diff)
perf thread: Introduce method to set comm from /proc/pid/self
Will be used for lazy comm loading in 'perf trace'. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Milian Wolff <milian.wolff@kdab.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-7ogbkuoka1y2qsmcckqxvl5m@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/thread.c')
-rw-r--r--tools/perf/util/thread.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index de2036d1251b..45fcb715a36b 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -10,6 +10,8 @@
10#include "comm.h" 10#include "comm.h"
11#include "unwind.h" 11#include "unwind.h"
12 12
13#include <api/fs/fs.h>
14
13int thread__init_map_groups(struct thread *thread, struct machine *machine) 15int thread__init_map_groups(struct thread *thread, struct machine *machine)
14{ 16{
15 struct thread *leader; 17 struct thread *leader;
@@ -153,6 +155,23 @@ int __thread__set_comm(struct thread *thread, const char *str, u64 timestamp,
153 return 0; 155 return 0;
154} 156}
155 157
158int thread__set_comm_from_proc(struct thread *thread)
159{
160 char path[64];
161 char *comm = NULL;
162 size_t sz;
163 int err = -1;
164
165 if (!(snprintf(path, sizeof(path), "%d/task/%d/comm",
166 thread->pid_, thread->tid) >= (int)sizeof(path)) &&
167 procfs__read_str(path, &comm, &sz) == 0) {
168 comm[sz - 1] = '\0';
169 err = thread__set_comm(thread, comm, 0);
170 }
171
172 return err;
173}
174
156const char *thread__comm_str(const struct thread *thread) 175const char *thread__comm_str(const struct thread *thread)
157{ 176{
158 const struct comm *comm = thread__comm(thread); 177 const struct comm *comm = thread__comm(thread);