Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13549592pxu; Sun, 3 Jan 2021 19:50:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwZlWzR0X4VUWJEgYnhE2Tt946t7CrLuDMpX52u3J6U8znZcG3wd1jCIzkdtCEIrqCDGh6 X-Received: by 2002:aa7:c151:: with SMTP id r17mr67932639edp.106.1609732213996; Sun, 03 Jan 2021 19:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609732213; cv=none; d=google.com; s=arc-20160816; b=dvUHGOI71G+ybJE9EZt7HeR4F4nrZs/ThIdaQVVSREqya6y/RAe8Uhtej1wnwRauE7 /U22muWowENrcLXza71cfw/mSPBIlNtOxtW5RN5tYfKuxqq4wl714outAlLZBAAxKQ4Q LtnRipg14QQ2mN/acGZiUa9qB8S/UmSSKVnZPJQ01hwbnQWW+P63GHXLVBEx8PSuu9Ac NWRsWdupdPI/nw3I/82qZNgcH7U3IEhcpRzRUrtYj2gCqXfKRmyajurXc+DJhcymwTv6 TYP6Q/9CP1TPhepGmCBWQbo3MB8sCGkynNnRcbHoH1A997h2NhAS+xOGv2a1fpot4sNE u2jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=SzerivFJhBvXyzBnf8saZyqWAn+4hqthQ7n6mPHHlTo=; b=qO2EnMJnJ/RD95XSLW49XA6mYdSTi0gGcSZR2xThRQukzy2nbhH/4cSJi3kksTbtAb mNJtaL5m5hRXN6kp63uzUHVOUW85nsYB04/WwBWBdp5i7QwTgtZMdSI2fDCFWKNkW2LH gJ47hPMHVrRL5P/CK/Ydrw9eeUaUrknf8o09GArXoSuPYlhqGpEol9OoeG0+WOaJTI0/ etQoG5VetJnkettbS5TCbGbtmdv5oCx/ahnTuhP7zqQM9zb1IMkdBrw3JKTPQpTMg8E5 DQQ3gmp47V+Krs+gmIrmqu+BOlsHbQY74FjRXvTBDPFbhl7WuI/5w7WD8CEdcHMBPA37 e5MQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u22si30260369edx.500.2021.01.03.19.49.51; Sun, 03 Jan 2021 19:50:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727885AbhADCVf (ORCPT + 99 others); Sun, 3 Jan 2021 21:21:35 -0500 Received: from mga18.intel.com ([134.134.136.126]:44472 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727670AbhADCVf (ORCPT ); Sun, 3 Jan 2021 21:21:35 -0500 IronPort-SDR: k1plfpJwNzWU4ZNzzs6oL2EAtBbHeKujvmdr8ZQI1Re6IpxKTJB8jcnH6d9LmTT0CQAgQoZDbH LAmuEzA4zMcg== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="164606408" X-IronPort-AV: E=Sophos;i="5.78,472,1599548400"; d="scan'208";a="164606408" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2021 18:19:49 -0800 IronPort-SDR: DKOgNdj9NVI6OnSLf5n/e2xLntJZbSdMUSt9fIdzKVwh7Oc58gUeA9FqzapR0MtXuUC7g6JnwP uMCU+LY99ivQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,472,1599548400"; d="scan'208";a="461783425" Received: from kbl-ppc.sh.intel.com ([10.239.159.163]) by fmsmga001.fm.intel.com with ESMTP; 03 Jan 2021 18:19:46 -0800 From: Jin Yao 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 Subject: [PATCH v2] perf stat: Append to default list if use -e +event Date: Mon, 4 Jan 2021 10:18:37 +0800 Message-Id: <20210104021837.30473-1-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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