From patchwork Tue Dec 13 05:00:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13071722 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 99CCCC4332F for ; Tue, 13 Dec 2022 05:05:19 +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=Gda6xXjiWHzdzTAp844sPEz3McyCB/XgiA0SyNw26mc=; b=smmH0FOu12sAh1daAHUwwBbUFC S0pP4nllz71R6sBg98PdlLPs/eeAz5PfXVo18/VPYx7pqaLtf7zYcrfX51YZbB6XXKYcWS1+rLGvr HLBNq8RKd+iROqzE40AXT1TZab6C3ooAUOOTYEeQxl74whH6aj7kHKDlE/VShIyfN7CYLusmvnevn 1KOiIuyDfdorikLyqIEFHoQ92UesDaupJQlfM/6J9urck8kyahCxRvxNhQPS1+CRYTXYfn2RyQae+ w641XzcUCi847k/m9VTyI9s3qrWykjtc1IsgHZ9pjVbSgQNBWNNG7WqDTlvvJDWMsjSJu/6nF/M8i 5LW7ExxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4xSS-00B6eh-8h; Tue, 13 Dec 2022 05:04:00 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4xQj-00B5zv-Nm for linux-arm-kernel@lists.infradead.org; Tue, 13 Dec 2022 05:02:16 +0000 Received: by mail-pj1-x1049.google.com with SMTP id b16-20020a17090a10d000b00221653b4526so1251493pje.2 for ; Mon, 12 Dec 2022 21:02:12 -0800 (PST) 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:subject:date:message-id:reply-to; bh=38QYNRsCdXA58zmeiyEnX9qHG+LlKARQrs6L5bFJGmM=; b=ZwSzYgPKM3xNmtyHwDzsR/elgCiCTdCA3ZqyzuSeAgvVJ8+7DpbNxaihdfbMFmXeuL HgBMwlWo1NWTP2x/YhsXdFhL44+aPs1008/SjG/zaDdJmCW3SWx1RPMeAX0UHhwZ1dB8 8Fi9t+CWwe0ZuXJKvdi1XZoW1OSqKpJTwXT+hFulAg//PsCAS2G3v+Spu0e+fRY6Z1/A LB3QYyxI3UllQI81PS1EMEsjB3q2ZlzGXLtlAMSGY5GYa8U/o9eP1Ep+jfqosc4izNvX 3JwDAOJ8C1qLadDJiFSBMZ/r8/U9ltYDW0ox8kuE4eByWnJS9EXdMxzIpLw3c4YNzLlZ hS2A== 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:subject:date:message-id:reply-to; bh=38QYNRsCdXA58zmeiyEnX9qHG+LlKARQrs6L5bFJGmM=; b=XYgd8OtcnoEHl5NHmO+Zg9fPuS6p2otnljlQ9nKyPOfsCsNY3xNHtzqW9NO2uOcIsL F+MiSYWSHdbeiCFZezo9WR85VpYgfwp18kpG7OkMlzyj9+HiN7VfZicQIHV7v5rpc/IA NAMcLvs46c7aqKzXAp7qn4Deqd1D7F6+8IQ6AmyRLTsw9t1WfLRbNS62vB0q9b0np7RH TzYXj6mEM8BRsVIBKOwYbBGctnWY6xKhWTvfdkyBFvTTckcbBYWzRvbnhuRczBC7NrMe 0moVlKFRcoxvey4sZdZQ+li7k3fCTswxASIonSJa47hii9Hx6DjZWzWYZDgsXtYStmJS OzzA== X-Gm-Message-State: ANoB5pmsp8fifIvexmcrdnQJhE0Ou6Ggx6UU0HUQvi8JZZkjZK9hpp6a R8778NGV+LlkceJ54/s8ErD/cVHw+SKQ X-Google-Smtp-Source: AA0mqf5NjYnnJMl8dXHAzoxuTBUvXM+hRAmSW3b/0ORsS37wAy9f+GZghdscMj+Bkc+TpmYtEpMN7vyPtFnq X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:6b9f:864c:28da:e99b]) (user=irogers job=sendgmr) by 2002:a17:90a:684a:b0:219:8d8a:a644 with SMTP id e10-20020a17090a684a00b002198d8aa644mr140669pjm.174.1670907731914; Mon, 12 Dec 2022 21:02:11 -0800 (PST) Date: Mon, 12 Dec 2022 21:00:40 -0800 In-Reply-To: <20221213050043.1199380-1-irogers@google.com> Message-Id: <20221213050043.1199380-7-irogers@google.com> Mime-Version: 1.0 References: <20221213050043.1199380-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Subject: [PATCH v1 6/9] perf jevents: Combine table prefix and suffix writing 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 , Adrian Hunter , Kan Liang , Kim Phillips , Florian Fischer , Ravi Bangoria , Xing Zhengjun , Rob Herring , Kang Minchul , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das , Jing Zhang , linuxppc-dev@lists.ozlabs.org, Kajol Jain Cc: Stephane Eranian , Perry Taylor , Caleb Biggers , Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221212_210213_871890_25F38623 X-CRM114-Status: GOOD ( 14.89 ) 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 Combine into a single function to simplify, in a later change, writing metrics separately. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 36 +++++++++++++------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index ee3d4cdf01be..7b9714b25d0a 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -19,10 +19,10 @@ _sys_event_tables = [] # JsonEvent. Architecture standard events are in json files in the top # f'{_args.starting_dir}/{_args.arch}' directory. _arch_std_events = {} -# Track whether an events table is currently being defined and needs closing. -_close_table = False # Events to write out when the table is closed _pending_events = [] +# Name of table to be written out +_pending_events_tblname = None # Global BigCString shared by all structures. _bcs = None # Order specific JsonEvent attributes will be visited. @@ -376,24 +376,13 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.name.lower()] = event -def print_events_table_prefix(tblname: str) -> None: - """Called when a new events table is started.""" - global _close_table - if _close_table: - raise IOError('Printing table prefix but last table has no suffix') - _args.output_file.write(f'static const struct compact_pmu_event {tblname}[] = {{\n') - _close_table = True - - def add_events_table_entries(item: os.DirEntry, topic: str) -> None: """Add contents of file to _pending_events table.""" - if not _close_table: - raise IOError('Table entries missing prefix') for e in read_json_events(item.path, topic): _pending_events.append(e) -def print_events_table_suffix() -> None: +def print_pending_events() -> None: """Optionally close events table.""" def event_cmp_key(j: JsonEvent) -> Tuple[bool, str, str, str, str]: @@ -405,17 +394,19 @@ def print_events_table_suffix() -> None: return (j.desc is not None, fix_none(j.topic), fix_none(j.name), fix_none(j.pmu), fix_none(j.metric_name)) - global _close_table - if not _close_table: + global _pending_events + if not _pending_events: return - global _pending_events + global _pending_events_tblname + _args.output_file.write( + f'static const struct compact_pmu_event {_pending_events_tblname}[] = {{\n') + for event in sorted(_pending_events, key=event_cmp_key): _args.output_file.write(event.to_c_string()) - _pending_events = [] + _pending_events = [] _args.output_file.write('};\n\n') - _close_table = False def get_topic(topic: str) -> str: if topic.endswith('metrics.json'): @@ -453,12 +444,13 @@ def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None: # model directory, reset topic if item.is_dir() and is_leaf_dir(item.path): - print_events_table_suffix() + print_pending_events() tblname = file_name_to_table_name(parents, item.name) if item.name == 'sys': _sys_event_tables.append(tblname) - print_events_table_prefix(tblname) + global _pending_events_tblname + _pending_events_tblname = tblname return # base dir or too deep @@ -802,7 +794,7 @@ struct compact_pmu_event { for arch in archs: arch_path = f'{_args.starting_dir}/{arch}' ftw(arch_path, [], process_one_file) - print_events_table_suffix() + print_pending_events() print_mapping_table(archs) print_system_mapping_table()