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 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 E60D8C4167B for ; Wed, 21 Dec 2022 22:41:04 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NcpM334WGz3fG7 for ; Thu, 22 Dec 2022 09:41:03 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=bxVJqQOT; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--irogers.bounces.google.com (client-ip=2607:f8b0:4864:20::54a; helo=mail-pg1-x54a.google.com; envelope-from=3jiqjywckdoktczrpcdrzzrwp.nzxwtyfiaan-opgwtded.zkwlmd.zcr@flex--irogers.bounces.google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=bxVJqQOT; dkim-atps=neutral Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NcpDR0CW7z3c9Z for ; Thu, 22 Dec 2022 09:35:18 +1100 (AEDT) Received: by mail-pg1-x54a.google.com with SMTP id 38-20020a630b26000000b004773803dda1so106131pgl.17 for ; Wed, 21 Dec 2022 14:35:18 -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=pC6isRrZQJBTPK0pkg9ElG5ABnt5NfeUEOm6zvm9c6s=; b=bxVJqQOTiX9f1tA62gviN0yBaRAZx1IjeakOqrQFWy2XrypXLEa6yhuzevo6tTduWZ nVo63HkbDpt6HVpwdMZEOYanE067vmvtTb92yMQ5dsCQ2/p8BEs9vU501nD4zwfhSUZ7 BqL74ZB3n8EIVrew/Y06Vl+ylDsgyaQrtLG0Jz3uPMRnKdbOC89aArgZL+96t0UZL+wH +cd6Mjd3fNDMP7YupeYkgP4xnramou5By08FKVzeZMsOdTYGWfUnRXPLybP8FMusBtqo vCaLhWwRUeTd3HCG1bNDlsE6h0xFWmvkF/xxKZ/u6q633Xxgh/nx8SSuk9qlZZRQRVh8 JhIA== 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=pC6isRrZQJBTPK0pkg9ElG5ABnt5NfeUEOm6zvm9c6s=; b=yUexKQh4oe5/RV2AxBWTXOQyJNDclGSAv346iCewiF33ShmgZ7jTfA/p9Uh8WGBadd bu+RFPVQVu4RnmwSnL2SW1+4ZrTCtYgrT9rrSr0dZ8vdDFsJYx8vtubldhTb/kyrZCGz oeLPAzcJFELCtS3iHU/I0kGqJTJGWr66IWfqbn/bnbP9r272cBIi5BRU2IxQN8JBCeBL AKo/Segn0bEna0Yc33uSAS28iCGJha7oEZI5HvVdAcs6bmEB/OMzJfCRPR3fVw4Bsojk cUIqBDSie3rWEYj1FiQKgocWRYTGDRAzfZc9VAfCNx/mkOcl+myTCsCrI7tn45iO9tBu BKCw== X-Gm-Message-State: AFqh2ko8SktDLF3kgm3RqxAkn331dFgHbkTvlZerPGJ/Gu9Q0c//Bn3Z /XCEINbVXwHPUDeHuGT03Q+G44QMyKNh X-Google-Smtp-Source: AMrXdXvZgXgBm+ynSwUWG/YkqiQEqVQKEBGGCqm8lB+5EeVkLFjGgB4/0yy2i9dKPCb+QTfGBMBczDHbBr0U X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:62bd:f120:1fd8:1d21]) (user=irogers job=sendgmr) by 2002:a17:902:e045:b0:191:7ec:8236 with SMTP id x5-20020a170902e04500b0019107ec8236mr319004plx.38.1671662116379; Wed, 21 Dec 2022 14:35:16 -0800 (PST) Date: Wed, 21 Dec 2022 14:34:17 -0800 In-Reply-To: <20221221223420.2157113-1-irogers@google.com> Message-Id: <20221221223420.2157113-7-irogers@google.com> Mime-Version: 1.0 References: <20221221223420.2157113-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v2 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 Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Rogers , Perry Taylor , Caleb Biggers , Stephane Eranian Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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() -- 2.39.0.314.g84b9a713c41-goog