From patchwork Thu Aug 4 22:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12936726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 17D81C25B06 for ; Thu, 4 Aug 2022 22:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=It30+FSKA0alCHWyjBnFAOOLC3WQ9KSdBfR8IFldEQE=; b=1WxWRMbue+LZiLoPoe7UQbHS3O 76eSu16Jb+IrlU+tFq1loyxQfmp9t8TkTPRImI9AAUaMEq+Nh864maCIxE9xcZbbyTsppJg4C5/Ru SAPq6ujhV+JakAmFwli+Qa+gm8sS4jymAXRsKCvrUGh4PWdhPXB0+BWBG0roj6LmG6WXIJQSkgWo5 v+TiGMCkGJIXLrZq8SSWtV+wHRJNKNrFSugKxUJ/1Dj4KNOwf9aNOzpgJAcyEmXdhLjt2eRDp3mIj PsZGiVZHjQkabDlju+AZ3gh1JTsekWUpjq+lt4DkRmWeyAUNAFbuUnUe3hlRmTo1XSfgx6mEndxe8 1YYZ1k+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJjCw-009Wxp-FI; Thu, 04 Aug 2022 22:20:48 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJjAj-009W2u-TI for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2022 22:18:31 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f58599ad3so6973187b3.20 for ; Thu, 04 Aug 2022 15:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=N++Mrhq6kQeFrF8RmnJUsnk+16Uv6ufZYhZg1IA0uDA=; b=TXD73nrJU+7eARBRcGR55uk4+DwtVJBAQxSiOVKpyhrRZ5RO7RndxUr8lO+mmzD4T2 BrmRQ3He1TQzRs029LnPWblE5dDPet7+BdRpqE++iRb8WKUkWedWWxDuC9LNd6CK/9Ls XQzmnEiLmYEUmR6zXQxllkqPR7bc6ihVYbrExoW3EK5EzMwEL61px4MxFO9qSKyoPdeB vQYyXhVQEiRbh4P7lnLmVwTfQLwukDO+GiT0AcC+Usl7ncPvlPu6IuVxZQjwhoVd7KXU 439AEoMLzX8I1tlwlwoC3jRIbz6ON9tce+YmPNEV4jmtBaGSTw0iXPfg1Pr7xiY5YobC HIJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=N++Mrhq6kQeFrF8RmnJUsnk+16Uv6ufZYhZg1IA0uDA=; b=4Jf7HKGxAURi08AAQi7CC7YFyQ7O94SoF9VE7nQ64yj0ySpueBYJk3Xh/7006N1Bhi zgTdlaIIkfEkxHsRizqc3++OkrNqtCMyw5qr0HGaFHgzhwrlpmqUo1arjnfeKQutMKT/ BFY3JViU6Z7A6FnX8hF7eu6H0t5ZVak7gPIww67abLorxKWFcOuVw2wefFCXzyTnBh0K OTrmIM6HmihV/z+Lqr7Z+pdz+1vxNVSRG1ulEEnA3LCO2ZUxdclXtDlLLhZIeug8rOD4 bC4IoHmg9aoewQxZnahPB5M5KSCOFoUzB3BWIuaXnyyqLl4NoEx5QUGwT02em1F2z3ls SCfg== X-Gm-Message-State: ACgBeo3VhnMWlFC4J5YucSv/OIiucHuQ51gSJg0Zd+/y5PRBHQhKXpe8 8hFQoztJodBIOMylh86I3fyJC+EfGbt+ X-Google-Smtp-Source: AA6agR6l2OkctpCBldtJSDt5KcZmeFaj7z6S97AUd0CAOBSyjbZU2NHKqPh/zAmXOFewOm+ciB+zYLxT+Eka X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:f5e1:5bc5:7dab:2b7c]) (user=irogers job=sendgmr) by 2002:a25:9b48:0:b0:67a:6ad0:f078 with SMTP id u8-20020a259b48000000b0067a6ad0f078mr3169103ybo.536.1659651508142; Thu, 04 Aug 2022 15:18:28 -0700 (PDT) Date: Thu, 4 Aug 2022 15:18:01 -0700 In-Reply-To: <20220804221816.1802790-1-irogers@google.com> Message-Id: <20220804221816.1802790-3-irogers@google.com> Mime-Version: 1.0 References: <20220804221816.1802790-1-irogers@google.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog Subject: [PATCH v4 02/17] perf jevents: Simplify generation of C-string From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Zhengjun Xing , Ravi Bangoria , Kan Liang , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Cc: Stephane Eranian , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_151830_011682_495B73E3 X-CRM114-Status: GOOD ( 13.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Previous implementation wanted variable order and '(null)' string output to match the C implementation. The '(null)' string output was a quirk/bug and so there is no need to carry it forward. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index 5b72048d50da..cdfa4e0e7557 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -203,7 +203,7 @@ class JsonEvent: """Representation of the event as a C struct initializer.""" def attr_string(attr: str, value: str) -> str: - return '\t.%s = \"%s\",\n' % (attr, value) + return f'\t.{attr} = \"{value}\",\n' def str_if_present(self, attr: str) -> str: if not getattr(self, attr): @@ -211,17 +211,11 @@ class JsonEvent: return attr_string(attr, getattr(self, attr)) s = '{\n' - for attr in ['name', 'event']: - s += str_if_present(self, attr) - if self.desc is not None: - s += attr_string('desc', self.desc) - else: - s += attr_string('desc', '(null)') - s += str_if_present(self, 'compat') s += f'\t.topic = "{topic_local}",\n' for attr in [ - 'long_desc', 'pmu', 'unit', 'perpkg', 'aggr_mode', 'metric_expr', - 'metric_name', 'metric_group', 'deprecated', 'metric_constraint' + 'aggr_mode', 'compat', 'deprecated', 'desc', 'event', 'long_desc', + 'metric_constraint', 'metric_expr', 'metric_group', 'metric_name', + 'name', 'perpkg', 'pmu', 'unit' ]: s += str_if_present(self, attr) s += '},\n'