From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F72BFA3733 for ; Thu, 17 Oct 2019 11:52:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4B342082C for ; Thu, 17 Oct 2019 11:52:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502188AbfJQLwA (ORCPT ); Thu, 17 Oct 2019 07:52:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:41070 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2502168AbfJQLwA (ORCPT ); Thu, 17 Oct 2019 07:52:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 73E88B03A; Thu, 17 Oct 2019 11:51:58 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 9C1DEDA808; Thu, 17 Oct 2019 13:52:09 +0200 (CEST) Date: Thu, 17 Oct 2019 13:52:09 +0200 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: Re: [PATCH v2] tools/lib/traceevent, perf tools: Handle %pU format correctly Message-ID: <20191017115209.GG2751@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org References: <20191017022800.31866-1-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191017022800.31866-1-wqu@suse.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 17, 2019 at 10:28:00AM +0800, Qu Wenruo wrote: > [BUG] > For btrfs related events, there is a field for fsid, but perf never > parse it correctly. > > # perf trace -e btrfs:qgroup_meta_convert xfs_io -f -c "pwrite 0 4k" \ > /mnt/btrfs/file1 > 0.000 xfs_io/77915 btrfs:qgroup_meta_reserve:(nil)U: refroot=5(FS_TREE) type=0x0 diff=2 > ^^^^^^ Not a correct UUID > ... > > [CAUSE] > The pretty_print() function doesn't handle the %pU format correctly. > In fact it doesn't handle %pU as uuid at all. > > [FIX] > Add a new function, print_uuid_arg(), to handle %pU correctly. > > Now perf trace can at least print fsid correctly: > 0.000 xfs_io/79619 btrfs:qgroup_meta_reserve:23ad1511-dd83-47d4-a79c-e96625a15a6e refroot=5(FS_TREE) type=0x0 diff=2 > > Signed-off-by: Qu Wenruo > --- > Changelog: > v2: > - Use more comment explaining the finetunings we skipped for %pU* > - Use more elegant way to output uuid string > --- > tools/lib/traceevent/event-parse.c | 56 ++++++++++++++++++++++++++++++ > 1 file changed, 56 insertions(+) > > diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c > index d948475585ce..3c9473f46efe 100644 > --- a/tools/lib/traceevent/event-parse.c > +++ b/tools/lib/traceevent/event-parse.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > > #include > @@ -4508,6 +4509,45 @@ get_bprint_format(void *data, int size __maybe_unused, > return format; > } > > +static void print_uuid_arg(struct trace_seq *s, void *data, int size, > + struct tep_event *event, struct tep_print_arg *arg) > +{ > + unsigned char *buf; > + int i; > + > + if (arg->type != TEP_PRINT_FIELD) { > + trace_seq_printf(s, "ARG TYPE NOT FIELID but %d", arg->type); > + return; > + } > + > + if (!arg->field.field) { > + arg->field.field = tep_find_any_field(event, arg->field.name); > + if (!arg->field.field) { > + do_warning("%s: field %s not found", > + __func__, arg->field.name); > + return; > + } > + } > + if (arg->field.field->size < 16) { > + trace_seq_printf(s, "INVALID UUID: size have %u expect 16", > + arg->field.field->size); > + return; > + } So if there's an interest for very compact printing loop, something like this produces the same output: for (i = 0; i < 8; i++) { printf("%02X", buf[i]); printf("%02X", buf[i]); if (1 <= i && i <= 4) putchar('-'); } "23ad 1511 - dd83 - 47d4 - a79c - e966 25a1 5a6e" 0 1 2 3 4 5 6 7 IOW, split into pairs and print dash after a few of them.