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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B044AC27C76 for ; Thu, 26 Jan 2023 01:20:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236040AbjAZBUk (ORCPT ); Wed, 25 Jan 2023 20:20:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjAZBUj (ORCPT ); Wed, 25 Jan 2023 20:20:39 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91DBF64DA0 for ; Wed, 25 Jan 2023 17:20:10 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4597b0ff5e9so3943997b3.10 for ; Wed, 25 Jan 2023 17:20:10 -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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=szv/8QdNSp2myZhetiv+HBlEzrYqtH54GGv+4csDy6tkYmSOpnwfgd8SizPlPCYMl7 BT6unBlOqiizZhkCKtirqUKAZTutPbk+WAeKe7xm3Ow/tYJ14SOscBOib2QVMdyNR6zB 2xayHzwqsTnWj4IiJgAMl16SvkORUua1H9c/vUE/6NI79psnvhHOqeOzS3HYg3gaMmxF ru/Zv+iHMCvLUZka9TjOqZsGj5e6oa6sEttZPrLbZ1hsRpoKwaXVB4k6EPEIa0Q590Og rmo9oyt5YAwjFm/Elbc5lfpNIymEOGJkMDdEFC5+t4yLjuRfFwiR4WFccmMnSJTVuf2P RVUA== 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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=4K65vwA0ovEsDelO984y0lmxJxNtbRVsVW7tZAvI5nDG97YdpyzIjzN4v2B5D2vzaX DehNa7rDbOe0gFsfepB1glpBCcMbsxgQgCd7uQ2/de6w6euTHjpyJzWmKsE85Np/pm5F T6W9Ert+F+Z+w72KY75iDyEh6JlIhytOEdUoDML2MuxcX7+n73Ycpi41IoP3QTEQLaMR /CZnUj2KntTF2khqwSXYBFA8cuJbH8aSN8YZQ2033iyawN8him7WjoykdimzkgDTPwwb hRwuiMz/+Spy0WG/SJ+fYnqFRr2Msf4zJeYonXYhu8TQ7b8/ZR4uXlPSoIf4B/g4r/2P aeNA== X-Gm-Message-State: AFqh2koAXQ1B7g3DD2BMpqnU92eHt8IRt6RiWyivIE5UiX+zsDFfvf11 bpE8GtOL5s49kWbK/sTykKbVkhpAkzOQ X-Google-Smtp-Source: AMrXdXvF8lJSvZWcavK7Q1tHKy9uwBax3i34mr7oaH67rab6/l55Wb54YSMzQO04ft9SdijBc4q9I+5h24Lm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:568d:4d98:b468:b025]) (user=irogers job=sendgmr) by 2002:a25:8b82:0:b0:75e:ca27:ca65 with SMTP id j2-20020a258b82000000b0075eca27ca65mr4100382ybl.464.1674696009789; Wed, 25 Jan 2023 17:20:09 -0800 (PST) Date: Wed, 25 Jan 2023 17:18:50 -0800 In-Reply-To: <20230126011854.198243-1-irogers@google.com> Message-Id: <20230126011854.198243-9-irogers@google.com> Mime-Version: 1.0 References: <20230126011854.198243-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v4 08/12] 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.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 4cdbf34b7298..5f8d490c7269 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. @@ -378,24 +378,13 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.metric_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]: @@ -407,17 +396,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'): @@ -455,12 +446,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 @@ -809,7 +801,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.1.456.gfc5497dd1b-goog 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 BEE29C54E94 for ; Thu, 26 Jan 2023 01:27:32 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4P2NNz1q50z3fT3 for ; Thu, 26 Jan 2023 12:27:31 +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=szv/8QdN; 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::114a; helo=mail-yw1-x114a.google.com; envelope-from=3sdxrywckdgagpmecpqemmejc.amkjglsvnna-bctjgqrq.mxj89q.mpe@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=szv/8QdN; dkim-atps=neutral Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) (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 4P2NDX2Slsz3fDG for ; Thu, 26 Jan 2023 12:20:12 +1100 (AEDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-4d5097a95f5so4138757b3.1 for ; Wed, 25 Jan 2023 17:20:11 -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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=szv/8QdNSp2myZhetiv+HBlEzrYqtH54GGv+4csDy6tkYmSOpnwfgd8SizPlPCYMl7 BT6unBlOqiizZhkCKtirqUKAZTutPbk+WAeKe7xm3Ow/tYJ14SOscBOib2QVMdyNR6zB 2xayHzwqsTnWj4IiJgAMl16SvkORUua1H9c/vUE/6NI79psnvhHOqeOzS3HYg3gaMmxF ru/Zv+iHMCvLUZka9TjOqZsGj5e6oa6sEttZPrLbZ1hsRpoKwaXVB4k6EPEIa0Q590Og rmo9oyt5YAwjFm/Elbc5lfpNIymEOGJkMDdEFC5+t4yLjuRfFwiR4WFccmMnSJTVuf2P RVUA== 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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=PDG/slyXxhib0RET9GAU8fpqMOyxux8NxV2nIWg674+2e6EdcOi5jmm/Xe4QAo6KUd AEkrTsixcybFXJzdpy0E7C08XLffA6ezT5J7Y3//x+9vKoj5DMqxcN3kBC79H1OZdPDW plf29roNrr6WNR9qS0ZeePyTip0ubJabKLI6Xi5QbWfyX88Ijf0rOBaXoFDIwBe4o6S1 6o+Jcga95h1FYEM9OPMsm+LNtTFuIUycvOMusqLFN6kP7c66Sbr2eood6F5FWIXotxqp 0/LzoYk9HF1gTUJa0K13veenwFQpSEQ30Rs5R9vdF81NDK/JeNT705ceas4jjxvKmAXb kpqA== X-Gm-Message-State: AFqh2kqgzEF/JegJ2sqIEWSiniMFn7dL61IjKx/nqqo7dEmZjP2oe/32 VxSy1EqX7kCXi0kVdCncfw1oNVBg4dDh X-Google-Smtp-Source: AMrXdXvF8lJSvZWcavK7Q1tHKy9uwBax3i34mr7oaH67rab6/l55Wb54YSMzQO04ft9SdijBc4q9I+5h24Lm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:568d:4d98:b468:b025]) (user=irogers job=sendgmr) by 2002:a25:8b82:0:b0:75e:ca27:ca65 with SMTP id j2-20020a258b82000000b0075eca27ca65mr4100382ybl.464.1674696009789; Wed, 25 Jan 2023 17:20:09 -0800 (PST) Date: Wed, 25 Jan 2023 17:18:50 -0800 In-Reply-To: <20230126011854.198243-1-irogers@google.com> Message-Id: <20230126011854.198243-9-irogers@google.com> Mime-Version: 1.0 References: <20230126011854.198243-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v4 08/12] 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 4cdbf34b7298..5f8d490c7269 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. @@ -378,24 +378,13 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.metric_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]: @@ -407,17 +396,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'): @@ -455,12 +446,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 @@ -809,7 +801,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.1.456.gfc5497dd1b-goog 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 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 545EFC54E94 for ; Thu, 26 Jan 2023 01:23:16 +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=DxZ8GuQfHQKqV2L2BK2wcyrba5TMP+mNcP6PriSmhhE=; b=inTLZg4PcaZ5ToqG84d0W88d4m 3qI/4lcTf2nDT6Wy+KhFA6VJ58V818w6PBs8Ko1D6Q1SAfwOiFQp47ItJS9fegzb/z+hhFrnciT+B bcX543tvF4RQ32vuiAk2nuYnz7u0XRP70ZDZ/JiLpZVpOb+DDrPYjrXSU++zFs5MwZ57py/OZolNY b2wUPR3Wa6Pbgu2qEpibnhKdyg9xfD0zLUmaaYU98E7y6+FCYAjIvhxuWqSvBYYWgr2rVUh3Czetv HXF/rvh+b00I2ypbm5TNKsSMrj1GsezyfAh+065Y98Ky5ZYVmdG0RNXZ94fP2hyx2FCCGiWlFxs46 Db4mXIDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKqxs-009KKu-Vo; Thu, 26 Jan 2023 01:22:10 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pKqvz-009JXy-Cc for linux-arm-kernel@lists.infradead.org; Thu, 26 Jan 2023 01:20:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-507aac99fdfso3873777b3.11 for ; Wed, 25 Jan 2023 17:20:10 -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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=szv/8QdNSp2myZhetiv+HBlEzrYqtH54GGv+4csDy6tkYmSOpnwfgd8SizPlPCYMl7 BT6unBlOqiizZhkCKtirqUKAZTutPbk+WAeKe7xm3Ow/tYJ14SOscBOib2QVMdyNR6zB 2xayHzwqsTnWj4IiJgAMl16SvkORUua1H9c/vUE/6NI79psnvhHOqeOzS3HYg3gaMmxF ru/Zv+iHMCvLUZka9TjOqZsGj5e6oa6sEttZPrLbZ1hsRpoKwaXVB4k6EPEIa0Q590Og rmo9oyt5YAwjFm/Elbc5lfpNIymEOGJkMDdEFC5+t4yLjuRfFwiR4WFccmMnSJTVuf2P RVUA== 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=rOKzY9YOyxiZd0jwhBCOLQV0VT54WWM+lqROihc/Rhw=; b=7jq0f+GH8ZIMFzTc3Xkc3s2Q48rUgRTDG1G3b/68rABOPli16Zmr0kLfmj72qR4z6b VvZFGumj5Ur18GaqVMMASSdJSl4yt+bOt5uRj1etmjHdbKAqdHvEGiCv9yYCMQDmBB3E eOG+YOOTlUYbPdwFZFvz6iW+j8bB/xFFh+8nnUAIDmKWu8BxI5HekCm4JUbZRzjas8av QhlkUA2gQZCPQE/XlNeB+6mA1qWqTmkkNAaXOIrX8xbeGZWNuq3cOT7T7bbsD8lQcgmR gs2KuCf9bcCCI+WpqgpmppOhXUAHE4G1BkGJ+2ulsZ5Ei/Xmfv3Zx4IVCHLvk+RRjeUz Nl9A== X-Gm-Message-State: AFqh2kreEmvMX4Ii2D2S+WaRFAV2wmip0bD7hUspC/nPqtQbd0SSWU5Z gXvIHBP95yXznYKJXQa0BJBk4HqlFgIQ X-Google-Smtp-Source: AMrXdXvF8lJSvZWcavK7Q1tHKy9uwBax3i34mr7oaH67rab6/l55Wb54YSMzQO04ft9SdijBc4q9I+5h24Lm X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:568d:4d98:b468:b025]) (user=irogers job=sendgmr) by 2002:a25:8b82:0:b0:75e:ca27:ca65 with SMTP id j2-20020a258b82000000b0075eca27ca65mr4100382ybl.464.1674696009789; Wed, 25 Jan 2023 17:20:09 -0800 (PST) Date: Wed, 25 Jan 2023 17:18:50 -0800 In-Reply-To: <20230126011854.198243-1-irogers@google.com> Message-Id: <20230126011854.198243-9-irogers@google.com> Mime-Version: 1.0 References: <20230126011854.198243-1-irogers@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Subject: [PATCH v4 08/12] 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-20230125_172011_493645_B8E2FEB7 X-CRM114-Status: GOOD ( 14.98 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 4cdbf34b7298..5f8d490c7269 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. @@ -378,24 +378,13 @@ def preprocess_arch_std_files(archpath: str) -> None: _arch_std_events[event.metric_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]: @@ -407,17 +396,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'): @@ -455,12 +446,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 @@ -809,7 +801,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.1.456.gfc5497dd1b-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel