public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jin Yao <yao.jin@linux.intel.com>
To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org,
	mingo@redhat.com, alexander.shishkin@linux.intel.com
Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com,
	kan.liang@intel.com, yao.jin@intel.com,
	Jin Yao <yao.jin@linux.intel.com>
Subject: [PATCH v2] perf stat: Append to default list if use -e +event
Date: Mon,  4 Jan 2021 10:18:37 +0800	[thread overview]
Message-ID: <20210104021837.30473-1-yao.jin@linux.intel.com> (raw)

The default event list includes the most common events which are widely
used by users. But with -e option, the current perf only counts the events
assigned by -e option. Users may want to collect some extra events with
the default list. For this case, users have to manually add all the events
from the default list. It's inconvenient. Also, users may don't know how to
get the default list.

Now it supports a simple syntax: -e +event

The prefix '+' tells perf to append this event (or event list) to default
event list.

Before:

root@kbl-ppc:~# ./perf stat -e power/energy-pkg/ -a -- sleep 1

 Performance counter stats for 'system wide':

              2.04 Joules power/energy-pkg/

       1.000863884 seconds time elapsed

After:

root@kbl-ppc:~# ./perf stat -e +power/energy-pkg/ -a -- sleep 1

 Performance counter stats for 'system wide':

              2.11 Joules +power/energy-pkg/        #    0.000 K/sec
          8,007.17 msec   cpu-clock                 #    7.993 CPUs utilized
               125        context-switches          #    0.016 K/sec
                 8        cpu-migrations            #    0.001 K/sec
                 2        page-faults               #    0.000 K/sec
         8,520,084        cycles                    #    0.001 GHz
         2,808,302        instructions              #    0.33  insn per cycle
           555,427        branches                  #    0.069 M/sec
            59,005        branch-misses             #   10.62% of all branches

       1.001832003 seconds time elapsed

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
 v2:
   We just use a simple syntax: -e +event to append the -e event
   to default list.

 v1: 
   Create a new option '--add-default' to append -e event to
   default list.

 tools/perf/Documentation/perf-stat.txt |  1 +
 tools/perf/builtin-stat.c              |  3 ++-
 tools/perf/util/evlist.c               | 10 ++++++++++
 tools/perf/util/evlist.h               |  1 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 5d4a673d7621..f60af902b8e1 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -63,6 +63,7 @@ report::
 	Multiple PMU instances are typical for uncore PMUs, so the prefix
 	'uncore_' is also ignored when performing this match.
 
+	If the prefix '+' is used, the event is appended to default event list.
 
 -i::
 --no-inherit::
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 8cc24967bc27..8400953473ef 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1763,7 +1763,8 @@ static int add_default_attributes(void)
 		free(str);
 	}
 
-	if (!evsel_list->core.nr_entries) {
+	if (!evsel_list->core.nr_entries ||
+	    evlist__append_default_list(evsel_list)) {
 		if (target__has_cpu(&target))
 			default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;
 
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 05363a7247c4..fceef4e57964 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -2010,3 +2010,13 @@ struct evsel *evlist__find_evsel(struct evlist *evlist, int idx)
 	}
 	return NULL;
 }
+
+bool evlist__append_default_list(struct evlist *evlist)
+{
+	struct evsel *first = evlist__first(evlist);
+
+	if (first->name && first->name[0] == '+')
+		return true;
+
+	return false;
+}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 1aae75895dea..54592bd22bc2 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -353,4 +353,5 @@ int evlist__ctlfd_ack(struct evlist *evlist);
 #define EVLIST_DISABLED_MSG "Events disabled\n"
 
 struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
+bool evlist__append_default_list(struct evlist *evlist);
 #endif /* __PERF_EVLIST_H */
-- 
2.17.1


             reply	other threads:[~2021-01-04  2:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04  2:18 Jin Yao [this message]
2021-01-12 10:08 ` [PATCH v2] perf stat: Append to default list if use -e +event Jiri Olsa
2021-01-18  4:54   ` Jin, Yao
2021-01-20 21:25     ` Jiri Olsa
2021-01-21  0:03       ` Arnaldo Carvalho de Melo
2021-01-21  6:08         ` Jin, Yao
2021-01-21 13:02           ` Arnaldo Carvalho de Melo
2021-01-22  1:43             ` Jin, Yao
2021-01-23 23:14             ` Jiri Olsa
2021-01-21  5:05       ` Jin, Yao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210104021837.30473-1-yao.jin@linux.intel.com \
    --to=yao.jin@linux.intel.com \
    --cc=Linux-kernel@vger.kernel.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=yao.jin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox