From patchwork Fri Jan 21 16:22:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12719909 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 5D727C433EF for ; Fri, 21 Jan 2022 16:26:52 +0000 (UTC) Received: from localhost ([::1]:39458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAwkV-0002qj-EG for qemu-devel@archiver.kernel.org; Fri, 21 Jan 2022 11:26:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwi1-0000bN-H7 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:17 -0500 Received: from mail-eopbgr50098.outbound.protection.outlook.com ([40.107.5.98]:38734 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwhU-0007rD-5d for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hxjc86Qe1m1kDbSpiNI6o4gm5YWLZ2LORFY3O7mI35h3rzYZbNMcsTH9DdRDZ3fFwhQzT/sKUnj51SN4B4Hd+Xx3mJXASRwfubK3h4uICFTnrrZy9y3Xn6K8FKRIjcF3H7Tep9jrRTGZ9zqb46gnTPmeTIkOM7ifQFhuxB6ofTSo/vsV3fyzRprFNitRJIT0kk87yhiTlSaklfmQYSUVVWczcaY+DbKV/iyKUXc07BmEIeAZAZgXUeiR9/z2PyMyawDIKToFJ9TRvevfrJRV0uSH1kK51RCw1F+uUhmkp5dMEURM3SwalcsuJ1k7Fuiw5ElZNFp4FpAiSUma6wzxaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bBcUE/FLNOpct4OXcXqZfC7bup3p46R64G9/1ABkaMQ=; b=OmX345uP8QT/jFoTTdOGujkCZWRYZXmI6zpNSsuzA5qh4YNpYqqQbxqjtoO75qB9BEcbSvhVUjIroxj4EXwCDze6KJUGviFPi91VPFaDO2pdhVtVosY/1ZE69QRrBHU7lSfF5IbM+R176jmOMrSpImZ/06mc+NvhFPx0gJarLtzzVAdlf6A+CH/4x0v0ObEd0m1yypsxzQEErboULpQVXQEB4Ais1Dd86+SacklGhnh3ih8FsiK7qFApqPEAUbNmK/5KJKU4MWrd1cEEQocEtckXWOSIVJbGqfyAmqHFhQ97eubGQMa9KwMVUwxezH1LASkHqSCgpSLkttrZUQdyWQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bBcUE/FLNOpct4OXcXqZfC7bup3p46R64G9/1ABkaMQ=; b=R4InWrHuQf1WgUzOPFIeCQZpzKZOx3hrDsCuFM/obE5AeE5HaVC2WaLlCHdLHOyzq/+5dDliFcBy0r1DOHUwa1XL7Zhcu14CstWRsRcHy+UFyFnofFfhoYo3kk1HwHrxq6knkTjOx/sKICKJUpvZyIvCPuCMX7kp8m8L0OJRD/g= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB4006.eurprd08.prod.outlook.com (2603:10a6:20b:a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Fri, 21 Jan 2022 16:22:46 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd%3]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 16:22:46 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, michael.roth@amd.com, armbru@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com Subject: [PATCH v4 1/3] scripts/qapi/gen.py: add FOO.trace-events output module Date: Fri, 21 Jan 2022 17:22:32 +0100 Message-Id: <20220121162234.2707906-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121162234.2707906-1-vsementsov@virtuozzo.com> References: <20220121162234.2707906-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0402CA0016.eurprd04.prod.outlook.com (2603:10a6:203:90::26) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 51dabd59-3272-44b1-1168-08d9dcfa4284 X-MS-TrafficTypeDiagnostic: AM6PR08MB4006:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fW9Mzelo5HV8sox3AGxdAy5wbYz7C6IBCsaZcbPjYPMXK11rK0u7XrS8hiy/Tck8128zgRIVAaBrGw1AwufMX1Rn9Ft0rljp+WDm8KWonYb3JtLw1/d9CDQkvAY+FjU/zZic0haAxRq/KXSvroxKReO6WSZJNoRjpqfoAZ5KbK+SogiSIA+gvM2DAVSCav3LOuAmxt3xwwF+8O86bQjzqvi1x1O6aPc9gF2X5Wi5JqFyLfZr+ZFQwTed1L6Egy643yztNSYIMPtijmHGaBrAZlF1IyfdZ0MRnQlsAzzLyY1h9XV0xRSlPcTofmTfodWfA1oY30Q85pF9LXVncCa2HI5AcNNu0aR5aSWYl7K2vikG6oPAQl0OHYXhtQA95jkrFadSL6KROLe8tstrMouBH1DRei193pkA8ruvlBEpc7UXg6/NIpekmkpkHKrZtzfmOdSgYOf5xTwaOnNLWtCfTovePWS/KdkPtzUljIUvPdllyd/smFk3RmUmfK3NyDr6WWjqpQ/bvKiPwSIWlXuNINVgkizk6pAXIYzJ/M/Vn1ot6BmOFdCnURhgzJCVMiL1vVJYy+EXZZmWrLIw0q1OFaMwHIrejjcoxYhl6RkMwnT9DMCwk6aI8A+7eumV0pqO9g6qXBKheOFnbn+AiVWCJr3iHmFLwkQ4e/MJbDazyb7SwLqm6qurWzQN1sdjNjEXQc/P6rPS00lgoX7kUCp1Og== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(52116002)(6916009)(2616005)(2906002)(6486002)(6512007)(316002)(8676002)(186003)(8936002)(26005)(508600001)(66946007)(66556008)(66476007)(4326008)(83380400001)(6666004)(5660300002)(38100700002)(38350700002)(86362001)(6506007)(1076003)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-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IQVHqyBW9ZLFQ+quMUnsq0evkhNSFR0kQM5iWb4hvIcVhBKQkwNBkMwg4qT0TOEpZTHz7wWGjHZWHhhF1xcH9ecFZkWDosJRB6WGYIQ87maao4uU1xIZFnZ1jwovyg6OQibbn85P/+cH9zlpEO9MROIunjJaGMt7hRxg4+wC9tIyXpWUJKQLqRV/mE9X5QM3eYtyeHdU7fa+brf3HRy/eX9YN3Au0s1alUN1I+NM76qM95w/WR4i88J9DYgPOzK3+38X1zLAZQ0fMghuCgGM3lXdN/wxqM+o7lkK4acl/9Fkl4ZPl6o/apmrmDf2EpYkH0FCbI4/dDvPmqIWSVyonkszuKXHuG0Ru6a+LOb6j9/OXuEleseXJ/hc76km8devpNOa9Mk7IxGXryD5rC7ZnlCDsMhpixjqHvEr6KMsJqvP8YR9vK0VXikNG9rra2o17ZXm7hQKHkPeUlN/IHRDWuqnN5zKY/NDQYE0i9uiqR319dr0UlS9wwMRyQi5EOJjiT6onZqAi523g6Zfo8cobO7veOuaBSBomvp8TtfI20MKjzLZQZtdR75sqYWuq2WIwOun0JxiR6IoWKzY/7WdU6hNPRB0dBe42gCcVllw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51dabd59-3272-44b1-1168-08d9dcfa4284 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2022 16:22:46.7698 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: npP/uFrVzw9ubKGVtuFCUE2wOQMkNNcGpZCm9xHJUR9IMnIg4y4ozdoLLXhvHhSx8MvYKFAeSAztXYe1if0znMXBcqy1z+6oYnO9CnpzeSY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4006 Received-SPF: pass client-ip=40.107.5.98; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We are going to generate trace events for qmp commands. We should generate both trace_*() function calls and trace-events files listing events for trace generator. So, add an output module FOO.trace-events for each FOO schema module. Still, we'll need these .trace-events files only for QAPISchemaGenCommandVisitor successor of QAPISchemaModularCVisitor. So, make this possibility optional, to avoid generating extra empty files for all other successors of QAPISchemaModularCVisitor. We can't simply add the new feature directly to QAPISchemaGenCommandVisitor: this means we'll have to reimplement a kind of ._module / .write() functionality of parent class in the successor, which seems worse than extending base class functionality. Currently nobody set add_trace_events to True, so new functionality is formally disabled. It will be enabled for QAPISchemaGenCommandVisitor in further commit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- scripts/qapi/gen.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 995a97d2b8..def52f021e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -192,6 +192,11 @@ def _bottom(self) -> str: return guardend(self.fname) +class QAPIGenTrace(QAPIGen): + def _top(self): + return super()._top() + '# AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n' + + @contextmanager def ifcontext(ifcond: QAPISchemaIfCond, *args: QAPIGenCCode) -> Iterator[None]: """ @@ -244,15 +249,18 @@ def __init__(self, what: str, user_blurb: str, builtin_blurb: Optional[str], - pydoc: str): + pydoc: str, + add_trace_events: bool = False): self._prefix = prefix self._what = what self._user_blurb = user_blurb self._builtin_blurb = builtin_blurb self._pydoc = pydoc self._current_module: Optional[str] = None - self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH]] = {} + self._module: Dict[str, Tuple[QAPIGenC, QAPIGenH, + Optional[QAPIGenTrace]]] = {} self._main_module: Optional[str] = None + self.add_trace_events = add_trace_events @property def _genc(self) -> QAPIGenC: @@ -264,6 +272,14 @@ def _genh(self) -> QAPIGenH: assert self._current_module is not None return self._module[self._current_module][1] + @property + def _gent(self) -> QAPIGenTrace: + assert self.add_trace_events + assert self._current_module is not None + gent = self._module[self._current_module][2] + assert gent is not None + return gent + @staticmethod def _module_dirname(name: str) -> str: if QAPISchemaModule.is_user_module(name): @@ -293,7 +309,12 @@ def _add_module(self, name: str, blurb: str) -> None: basename = self._module_filename(self._what, name) genc = QAPIGenC(basename + '.c', blurb, self._pydoc) genh = QAPIGenH(basename + '.h', blurb, self._pydoc) - self._module[name] = (genc, genh) + if self.add_trace_events: + gent = QAPIGenTrace(basename + '.trace-events') + else: + gent = None + + self._module[name] = (genc, genh, gent) self._current_module = name @contextmanager @@ -304,11 +325,13 @@ def _temp_module(self, name: str) -> Iterator[None]: self._current_module = old_module def write(self, output_dir: str, opt_builtins: bool = False) -> None: - for name, (genc, genh) in self._module.items(): + for name, (genc, genh, gent) in self._module.items(): if QAPISchemaModule.is_builtin_module(name) and not opt_builtins: continue genc.write(output_dir) genh.write(output_dir) + if gent is not None: + gent.write(output_dir) def _begin_builtin_module(self) -> None: pass From patchwork Fri Jan 21 16:22:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12719943 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 1D517C433EF for ; Fri, 21 Jan 2022 16:58:04 +0000 (UTC) Received: from localhost ([::1]:47632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAxEg-0001On-SL for qemu-devel@archiver.kernel.org; Fri, 21 Jan 2022 11:58:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwi5-0000lj-CQ for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:21 -0500 Received: from mail-eopbgr50116.outbound.protection.outlook.com ([40.107.5.116]:56897 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwi1-0007uB-1b for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:21 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MZTvqrSV9KvUEobVhYRpA8zoAQA2tRdkM7OAAYhwuuI+BlV4alRu9Z4qcb4tiynUGvf1cruWF+e/ieLYv1US0G9H5KRR/e8wPO22Sc+PUWwz/V0Pmyz9Xfj/TsMyOc2M0g8KH4F+0z+/pTLTMkdHGZfQjOFKWThx9U4RUWO/VJ20z5jeaWGJ9ztmHeMh6TOFDuX5y8jzAkf0ur6c/BhTX6/HytJyekQcUtquJF2aPGrf+oP8ysLvfG1hUgnJkYNlBhDZLPeBvxBplE9A446fUffTWqoB6srajY4S46sXngX9tGEBDC6g5a8DNc2iYyF6hFfRIoFd/duhXuj31gNATg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UL9d17bkrrBC2Ut3TwPO06SZgPV56BpBIHAMLUk7p9A=; b=Ln3L6uarGBP/bb8rCFd+cpuJlz2q15BMk6MWZ6vs2I+22hnoo2gThEAQvQEVEVLmL6CHmnMaut/Ewb82KqAMu3vmI56D1sSweeVpNJzuG9/on+l3vBxeHRoEkKFwHE/qLL478st3VkkD4V/OcEM/4oZzVPM7KldSeZ5LLrjiuk7J7USy1SCf9rGeUA441vzIwCDEB57gdLoZA1nWCaY3XlBB+2AgRQDEfadC42EQJWL973hDKKy+LwdNbBt4tLpbx82ls89fpcLgb4YTBm4guFTnE1H/XHL+JY8M1W6zIKrQemATy1bTRe+RkHDvMY+21JLNvttCry/3D63Y1RVp+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UL9d17bkrrBC2Ut3TwPO06SZgPV56BpBIHAMLUk7p9A=; b=nv37P/vZfnBslYIxtT7R1Ff1tc26nHg0DIpCyLCjwtWwT8SriTKxAbC6sQqIdz0A29EyHTPEJyQ+0TrgV08soOSeKSNnjZNiDY6wky+J3B1dKsKmGNitn20RcPD5F9AQZTy+QkroWGApGapiRtiiiLcTTS/uC7IC3qrot8tc9XY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB4006.eurprd08.prod.outlook.com (2603:10a6:20b:a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Fri, 21 Jan 2022 16:22:47 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd%3]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 16:22:47 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, michael.roth@amd.com, armbru@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com Subject: [PATCH v4 2/3] scripts/qapi/commands: gen_commands(): add add_trace_events arg Date: Fri, 21 Jan 2022 17:22:33 +0100 Message-Id: <20220121162234.2707906-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121162234.2707906-1-vsementsov@virtuozzo.com> References: <20220121162234.2707906-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0402CA0016.eurprd04.prod.outlook.com (2603:10a6:203:90::26) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b00d1fa-7bcd-45eb-91c8-08d9dcfa42d2 X-MS-TrafficTypeDiagnostic: AM6PR08MB4006:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:102; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5pVPBdOMU6P8abUl59NhBRTj2opwR6xBrt1w5/XnSB+xeLtXJclBGpFfPSu/CJcWR0NWzX4u1WpoTxF/aCrheuymqigXPIJsCEkFRLef7vJZUgtWcwJnIvYKrA7Tf1aYbEK2vr4WWyZX2/tE33ydPLgDjPatRJvp7Yc8/1HtENja2CbwvoTAwFyvnO1e78J06O8Bpo3qT8PdCHIki+p8bjbm2fcSx6waX3zKx6Gw9iGZzA6QXch+yvQ4zkBhZZE/rJzNYkz8JKFKuV69W6RflLg/vtr9bQCKKENxZXUo57719UcQMfaQ0ylSWJE652tEeMynTO/WfJ81++6S8VaVoSVKvry3qpT+oZU1pYYCXxNsCgr+MWyEVRCsZO0Z7szE9F+X0rZ4pBoJ4y4bp1jn58ZPOxATwKlQJG8p6CaykPrM6O8z/1u2c3szmbg4f/2mk9iHeUtRbbgZthRJKJYPuQCDI/ayCxtMgN5uCBKGjixcBJlCVPdPkg/cSyBOf+X/7yOo3BxOMcnStAMZkm7+lm07iiaAYf9iMXYeqwGvtxuBELCGP9dXx8XUMPNtk1GYUxzXjgr/rCagwnO4QZ6ypooLjzWR181wIy6A4uVcsKWo4FqMTE6sLv4tnVjSzzFRBAnU3Ee5AiQRTmABIATGIdG1MT/FfwP/lcqTRNjGi7hNDIjd+V6UkRkW+YMu1DlJOLnnLcAcgL6T6QJ9okxAAQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(52116002)(6916009)(2616005)(2906002)(6486002)(6512007)(316002)(8676002)(186003)(8936002)(26005)(508600001)(66946007)(66556008)(66476007)(4326008)(83380400001)(6666004)(5660300002)(38100700002)(38350700002)(86362001)(6506007)(1076003)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V1D8X1XcvgfF/er2GsfE021KXXOJqHvfmd0+/PlT3PsL+Rm/UJYChGPfyaFWGMwDSUm8EfeeU2c9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4sLftB3AdcrsK0n0kxdOtwtgpGz/sZTp0aW8xYr2o9Cppt7PiMsdjtF65KV+NYmlzuq+w2m9V4nFm2E5nVw0gSjnPdXHIvXiQ1XUdId/JVTUQqagIAae8AufcY/RoGBvTe5f31H66nZ1ae/K4KyVgOGwqk6QIv9PJV0jxjrc/pho4P4fvxXtmmDgj7PkZpWAG4aahjgcCaTRfyo/2InygakUVQgNONCc6H6xsne8PPM1GN3kokWHW/vebEHXfWngfTrHu+8mlSqp2jEAqj8WfHjcIC8YeLXWCcCqkBgCuqiMDTeVNlUB9zW2fay4ukiUpjRWirCHz87fbxIqvtmbncD81WvAylXgjarADGZSJvImx+ieGNr9fok+VDbYYrx67jnBxcQsU/jEtuKnWqMUdSZQghGKfcH1gs61YlqeVeLg7yWSn5Ak2wtqaL8t7NYXHEb+0HYmjpAjUhNAcEyUBV6lnOvt2wQWqY2VMljIysRYqOrWpVl9mnzkH36g1aFT5siYdtvuZ+1mHj8l/tTDJ5tXm/bBQnLwdkMCqXq7/U= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b00d1fa-7bcd-45eb-91c8-08d9dcfa42d2 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2022 16:22:47.1760 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5HrmTJwU/GneTlVP+w2vz+KZNVwi3KXBAnAb35WWJBC2xmwyimNuh3M5nSIOZCncaqhQ//S6UTkGL0ddKn4ljUvyTSkO5A6/3UvyRIFEojc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4006 Received-SPF: pass client-ip=40.107.5.116; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We are going to generate trace events for qmp commands. We should generate both trace_*() function calls and trace-events files listing events for trace generator. Now implement that possibility in gen_commands() function. The functionality will be used in the following commit, and now comment in _begin_user_module() about c_name() is a bit premature. Signed-off-by: Vladimir Sementsov-Ogievskiy --- scripts/qapi/commands.py | 101 +++++++++++++++++++++++++++++++++------ scripts/qapi/main.py | 2 +- 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 21001bbd6b..166bf5dcbc 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -53,7 +53,8 @@ def gen_command_decl(name: str, def gen_call(name: str, arg_type: Optional[QAPISchemaObjectType], boxed: bool, - ret_type: Optional[QAPISchemaType]) -> str: + ret_type: Optional[QAPISchemaType], + add_trace_events: bool) -> str: ret = '' argstr = '' @@ -71,21 +72,67 @@ def gen_call(name: str, if ret_type: lhs = 'retval = ' - ret = mcgen(''' + name = c_name(name) + upper = name.upper() - %(lhs)sqmp_%(c_name)s(%(args)s&err); - error_propagate(errp, err); -''', - c_name=c_name(name), args=argstr, lhs=lhs) - if ret_type: + if add_trace_events: ret += mcgen(''' + + if (trace_event_get_state_backends(TRACE_QMP_ENTER_%(upper)s)) { + g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args)); + + trace_qmp_enter_%(name)s(req_json->str); + } + ''', + upper=upper, name=name) + + ret += mcgen(''' + + %(lhs)sqmp_%(name)s(%(args)s&err); +''', + name=name, args=argstr, lhs=lhs) + + ret += mcgen(''' if (err) { +''') + + if add_trace_events: + ret += mcgen(''' + trace_qmp_exit_%(name)s(error_get_pretty(err), false); +''', + name=name) + + ret += mcgen(''' + error_propagate(errp, err); goto out; } +''') + + if ret_type: + ret += mcgen(''' qmp_marshal_output_%(c_name)s(retval, ret, errp); ''', c_name=ret_type.c_name()) + + if add_trace_events: + if ret_type: + ret += mcgen(''' + + if (trace_event_get_state_backends(TRACE_QMP_EXIT_%(upper)s)) { + g_autoptr(GString) ret_json = qobject_to_json(*ret); + + trace_qmp_exit_%(name)s(ret_json->str, true); + } + ''', + upper=upper, name=name) + else: + ret += mcgen(''' + + trace_qmp_exit_%(name)s("{}", true); + ''', + name=name) + return ret @@ -122,10 +169,19 @@ def gen_marshal_decl(name: str) -> str: proto=build_marshal_proto(name)) +def gen_trace(name: str) -> str: + return mcgen(''' +qmp_enter_%(name)s(const char *json) "%%s" +qmp_exit_%(name)s(const char *result, bool succeeded) "%%s %%d" +''', + name=c_name(name)) + + def gen_marshal(name: str, arg_type: Optional[QAPISchemaObjectType], boxed: bool, - ret_type: Optional[QAPISchemaType]) -> str: + ret_type: Optional[QAPISchemaType], + add_trace_events: bool) -> str: have_args = boxed or (arg_type and not arg_type.is_empty()) if have_args: assert arg_type is not None @@ -180,7 +236,7 @@ def gen_marshal(name: str, } ''') - ret += gen_call(name, arg_type, boxed, ret_type) + ret += gen_call(name, arg_type, boxed, ret_type, add_trace_events) ret += mcgen(''' @@ -238,11 +294,13 @@ def gen_register_command(name: str, class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): - def __init__(self, prefix: str): + def __init__(self, prefix: str, add_trace_events: bool): super().__init__( prefix, 'qapi-commands', - ' * Schema-defined QAPI/QMP commands', None, __doc__) + ' * Schema-defined QAPI/QMP commands', None, __doc__, + add_trace_events=add_trace_events) self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] = {} + self.add_trace_events = add_trace_events def _begin_user_module(self, name: str) -> None: self._visited_ret_types[self._genc] = set() @@ -261,6 +319,17 @@ def _begin_user_module(self, name: str) -> None: ''', commands=commands, visit=visit)) + + if self.add_trace_events and commands != 'qapi-commands': + self._genc.add(mcgen(''' +#include "trace/trace-qapi.h" +#include "qapi/qmp/qjson.h" +#include "trace/trace-%(nm)s_trace_events.h" +''', + nm=c_name(commands, protect=False))) + # We use c_name(commands, protect=False) to turn '-' into '_', to + # match .underscorify() in trace/meson.build + self._genh.add(mcgen(''' #include "%(types)s.h" @@ -322,7 +391,10 @@ def visit_command(self, with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_command_decl(name, arg_type, boxed, ret_type)) self._genh.add(gen_marshal_decl(name)) - self._genc.add(gen_marshal(name, arg_type, boxed, ret_type)) + self._genc.add(gen_marshal(name, arg_type, boxed, ret_type, + self.add_trace_events)) + if self.add_trace_events: + self._gent.add(gen_trace(name)) with self._temp_module('./init'): with ifcontext(ifcond, self._genh, self._genc): self._genc.add(gen_register_command( @@ -332,7 +404,8 @@ def visit_command(self, def gen_commands(schema: QAPISchema, output_dir: str, - prefix: str) -> None: - vis = QAPISchemaGenCommandVisitor(prefix) + prefix: str, + add_trace_events: bool) -> None: + vis = QAPISchemaGenCommandVisitor(prefix, add_trace_events) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index f2ea6e0ce4..2e61409f04 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -49,7 +49,7 @@ def generate(schema_file: str, schema = QAPISchema(schema_file) gen_types(schema, output_dir, prefix, builtins) gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix) + gen_commands(schema, output_dir, prefix, False) gen_events(schema, output_dir, prefix) gen_introspect(schema, output_dir, prefix, unmask) From patchwork Fri Jan 21 16:22:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12719911 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.gnu.org (lists.gnu.org [209.51.188.17]) (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 0084EC433EF for ; Fri, 21 Jan 2022 16:29:16 +0000 (UTC) Received: from localhost ([::1]:45006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAwmq-0006hj-11 for qemu-devel@archiver.kernel.org; Fri, 21 Jan 2022 11:29:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58400) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwi8-0000tv-G5 for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:24 -0500 Received: from mail-eopbgr50098.outbound.protection.outlook.com ([40.107.5.98]:38734 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAwi1-0007rD-Gc for qemu-devel@nongnu.org; Fri, 21 Jan 2022 11:24:24 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HaWQBBo6rWhEHFpt0aOZptfXgYqlYuPnG3BUfDZpHpGK1+/xdC7GsOqknDfpbMVS0U3zyfASsp9BsePkynb7558feJKNazQ3t78ZlUGYbgOMf7HE/jt78dWe23iKKjYvusvTzGarlhso8RWBnYFMMyt14QmBTAEvkLNWoLimL8S+3Gbu8l68Vx1gS2SXS+dohwKKcLhie+d0yIMIZrHkTmDzv0OqiCS7VQBnIRUk+t7YmEradBpT45d7QC4XioTsTGUZCSOdrA0q0tdm8FafWb452orkJUZZp5e66R9D5stxzaq9TDyk7lqtMXz/7tlJXcUdu6bVkgPwd2B6sQeuuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=S1S1zeiQ1YayZ59HwuJKdygmzD0H0zpAnUGGEopecOg=; b=H90y6DJUKJ7b21FJZ6UVFcHce+AYe6MqRwDHollKAO7OTIaXvOr0Icl4OVx0Y9kYL/drxMpM3QO56ELL71tIp4AjR5t4DwvLPLI3//j6zwq+Lp+h5EPuf8AshNLYm2KZinP2gb6JRCcO6Zo/glc7G5aBBvoSCT/JDlD9KhFl3w3/oEA3mit0xnqvVhqj7kIemxjHolD/pDTXS73KIYvXOqUM11N0XKdbXdvlO+WOSBI1jKNu0lGoNcKH3jxADu2WnauaySFHMvJEtwR4PvXNu4atmaXttGxrz1abPml6oD/2r5E4ARSYTH9m12mqbXcIEwNEgHioK/bT2ifU4MUzlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1S1zeiQ1YayZ59HwuJKdygmzD0H0zpAnUGGEopecOg=; b=iZZBFq3nbuZlLxgFjam0kdWlNIRzruxMy8lKbLHx65sikq4+a8ltcA/QsCUgC0ZrKpTuQwGzXNGXEU0pnR6Omuhz/Njj2CTPzRU2H1mkTrKOKf4i2uy+ScYqoMX2QBRjlLnx7wV94AcLVXKWtjIujguAP/BYL9zwMoEkBGrPz0g= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM6PR08MB4006.eurprd08.prod.outlook.com (2603:10a6:20b:a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4909.10; Fri, 21 Jan 2022 16:22:47 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::4def:4b08:dfe6:b4bd%3]) with mapi id 15.20.4909.012; Fri, 21 Jan 2022 16:22:47 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, michael.roth@amd.com, armbru@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com, pbonzini@redhat.com Subject: [PATCH v4 3/3] meson: generate trace events for qmp commands Date: Fri, 21 Jan 2022 17:22:34 +0100 Message-Id: <20220121162234.2707906-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220121162234.2707906-1-vsementsov@virtuozzo.com> References: <20220121162234.2707906-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0402CA0016.eurprd04.prod.outlook.com (2603:10a6:203:90::26) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e456217c-884e-4a8c-b5b0-08d9dcfa4315 X-MS-TrafficTypeDiagnostic: AM6PR08MB4006:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aUrBv1bsx96WUnNEB5WreL9zXWaiqwOyPF1z/j54Xq1GDhe5NkI0FC4H916dbNQmdM4PUXyKKMKLNOLQ92NOVYQmRLnDWGRwRY6+BZi52Z5yrjL1JIEKbq5lx+tMHncSk+30hgLH0T2fJsbploZTaDfQDocMwNgTtKvAIhuGK9ZtuTCok0O8mcdDIs5fDScnA2pb6z2nEMs5gbfB2YZ4mYV7WnbREWhLYxfJaW4186VeQdVFbTfBnzCcmYTZtruzgxD4L412AfYBvJ7jv7LP1H1gXxY1Q5XAcXPbURk/jOs7oBb0Fi1LtHsQ2J3Bay0B+pTxszCHWrVL6PuSNoaHYnx73SXOKEasrRr4DDohoUELJIwSoY6Mwm8jEFTcq/FbD9G40xSqU29FRgVIEgo+h6qvaqLoHgk1Ip4WMPeXBYjYFIoI4y9zAiCcCxKGw+6Sgg+4oq60vOOV+434UekI64MlmfM5n0Bc+azDeC1AA05k8Jh5DketqG+HY356aAKwEgFLeJEeFAvJS3GiKGs2bCYPjW7zHZV4yajDyRmyGw5a1hE7rXPRAobPMhKp9oSCHmZHo6fgEHotVX9kYjC/BE50r1DEoS0fuyGMo7iUEft0emPoyUlifuXCC1q4NAcf9SAiYRPigsQDs/UiK36qbD8R8gY8QwHaauqJST46M89SNvokpMVBVsUadJwow4uK6WI77nu9lUId/PTxrVKdcw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(52116002)(6916009)(2616005)(2906002)(6486002)(6512007)(316002)(8676002)(186003)(8936002)(26005)(508600001)(66946007)(66556008)(66476007)(4326008)(83380400001)(6666004)(5660300002)(38100700002)(38350700002)(86362001)(6506007)(1076003)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exch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qhT4pH2WMw5AdAnBes30Rgxprb2NMCuJtPEfJ/UZr1bScXz0LJRwK0m6mIG2XNywCjW+VVVbo/AEPKxbkDP6wXrtEigUoDCvB2tcmiWbjuU9MdxT4RXZSFnEp+5D8hUuSkJunv5P2Wcdctt/xYBd29LVKkF9FkcvZsi5b8okMF3HJDLImjTXsaiQa8As7S8ZumbMhjvAPp4mVtbHv02vHcUXGb5KRjlmvdz+PJKK8dAfadLu0ZDNfOHuQpJ9HK4SOUJRvnkJWHDyM4aY0T8cmBYKRfFKG1fI0HWiG525JI7PhJMu4Dqq5TuplQdPbL9BszgRyI6tXSxokwZGUvJ5KN6LK1uWHTNqQ9RJIhk4VWmKAnVN8f7D0b4zqM1eCr9x29bWJQuyZyZKpPkH6LWT6dZwCey3vBbb3n6QR5nKg+S4Ve+m6lHgV6chLhdJbsAU3OrojSYvpmxzqUJgc1JCWZKulHhYXTXhiRw19HQN50tLdegwUm/VsHH1TQEDgCdOmYhNfuSfLDLMueu9o4/hvv0Pdmjq40n2Ef7Gm5rkQzZ6daqzenxMGKzP8nHojwf3tdmyOS0iTrC3mOJIvCSVlja15aqxeVnUXig/SS2LOfNEDRkvjgiHob6lNhJ3urri8g= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e456217c-884e-4a8c-b5b0-08d9dcfa4315 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jan 2022 16:22:47.6316 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BoLd1rN9QLB+F+jDu4prMnB8DpFZpOqZZEkr005zVqfiivT5hPzA/ThUNzQbDZTTun+f6FrTrknH9yNThdbcr7LoGK8xeuzEwr6Eq4A+LvY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4006 Received-SPF: pass client-ip=40.107.5.98; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 1. Add --no-trace-events to suppress trace events generation in some cases, and make trace events be generated by default. 2. Add corresponding .trace-events files as outputs in qapi_files custom target 3. Define global qapi_trace_events list of .trace-events file targets, to fill in trace/qapi.build and to use in trace/meson.build 4. In trace/meson.build use the new array as an additional source of .trace_events files to be processed Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: John Snow --- docs/devel/qapi-code-gen.rst | 23 +++++++++++++++++++++-- meson.build | 3 +++ qapi/meson.build | 7 +++++++ qga/meson.build | 11 ++++++++++- scripts/qapi/main.py | 10 +++++++--- tests/meson.build | 11 ++++++++++- trace/meson.build | 11 ++++++++--- 7 files changed, 66 insertions(+), 10 deletions(-) diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index a3b5473089..a3430740bd 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -1619,7 +1619,10 @@ Code generated for commands These are the marshaling/dispatch functions for the commands defined in the schema. The generated code provides qmp_marshal_COMMAND(), and -declares qmp_COMMAND() that the user must implement. +declares qmp_COMMAND() that the user must implement. The generated code +contains trace events code. Corresponding .trace-events file with list +of trace events is generated too, and should be parsed by trace generator +later to generate trace event code, see `tracing `. The following files are generated: @@ -1630,6 +1633,9 @@ The following files are generated: ``$(prefix)qapi-commands.h`` Function prototypes for the QMP commands specified in the schema + ``$(prefix)qapi-commands.trace-events`` + Trace events file for trace generator, see `tracing `. + ``$(prefix)qapi-init-commands.h`` Command initialization prototype @@ -1689,14 +1695,27 @@ Example:: goto out; } + if (trace_event_get_state_backends(TRACE_QMP_ENTER_MY_COMMAND)) { + g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args)); + + trace_qmp_enter_my_command(req_json->str); + } + retval = qmp_my_command(arg.arg1, &err); - error_propagate(errp, err); if (err) { + trace_qmp_exit_my_command(error_get_pretty(err), false); + error_propagate(errp, err); goto out; } qmp_marshal_output_UserDefOne(retval, ret, errp); + if (trace_event_get_state_backends(TRACE_QMP_EXIT_MY_COMMAND)) { + g_autoptr(GString) ret_json = qobject_to_json(*ret); + + trace_qmp_exit_my_command(ret_json->str, true); + } + out: visit_free(v); v = qapi_dealloc_visitor_new(); diff --git a/meson.build b/meson.build index 833fd6bc4c..e0cfafe8d9 100644 --- a/meson.build +++ b/meson.build @@ -41,6 +41,7 @@ qemu_icondir = get_option('datadir') / 'icons' config_host_data = configuration_data() genh = [] +qapi_trace_events = [] target_dirs = config_host['TARGET_DIRS'].split() have_linux_user = false @@ -2557,6 +2558,8 @@ if 'CONFIG_VHOST_USER' in config_host vhost_user = libvhost_user.get_variable('vhost_user_dep') endif +# NOTE: the trace/ subdirectory needs the qapi_trace_events variable +# that is filled in by qapi/. subdir('qapi') subdir('qobject') subdir('stubs') diff --git a/qapi/meson.build b/qapi/meson.build index c0c49c15e4..656ef0e039 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -114,6 +114,7 @@ foreach module : qapi_all_modules 'qapi-events-@0@.h'.format(module), 'qapi-commands-@0@.c'.format(module), 'qapi-commands-@0@.h'.format(module), + 'qapi-commands-@0@.trace-events'.format(module), ] endif if module.endswith('-target') @@ -137,6 +138,9 @@ foreach output : qapi_util_outputs if output.endswith('.h') genh += qapi_files[i] endif + if output.endswith('.trace-events') + qapi_trace_events += qapi_files[i] + endif util_ss.add(qapi_files[i]) i = i + 1 endforeach @@ -145,6 +149,9 @@ foreach output : qapi_specific_outputs + qapi_nonmodule_outputs if output.endswith('.h') genh += qapi_files[i] endif + if output.endswith('.trace-events') + qapi_trace_events += qapi_files[i] + endif specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: qapi_files[i]) i = i + 1 endforeach diff --git a/qga/meson.build b/qga/meson.build index cfb1fbc085..1f2818a1b9 100644 --- a/qga/meson.build +++ b/qga/meson.build @@ -15,10 +15,19 @@ qga_qapi_outputs = [ 'qga-qapi-visit.h', ] +# We don't generate trace-events, just because it's not simple. For do it, +# we also should add .trace-events file into qga_qapi_outputs, and than +# add corresponding element of qga_qapi_files into qapi_trace_events +# global list, which is processed than in trace/meson.build. +# This means, that we'll have to move subdir('qga') above subdir('trace') +# in root meson.build. But that in turn will break the dependency of +# qga on qemuutil (which depends on trace_ss). +# So, resolving these dependencies and drop --no-trace-events is a TODO. qga_qapi_files = custom_target('QGA QAPI files', output: qga_qapi_outputs, input: 'qapi-schema.json', - command: [ qapi_gen, '-o', 'qga', '-p', 'qga-', '@INPUT0@' ], + command: [ qapi_gen, '-o', 'qga', '-p', 'qga-', '@INPUT0@', + '--no-trace-events' ], depend_files: qapi_gen_depends) qga_ss = ss.source_set() diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index 2e61409f04..d53e5b800c 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -32,7 +32,8 @@ def generate(schema_file: str, output_dir: str, prefix: str, unmask: bool = False, - builtins: bool = False) -> None: + builtins: bool = False, + add_trace_events: bool = False) -> None: """ Generate C code for the given schema into the target directory. @@ -49,7 +50,7 @@ def generate(schema_file: str, schema = QAPISchema(schema_file) gen_types(schema, output_dir, prefix, builtins) gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix, False) + gen_commands(schema, output_dir, prefix, add_trace_events) gen_events(schema, output_dir, prefix) gen_introspect(schema, output_dir, prefix, unmask) @@ -74,6 +75,8 @@ def main() -> int: parser.add_argument('-u', '--unmask-non-abi-names', action='store_true', dest='unmask', help="expose non-ABI names in introspection") + parser.add_argument('--no-trace-events', action='store_true', + help="suppress adding trace events to qmp marshals") parser.add_argument('schema', action='store') args = parser.parse_args() @@ -88,7 +91,8 @@ def main() -> int: output_dir=args.output_dir, prefix=args.prefix, unmask=args.unmask, - builtins=args.builtins) + builtins=args.builtins, + add_trace_events=not args.no_trace_events) except QAPIError as err: print(f"{sys.argv[0]}: {str(err)}", file=sys.stderr) return 1 diff --git a/tests/meson.build b/tests/meson.build index 3f3882748a..b4b95cc198 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -31,13 +31,22 @@ test_qapi_outputs = [ 'test-qapi-visit.h', ] +# We don't generate trace-events, just because it's not simple. For do it, +# we also should add .trace-events file into test_qapi_outputs, and than +# add corresponding element of test_qapi_files into qapi_trace_events +# global list, which is processed than in trace/meson.build. +# This means, that we'll have to move subdir('tests') above subdir('trace') +# in root meson.build. But that in turn will break the dependency of +# tests on qemuutil (which depends on trace_ss). +# So, resolving these dependencies and drop --no-trace-events is a TODO. test_qapi_files = custom_target('Test QAPI files', output: test_qapi_outputs, input: files('qapi-schema/qapi-schema-test.json', 'qapi-schema/include/sub-module.json', 'qapi-schema/sub-sub-module.json'), command: [ qapi_gen, '-o', meson.current_build_dir(), - '-b', '-p', 'test-', '@INPUT0@' ], + '-b', '-p', 'test-', '@INPUT0@', + '--no-trace-events' ], depend_files: qapi_gen_depends) # meson doesn't like generated output in other directories diff --git a/trace/meson.build b/trace/meson.build index 573dd699c6..c4794a1f2a 100644 --- a/trace/meson.build +++ b/trace/meson.build @@ -2,10 +2,15 @@ specific_ss.add(files('control-target.c')) trace_events_files = [] -foreach dir : [ '.' ] + trace_events_subdirs - trace_events_file = meson.project_source_root() / dir / 'trace-events' +foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events + if item in qapi_trace_events + trace_events_file = item + group_name = item.full_path().split('/')[-1].underscorify() + else + trace_events_file = meson.project_source_root() / item / 'trace-events' + group_name = item == '.' ? 'root' : item.underscorify() + endif trace_events_files += [ trace_events_file ] - group_name = dir == '.' ? 'root' : dir.underscorify() group = '--group=' + group_name fmt = '@0@-' + group_name + '.@1@'