Re: [PATCH v1 8/9] perf stat: Remove --per-thread pid/tid limitation

From: Jin, Yao
Date: Wed Nov 22 2017 - 00:39:04 EST




On 11/21/2017 11:18 PM, Jiri Olsa wrote:
On Mon, Nov 20, 2017 at 10:43:43PM +0800, Jin Yao wrote:
Currently, if we execute 'perf stat --per-thread' without specifying
pid/tid, perf will return error.

root@skl:/tmp# perf stat --per-thread
The --per-thread option is only available when monitoring via -p -t options.
-p, --pid <pid> stat events on existing process id
-t, --tid <tid> stat events on existing thread id

This patch removes this limitation. If no pid/tid specified, it returns
all threads (get threads from /proc).

Signed-off-by: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
---
tools/perf/builtin-stat.c | 23 +++++++++++++++--------
tools/perf/util/target.h | 7 +++++++
2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9eec145..2d718f7 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -277,7 +277,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
attr->enable_on_exec = 1;
}
- if (target__has_cpu(&target))
+ if (target__has_cpu(&target) && !target__has_per_thread(&target))

please add comment on why this is needed..

return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
return perf_evsel__open_per_thread(evsel, evsel_list->threads);
@@ -340,7 +340,7 @@ static int read_counter(struct perf_evsel *counter)
int nthreads = thread_map__nr(evsel_list->threads);
int ncpus, cpu, thread;
- if (target__has_cpu(&target))
+ if (target__has_cpu(&target) && !target__has_per_thread(&target))

same here


That's because this patch series doesn't support cpu_list yet. So if it's a cpu_list case, then skip.

I plan to add cpu_list supporting as follow-up patch to avoid adding too much in this patch series.

Thanks
Jin Yao

thanks,
jirka