[v2,3/4] perf tools: Add printing perf_event_attr type symbol in perf_event_attr__fprintf()
Message ID | 20230511075154.240163-4-yangjihong1@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4197181vqo; Thu, 11 May 2023 01:08:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NaiyyweUsekcjGNkcUMeyG13mMIR1HX0fMOrM/loM676eKhTVPgjyPCR4a8JVBk4he8nP X-Received: by 2002:a17:902:ea0e:b0:1ac:7d8a:35a with SMTP id s14-20020a170902ea0e00b001ac7d8a035amr15916687plg.12.1683792516479; Thu, 11 May 2023 01:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683792516; cv=none; d=google.com; s=arc-20160816; b=dg6fKoA4++7/3azhwcZ1I/HfCeS730+s1W86qemPBGAe901MtF3GBVLB13oVZUDLmd 9pAesYlx1S57P/VsEhoywHG8UIJBDrKogHmTkP0TJfrLvD10azszmMIaJlbJQTaZISxB FsaWd5d5c1Fb8vJzEM0WMdb2e+89G2OVS9K6rFSeG06zIY4MNmBWk/Qgd6xH2bGsrq2N w0LVucE2Od+NihHEol/gCn2wp2b8LyOtdG6JJ5NM5zGkejFeMvpeig8O1PK0KJA8f170 FIfNWSebfMsDxl75UoyM0DplyFCPeJzH+QCES2f7X4Fq/2Z8audys3+9US4NnXMYQs0O vcKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=O9dZyM2YICQBf5sTlrcKlct3HM2bS1o/Cq88m4ckG6Y=; b=WYtUYCBv3cchSmldwYl6v+0dcJ7BXFlRRJjSUUsNk+gPKi9OlDZYdDLGW9PiC6eu12 6kfRfWXr6Fts8kYs8Cm3SxiCm5T+RWaNFTdVlMWvArT6l3fhXV681j3IxVsQwoe0OlB4 nBcBSa2s1MV0Fut3jmrtkVr+9FvKFHBLMSz3SmFTT2vmmOfMY2qRicZk9wQYeU7rKxqJ kWkEKl9rdpD2EsMHG0H4f3MsS4bD9HHzvq+wQnD7z/5MI1CPVmyTeNM8WOXbUn4BTR6/ R5HfqexQl78Aogb1zqh4rDI4/3smNndwzh+zG+UsXY7Wwd7XuvhB3SqNfpGzjDWk8x+p xg1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18-20020a170902ced200b001aca056bdf9si6368898plg.33.2023.05.11.01.08.23; Thu, 11 May 2023 01:08:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbjEKHxq (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Thu, 11 May 2023 03:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237602AbjEKHxd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 11 May 2023 03:53:33 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 985B93AB3; Thu, 11 May 2023 00:53:30 -0700 (PDT) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4QH3tz4zwVz18LQt; Thu, 11 May 2023 15:49:15 +0800 (CST) Received: from localhost.localdomain (10.67.174.95) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 15:53:27 +0800 From: Yang Jihong <yangjihong1@huawei.com> To: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>, <mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>, <jolsa@kernel.org>, <namhyung@kernel.org>, <irogers@google.com>, <adrian.hunter@intel.com>, <anshuman.khandual@arm.com>, <jesussanp@google.com>, <linux-perf-users@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: <yangjihong1@huawei.com> Subject: [PATCH v2 3/4] perf tools: Add printing perf_event_attr type symbol in perf_event_attr__fprintf() Date: Thu, 11 May 2023 07:51:53 +0000 Message-ID: <20230511075154.240163-4-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT In-Reply-To: <20230511075154.240163-1-yangjihong1@huawei.com> References: <20230511075154.240163-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.95] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765584421443243997?= X-GMAIL-MSGID: =?utf-8?q?1765584421443243997?= |
Series |
perf tools: Add printing perf_event_attr `config` and `id` symbol in perf_event_attr__fprintf()
|
|
Commit Message
Yang Jihong
May 11, 2023, 7:51 a.m. UTC
When printing perf_event_attr, always display perf_event_attr type and its symbol
to improve the readability of debugging information.
Before:
# perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true
<SNIP>
------------------------------------------------------------
perf_event_attr:
size 136
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5
------------------------------------------------------------
perf_event_attr:
type 1
size 136
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6
------------------------------------------------------------
perf_event_attr:
type 2
size 136
config 0x143
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER
read_format ID
disabled 1
inherit 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7
------------------------------------------------------------
perf_event_attr:
type 3
size 136
config 0x10005
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9
------------------------------------------------------------
perf_event_attr:
type 4
size 136
config 0x101
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10
------------------------------------------------------------
perf_event_attr:
type 5
size 136
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|CPU|IDENTIFIER
read_format ID
disabled 1
inherit 1
sample_id_all 1
exclude_guest 1
bp_type 3
{ bp_len, config2 } 0x4
------------------------------------------------------------
<SNIP>
After:
# perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true
<SNIP>
------------------------------------------------------------
perf_event_attr:
type 0 (PERF_TYPE_HARDWARE)
size 136
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5
------------------------------------------------------------
perf_event_attr:
type 1 (PERF_TYPE_SOFTWARE)
size 136
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6
------------------------------------------------------------
perf_event_attr:
type 2 (PERF_TYPE_TRACEPOINT)
size 136
config 0x143
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER
read_format ID
disabled 1
inherit 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7
------------------------------------------------------------
perf_event_attr:
type 3 (PERF_TYPE_HW_CACHE)
size 136
config 0x10005
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9
------------------------------------------------------------
perf_event_attr:
type 4 (PERF_TYPE_RAW)
size 136
config 0x101
{ sample_period, sample_freq } 4000
sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER
read_format ID
disabled 1
inherit 1
freq 1
sample_id_all 1
exclude_guest 1
------------------------------------------------------------
sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10
------------------------------------------------------------
perf_event_attr:
type 5 (PERF_TYPE_BREAKPOINT)
size 136
{ sample_period, sample_freq } 1
sample_type IP|TID|TIME|CPU|IDENTIFIER
read_format ID
disabled 1
inherit 1
sample_id_all 1
exclude_guest 1
bp_type 3
{ bp_len, config2 } 0x4
------------------------------------------------------------
<SNIP>
Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
---
tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
Comments
On 11/05/23 10:51, Yang Jihong wrote: > When printing perf_event_attr, always display perf_event_attr type and its symbol > to improve the readability of debugging information. > > Before: > > # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true > <SNIP> > ------------------------------------------------------------ > perf_event_attr: > size 136 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 > ------------------------------------------------------------ > perf_event_attr: > type 1 > size 136 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 > ------------------------------------------------------------ > perf_event_attr: > type 2 > size 136 > config 0x143 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 > ------------------------------------------------------------ > perf_event_attr: > type 3 > size 136 > config 0x10005 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 > ------------------------------------------------------------ > perf_event_attr: > type 4 > size 136 > config 0x101 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 > ------------------------------------------------------------ > perf_event_attr: > type 5 > size 136 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > sample_id_all 1 > exclude_guest 1 > bp_type 3 > { bp_len, config2 } 0x4 > ------------------------------------------------------------ > <SNIP> > > After: > > # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true > <SNIP> > ------------------------------------------------------------ > perf_event_attr: > type 0 (PERF_TYPE_HARDWARE) > size 136 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 > ------------------------------------------------------------ > perf_event_attr: > type 1 (PERF_TYPE_SOFTWARE) > size 136 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 > ------------------------------------------------------------ > perf_event_attr: > type 2 (PERF_TYPE_TRACEPOINT) > size 136 > config 0x143 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 > ------------------------------------------------------------ > perf_event_attr: > type 3 (PERF_TYPE_HW_CACHE) > size 136 > config 0x10005 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 > ------------------------------------------------------------ > perf_event_attr: > type 4 (PERF_TYPE_RAW) > size 136 > config 0x101 > { sample_period, sample_freq } 4000 > sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > freq 1 > sample_id_all 1 > exclude_guest 1 > ------------------------------------------------------------ > sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 > ------------------------------------------------------------ > perf_event_attr: > type 5 (PERF_TYPE_BREAKPOINT) > size 136 > { sample_period, sample_freq } 1 > sample_type IP|TID|TIME|CPU|IDENTIFIER > read_format ID > disabled 1 > inherit 1 > sample_id_all 1 > exclude_guest 1 > bp_type 3 > { bp_len, config2 } 0x4 > ------------------------------------------------------------ > <SNIP> > > Signed-off-by: Yang Jihong <yangjihong1@huawei.com> > --- > tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++- > 1 file changed, 29 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c > index 433029c6afc5..cd0905d8cb7a 100644 > --- a/tools/perf/util/perf_event_attr_fprintf.c > +++ b/tools/perf/util/perf_event_attr_fprintf.c > @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) > __p_bits(buf, size, value, bits); > } > > +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); > +static const char *stringify_perf_type_id(u64 value) > +{ > + /* sync with enum perf_type_id in perf_event.h */ Everything in this file syncs with perf_event.h, so the comment does not seem very useful. > + switch (value) { > + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) > + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) > + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) > + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) > + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) > + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) > + default: > + return NULL; > + } > +} > +#undef ENUM_ID_TO_STR_CASE > + > +static void __p_type_id(char *buf, size_t size, u64 value) > +{ > + const char *str = stringify_perf_type_id(value); > + > + if (str == NULL) > + snprintf(buf, size, "%"PRIu64, value); > + else > + snprintf(buf, size, "%"PRIu64" (%s)", value, str); These 4 lines end up getting used again about 3 times in the next patch, so might as well be a separate function e.g. print_id(buf, size, value, stringify_perf_type_id(value)); where: static void print_id(char *buf, size_t size, u64 value, const char *str) { if (str == NULL) snprintf(buf, size, "%"PRIu64, value); else snprintf(buf, size, "%"PRIu64" (%s)", value, str); } > +} > + > #define BUF_SIZE 1024 > > #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) > @@ -79,6 +106,7 @@ static void __p_read_format(char *buf, size_t size, u64 value) > #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) > #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) > #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) > +#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val) > > #define PRINT_ATTRn(_n, _f, _p, _a) \ > do { \ > @@ -96,7 +124,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, > char buf[BUF_SIZE]; > int ret = 0; > > - PRINT_ATTRf(type, p_unsigned); > + PRINT_ATTRn("type", type, p_type_id, true); > PRINT_ATTRf(size, p_unsigned); > PRINT_ATTRf(config, p_hex); > PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned, false);
Hello, On 2023/5/12 18:34, Adrian Hunter wrote: > On 11/05/23 10:51, Yang Jihong wrote: >> When printing perf_event_attr, always display perf_event_attr type and its symbol >> to improve the readability of debugging information. >> >> Before: >> >> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >> <SNIP> >> ------------------------------------------------------------ >> perf_event_attr: >> size 136 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >> ------------------------------------------------------------ >> perf_event_attr: >> type 1 >> size 136 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >> ------------------------------------------------------------ >> perf_event_attr: >> type 2 >> size 136 >> config 0x143 >> { sample_period, sample_freq } 1 >> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >> ------------------------------------------------------------ >> perf_event_attr: >> type 3 >> size 136 >> config 0x10005 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >> ------------------------------------------------------------ >> perf_event_attr: >> type 4 >> size 136 >> config 0x101 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >> ------------------------------------------------------------ >> perf_event_attr: >> type 5 >> size 136 >> { sample_period, sample_freq } 1 >> sample_type IP|TID|TIME|CPU|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> sample_id_all 1 >> exclude_guest 1 >> bp_type 3 >> { bp_len, config2 } 0x4 >> ------------------------------------------------------------ >> <SNIP> >> >> After: >> >> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >> <SNIP> >> ------------------------------------------------------------ >> perf_event_attr: >> type 0 (PERF_TYPE_HARDWARE) >> size 136 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >> ------------------------------------------------------------ >> perf_event_attr: >> type 1 (PERF_TYPE_SOFTWARE) >> size 136 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >> ------------------------------------------------------------ >> perf_event_attr: >> type 2 (PERF_TYPE_TRACEPOINT) >> size 136 >> config 0x143 >> { sample_period, sample_freq } 1 >> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >> ------------------------------------------------------------ >> perf_event_attr: >> type 3 (PERF_TYPE_HW_CACHE) >> size 136 >> config 0x10005 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >> ------------------------------------------------------------ >> perf_event_attr: >> type 4 (PERF_TYPE_RAW) >> size 136 >> config 0x101 >> { sample_period, sample_freq } 4000 >> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> freq 1 >> sample_id_all 1 >> exclude_guest 1 >> ------------------------------------------------------------ >> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >> ------------------------------------------------------------ >> perf_event_attr: >> type 5 (PERF_TYPE_BREAKPOINT) >> size 136 >> { sample_period, sample_freq } 1 >> sample_type IP|TID|TIME|CPU|IDENTIFIER >> read_format ID >> disabled 1 >> inherit 1 >> sample_id_all 1 >> exclude_guest 1 >> bp_type 3 >> { bp_len, config2 } 0x4 >> ------------------------------------------------------------ >> <SNIP> >> >> Signed-off-by: Yang Jihong <yangjihong1@huawei.com> >> --- >> tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++- >> 1 file changed, 29 insertions(+), 1 deletion(-) >> >> diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c >> index 433029c6afc5..cd0905d8cb7a 100644 >> --- a/tools/perf/util/perf_event_attr_fprintf.c >> +++ b/tools/perf/util/perf_event_attr_fprintf.c >> @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) >> __p_bits(buf, size, value, bits); >> } >> >> +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); >> +static const char *stringify_perf_type_id(u64 value) >> +{ >> + /* sync with enum perf_type_id in perf_event.h */ > > Everything in this file syncs with perf_event.h, so the comment > does not seem very useful. OK, will fix in v3. > >> + switch (value) { >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) >> + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) >> + default: >> + return NULL; >> + } >> +} >> +#undef ENUM_ID_TO_STR_CASE >> + >> +static void __p_type_id(char *buf, size_t size, u64 value) >> +{ >> + const char *str = stringify_perf_type_id(value); >> + >> + if (str == NULL) >> + snprintf(buf, size, "%"PRIu64, value); >> + else >> + snprintf(buf, size, "%"PRIu64" (%s)", value, str); > > These 4 lines end up getting used again about 3 times in the next > patch, so might as well be a separate function e.g. > > print_id(buf, size, value, stringify_perf_type_id(value)); > > where: > > static void print_id(char *buf, size_t size, u64 value, const char *str) > { > if (str == NULL) > snprintf(buf, size, "%"PRIu64, value); > else > snprintf(buf, size, "%"PRIu64" (%s)", value, str); > } > OK, will add print_id() helper in v3. If print_id() helper is also used to print config id, is printed in the decimal format. In the past, it is printed in the hexadecimal format, there may be some changes here. Before: config 0x143 After: config 323 (sched:sched_switch) >> +} >> + >> #define BUF_SIZE 1024 >> >> #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) >> @@ -79,6 +106,7 @@ static void __p_read_format(char *buf, size_t size, u64 value) >> #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) >> #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) >> #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) >> +#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val) >> >> #define PRINT_ATTRn(_n, _f, _p, _a) \ >> do { \ >> @@ -96,7 +124,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, >> char buf[BUF_SIZE]; >> int ret = 0; >> >> - PRINT_ATTRf(type, p_unsigned); >> + PRINT_ATTRn("type", type, p_type_id, true); >> PRINT_ATTRf(size, p_unsigned); >> PRINT_ATTRf(config, p_hex); >> PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned, false); > > . >
On 15/05/23 11:48, Yang Jihong wrote: > Hello, > > On 2023/5/12 18:34, Adrian Hunter wrote: >> On 11/05/23 10:51, Yang Jihong wrote: >>> When printing perf_event_attr, always display perf_event_attr type and its symbol >>> to improve the readability of debugging information. >>> >>> Before: >>> >>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>> <SNIP> >>> ------------------------------------------------------------ >>> perf_event_attr: >>> size 136 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 1 >>> size 136 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 2 >>> size 136 >>> config 0x143 >>> { sample_period, sample_freq } 1 >>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 3 >>> size 136 >>> config 0x10005 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 4 >>> size 136 >>> config 0x101 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 5 >>> size 136 >>> { sample_period, sample_freq } 1 >>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> bp_type 3 >>> { bp_len, config2 } 0x4 >>> ------------------------------------------------------------ >>> <SNIP> >>> >>> After: >>> >>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>> <SNIP> >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 0 (PERF_TYPE_HARDWARE) >>> size 136 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 1 (PERF_TYPE_SOFTWARE) >>> size 136 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 2 (PERF_TYPE_TRACEPOINT) >>> size 136 >>> config 0x143 >>> { sample_period, sample_freq } 1 >>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 3 (PERF_TYPE_HW_CACHE) >>> size 136 >>> config 0x10005 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 4 (PERF_TYPE_RAW) >>> size 136 >>> config 0x101 >>> { sample_period, sample_freq } 4000 >>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> freq 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> ------------------------------------------------------------ >>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>> ------------------------------------------------------------ >>> perf_event_attr: >>> type 5 (PERF_TYPE_BREAKPOINT) >>> size 136 >>> { sample_period, sample_freq } 1 >>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>> read_format ID >>> disabled 1 >>> inherit 1 >>> sample_id_all 1 >>> exclude_guest 1 >>> bp_type 3 >>> { bp_len, config2 } 0x4 >>> ------------------------------------------------------------ >>> <SNIP> >>> >>> Signed-off-by: Yang Jihong <yangjihong1@huawei.com> >>> --- >>> tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++- >>> 1 file changed, 29 insertions(+), 1 deletion(-) >>> >>> diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c >>> index 433029c6afc5..cd0905d8cb7a 100644 >>> --- a/tools/perf/util/perf_event_attr_fprintf.c >>> +++ b/tools/perf/util/perf_event_attr_fprintf.c >>> @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) >>> __p_bits(buf, size, value, bits); >>> } >>> +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); >>> +static const char *stringify_perf_type_id(u64 value) >>> +{ >>> + /* sync with enum perf_type_id in perf_event.h */ >> >> Everything in this file syncs with perf_event.h, so the comment >> does not seem very useful. > OK, will fix in v3. >> >>> + switch (value) { >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) >>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) >>> + default: >>> + return NULL; >>> + } >>> +} >>> +#undef ENUM_ID_TO_STR_CASE >>> + >>> +static void __p_type_id(char *buf, size_t size, u64 value) >>> +{ >>> + const char *str = stringify_perf_type_id(value); >>> + >>> + if (str == NULL) >>> + snprintf(buf, size, "%"PRIu64, value); >>> + else >>> + snprintf(buf, size, "%"PRIu64" (%s)", value, str); >> >> These 4 lines end up getting used again about 3 times in the next >> patch, so might as well be a separate function e.g. >> >> print_id(buf, size, value, stringify_perf_type_id(value)); >> >> where: >> >> static void print_id(char *buf, size_t size, u64 value, const char *str) >> { >> if (str == NULL) >> snprintf(buf, size, "%"PRIu64, value); >> else >> snprintf(buf, size, "%"PRIu64" (%s)", value, str); >> } >> > OK, will add print_id() helper in v3. > If print_id() helper is also used to print config id, is printed in the decimal format. In the past, it is printed in the hexadecimal format, > there may be some changes here. > > Before: > config 0x143 > > After: > config 323 (sched:sched_switch) Right I didn't notice the difference. Best keep print_id() just for the hex cases. > >>> +} >>> + >>> #define BUF_SIZE 1024 >>> #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) >>> @@ -79,6 +106,7 @@ static void __p_read_format(char *buf, size_t size, u64 value) >>> #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) >>> #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) >>> #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) >>> +#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val) >>> #define PRINT_ATTRn(_n, _f, _p, _a) \ >>> do { \ >>> @@ -96,7 +124,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, >>> char buf[BUF_SIZE]; >>> int ret = 0; >>> - PRINT_ATTRf(type, p_unsigned); >>> + PRINT_ATTRn("type", type, p_type_id, true); >>> PRINT_ATTRf(size, p_unsigned); >>> PRINT_ATTRf(config, p_hex); >>> PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned, false); >> >> . >>
Hello, On 2023/5/15 16:56, Adrian Hunter wrote: > On 15/05/23 11:48, Yang Jihong wrote: >> Hello, >> >> On 2023/5/12 18:34, Adrian Hunter wrote: >>> On 11/05/23 10:51, Yang Jihong wrote: >>>> When printing perf_event_attr, always display perf_event_attr type and its symbol >>>> to improve the readability of debugging information. >>>> >>>> Before: >>>> >>>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>>> <SNIP> >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 1 >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 2 >>>> size 136 >>>> config 0x143 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 3 >>>> size 136 >>>> config 0x10005 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 4 >>>> size 136 >>>> config 0x101 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 5 >>>> size 136 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> bp_type 3 >>>> { bp_len, config2 } 0x4 >>>> ------------------------------------------------------------ >>>> <SNIP> >>>> >>>> After: >>>> >>>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>>> <SNIP> >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 0 (PERF_TYPE_HARDWARE) >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 1 (PERF_TYPE_SOFTWARE) >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 2 (PERF_TYPE_TRACEPOINT) >>>> size 136 >>>> config 0x143 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 3 (PERF_TYPE_HW_CACHE) >>>> size 136 >>>> config 0x10005 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 4 (PERF_TYPE_RAW) >>>> size 136 >>>> config 0x101 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 5 (PERF_TYPE_BREAKPOINT) >>>> size 136 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> bp_type 3 >>>> { bp_len, config2 } 0x4 >>>> ------------------------------------------------------------ >>>> <SNIP> >>>> >>>> Signed-off-by: Yang Jihong <yangjihong1@huawei.com> >>>> --- >>>> tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++- >>>> 1 file changed, 29 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c >>>> index 433029c6afc5..cd0905d8cb7a 100644 >>>> --- a/tools/perf/util/perf_event_attr_fprintf.c >>>> +++ b/tools/perf/util/perf_event_attr_fprintf.c >>>> @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) >>>> __p_bits(buf, size, value, bits); >>>> } >>>> +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); >>>> +static const char *stringify_perf_type_id(u64 value) >>>> +{ >>>> + /* sync with enum perf_type_id in perf_event.h */ >>> >>> Everything in this file syncs with perf_event.h, so the comment >>> does not seem very useful. >> OK, will fix in v3. >>> >>>> + switch (value) { >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) >>>> + default: >>>> + return NULL; >>>> + } >>>> +} >>>> +#undef ENUM_ID_TO_STR_CASE >>>> + >>>> +static void __p_type_id(char *buf, size_t size, u64 value) >>>> +{ >>>> + const char *str = stringify_perf_type_id(value); >>>> + >>>> + if (str == NULL) >>>> + snprintf(buf, size, "%"PRIu64, value); >>>> + else >>>> + snprintf(buf, size, "%"PRIu64" (%s)", value, str); >>> >>> These 4 lines end up getting used again about 3 times in the next >>> patch, so might as well be a separate function e.g. >>> >>> print_id(buf, size, value, stringify_perf_type_id(value)); >>> >>> where: >>> >>> static void print_id(char *buf, size_t size, u64 value, const char *str) >>> { >>> if (str == NULL) >>> snprintf(buf, size, "%"PRIu64, value); >>> else >>> snprintf(buf, size, "%"PRIu64" (%s)", value, str); >>> } >>> >> OK, will add print_id() helper in v3. >> If print_id() helper is also used to print config id, is printed in the decimal format. In the past, it is printed in the hexadecimal format, >> there may be some changes here. >> >> Before: >> config 0x143 >> >> After: >> config 323 (sched:sched_switch) > > Right I didn't notice the difference. Best keep print_id() just for the hex cases. > Emm...,Is the type id also printed in hexadecimal format? static void print_id(char *buf, size_t size, u64 value, const char *str) { if (str == NULL) snprintf(buf, size, "%#"PRIx64, value); else snprintf(buf, size, "%#"PRIx64" (%s)", value, str); } Output: perf_event_attr: type 0x2 (PERF_TYPE_TRACEPOINT) size 136 config 0x124 (sched:sched_switch) Because v3 has just been sent out, if need to modify it according to this, I'll send v4. Thanks, Yang
Hello, On 2023/5/15 16:56, Adrian Hunter wrote: > On 15/05/23 11:48, Yang Jihong wrote: >> Hello, >> >> On 2023/5/12 18:34, Adrian Hunter wrote: >>> On 11/05/23 10:51, Yang Jihong wrote: >>>> When printing perf_event_attr, always display perf_event_attr type and its symbol >>>> to improve the readability of debugging information. >>>> >>>> Before: >>>> >>>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>>> <SNIP> >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 1 >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 2 >>>> size 136 >>>> config 0x143 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 3 >>>> size 136 >>>> config 0x10005 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 4 >>>> size 136 >>>> config 0x101 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 5 >>>> size 136 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> bp_type 3 >>>> { bp_len, config2 } 0x4 >>>> ------------------------------------------------------------ >>>> <SNIP> >>>> >>>> After: >>>> >>>> # perf --debug verbose=2 record -e cycles,cpu-clock,sched:sched_switch,branch-load-misses,r101,mem:0x0 -C 0 true >>>> <SNIP> >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 0 (PERF_TYPE_HARDWARE) >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 5 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 1 (PERF_TYPE_SOFTWARE) >>>> size 136 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 6 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 2 (PERF_TYPE_TRACEPOINT) >>>> size 136 >>>> config 0x143 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|PERIOD|RAW|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 7 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 3 (PERF_TYPE_HW_CACHE) >>>> size 136 >>>> config 0x10005 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 9 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 4 (PERF_TYPE_RAW) >>>> size 136 >>>> config 0x101 >>>> { sample_period, sample_freq } 4000 >>>> sample_type IP|TID|TIME|CPU|PERIOD|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> freq 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> ------------------------------------------------------------ >>>> sys_perf_event_open: pid -1 cpu 0 group_fd -1 flags 0x8 = 10 >>>> ------------------------------------------------------------ >>>> perf_event_attr: >>>> type 5 (PERF_TYPE_BREAKPOINT) >>>> size 136 >>>> { sample_period, sample_freq } 1 >>>> sample_type IP|TID|TIME|CPU|IDENTIFIER >>>> read_format ID >>>> disabled 1 >>>> inherit 1 >>>> sample_id_all 1 >>>> exclude_guest 1 >>>> bp_type 3 >>>> { bp_len, config2 } 0x4 >>>> ------------------------------------------------------------ >>>> <SNIP> >>>> >>>> Signed-off-by: Yang Jihong <yangjihong1@huawei.com> >>>> --- >>>> tools/perf/util/perf_event_attr_fprintf.c | 30 ++++++++++++++++++++++- >>>> 1 file changed, 29 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c >>>> index 433029c6afc5..cd0905d8cb7a 100644 >>>> --- a/tools/perf/util/perf_event_attr_fprintf.c >>>> +++ b/tools/perf/util/perf_event_attr_fprintf.c >>>> @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) >>>> __p_bits(buf, size, value, bits); >>>> } >>>> +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); >>>> +static const char *stringify_perf_type_id(u64 value) >>>> +{ >>>> + /* sync with enum perf_type_id in perf_event.h */ >>> >>> Everything in this file syncs with perf_event.h, so the comment >>> does not seem very useful. >> OK, will fix in v3. >>> >>>> + switch (value) { >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) >>>> + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) >>>> + default: >>>> + return NULL; >>>> + } >>>> +} >>>> +#undef ENUM_ID_TO_STR_CASE >>>> + >>>> +static void __p_type_id(char *buf, size_t size, u64 value) >>>> +{ >>>> + const char *str = stringify_perf_type_id(value); >>>> + >>>> + if (str == NULL) >>>> + snprintf(buf, size, "%"PRIu64, value); >>>> + else >>>> + snprintf(buf, size, "%"PRIu64" (%s)", value, str); >>> >>> These 4 lines end up getting used again about 3 times in the next >>> patch, so might as well be a separate function e.g. >>> >>> print_id(buf, size, value, stringify_perf_type_id(value)); >>> >>> where: >>> >>> static void print_id(char *buf, size_t size, u64 value, const char *str) >>> { >>> if (str == NULL) >>> snprintf(buf, size, "%"PRIu64, value); >>> else >>> snprintf(buf, size, "%"PRIu64" (%s)", value, str); >>> } >>> >> OK, will add print_id() helper in v3. >> If print_id() helper is also used to print config id, is printed in the decimal format. In the past, it is printed in the hexadecimal format, >> there may be some changes here. >> >> Before: >> config 0x143 >> >> After: >> config 323 (sched:sched_switch) > > Right I didn't notice the difference. Best keep print_id() just for the hex cases. > v4 has been sent, print_id() helper is changed to a macro function to support printing of both 'hex' and 'unsigned' formats. Please see if it's OK. Thanks, Yang
diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c index 433029c6afc5..cd0905d8cb7a 100644 --- a/tools/perf/util/perf_event_attr_fprintf.c +++ b/tools/perf/util/perf_event_attr_fprintf.c @@ -71,6 +71,33 @@ static void __p_read_format(char *buf, size_t size, u64 value) __p_bits(buf, size, value, bits); } +#define ENUM_ID_TO_STR_CASE(x) case x: return (#x); +static const char *stringify_perf_type_id(u64 value) +{ + /* sync with enum perf_type_id in perf_event.h */ + switch (value) { + ENUM_ID_TO_STR_CASE(PERF_TYPE_HARDWARE) + ENUM_ID_TO_STR_CASE(PERF_TYPE_SOFTWARE) + ENUM_ID_TO_STR_CASE(PERF_TYPE_TRACEPOINT) + ENUM_ID_TO_STR_CASE(PERF_TYPE_HW_CACHE) + ENUM_ID_TO_STR_CASE(PERF_TYPE_RAW) + ENUM_ID_TO_STR_CASE(PERF_TYPE_BREAKPOINT) + default: + return NULL; + } +} +#undef ENUM_ID_TO_STR_CASE + +static void __p_type_id(char *buf, size_t size, u64 value) +{ + const char *str = stringify_perf_type_id(value); + + if (str == NULL) + snprintf(buf, size, "%"PRIu64, value); + else + snprintf(buf, size, "%"PRIu64" (%s)", value, str); +} + #define BUF_SIZE 1024 #define p_hex(val) snprintf(buf, BUF_SIZE, "%#"PRIx64, (uint64_t)(val)) @@ -79,6 +106,7 @@ static void __p_read_format(char *buf, size_t size, u64 value) #define p_sample_type(val) __p_sample_type(buf, BUF_SIZE, val) #define p_branch_sample_type(val) __p_branch_sample_type(buf, BUF_SIZE, val) #define p_read_format(val) __p_read_format(buf, BUF_SIZE, val) +#define p_type_id(val) __p_type_id(buf, BUF_SIZE, val) #define PRINT_ATTRn(_n, _f, _p, _a) \ do { \ @@ -96,7 +124,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, char buf[BUF_SIZE]; int ret = 0; - PRINT_ATTRf(type, p_unsigned); + PRINT_ATTRn("type", type, p_type_id, true); PRINT_ATTRf(size, p_unsigned); PRINT_ATTRf(config, p_hex); PRINT_ATTRn("{ sample_period, sample_freq }", sample_period, p_unsigned, false);