From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.43]) by mx.groups.io with SMTP id smtpd.web09.197.1631803579987778444 for ; Thu, 16 Sep 2021 07:46:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=kITekX3R; spf=pass (domain: arm.com, ip: 40.107.22.43, mailfrom: joey.gouly@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+5CC71aWxyi8PB09i2ca08GPb65OgEkberWxw3wCQQ=; b=kITekX3RBLx3QXMsJHFxMO+9znafu0OZSXr+fLf8Fu118ax89aQ7GI5NK16WMJjw9WWtg8wCwILvhbWh+4jQYELn1LGuGmAZFdgVc7HSiRYVLd3itI/f4rpbZtAbVDp7OSQ979gGUlfNkZq2h1bPFKV3jvXiJ7ZCNknOUstoj08= Received: from DU2PR04CA0210.eurprd04.prod.outlook.com (2603:10a6:10:28d::35) by AM6PR08MB3016.eurprd08.prod.outlook.com (2603:10a6:209:44::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.16; Thu, 16 Sep 2021 14:46:16 +0000 Received: from DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:28d:cafe::ca) by DU2PR04CA0210.outlook.office365.com (2603:10a6:10:28d::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16 via Frontend Transport; Thu, 16 Sep 2021 14:46:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT047.mail.protection.outlook.com (10.152.21.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:16 +0000 Received: ("Tessian outbound b9598e0ead92:v103"); Thu, 16 Sep 2021 14:46:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b0fcebcd4128b07b X-CR-MTA-TID: 64aa7808 Received: from b147a66631c6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8AE07B08-1B25-40C0-A51B-6A794DE8DBED.1; Thu, 16 Sep 2021 14:46:10 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b147a66631c6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 16 Sep 2021 14:46:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AO85foxT6DBJytMAnPnIm3udrEaqqunh932stg0szk1kRPb9lv3K0/+9NPapr0Z5KUaoXrVOF4Zb1EZYZNPUUWyCRNflLIxqg2cKYVL2Ds6P/8qVpXp8VA7Sh3YVsP5Cb8Kwsg1FlOdN98xmKNUFIQDBfSWngW2NaARMPUO+8sSYlu7/aMHa3jYjhoMGsJlra3+pfmV7eF3lkr1Xas10jBDsdXw4rGSwCUpfeTWQ4Qf88l0DYt0HZ4zjj6gvFvIO3ax/nUsrSIl4CY73zkvO5GBHz/RdhIvseuhusJJOUqqOk4XXIYlJtK3jrMFSILCd1/AOJdmQ71Q5OOMmlwf/IQ== 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; bh=E+5CC71aWxyi8PB09i2ca08GPb65OgEkberWxw3wCQQ=; b=m5b+3zlrlWvHtXuHgdfV1VzDYdGBfhcuZp+KMjHYvtyNhLK3tVkJa37iMWJQIF8jGBdA74syZdua/vFz91HHd2PHpqMZh5N4inWvyAqbPl/gY0jIbCpqpc1DZ3utg30wyBXWebMaYdGY7Oa8j+0Fy7YYyUHUvPvnJiXszBYADxQJs7v2KIsUgDGrJh6aWvlIt++L18wReizLgNCiEUx7ufcyvmpvDIZPzL1ZaZ1Zm9pwA8T+aQSlSbuV2GFjy4p6fpaN4ZdAoL7To094Bik3iPb8CWjpx3LfH4ttqsYZgC737Qvw6EYNUTPANKeLlosXHaYZ4QOz9vR3hka/z9LQdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+5CC71aWxyi8PB09i2ca08GPb65OgEkberWxw3wCQQ=; b=kITekX3RBLx3QXMsJHFxMO+9znafu0OZSXr+fLf8Fu118ax89aQ7GI5NK16WMJjw9WWtg8wCwILvhbWh+4jQYELn1LGuGmAZFdgVc7HSiRYVLd3itI/f4rpbZtAbVDp7OSQ979gGUlfNkZq2h1bPFKV3jvXiJ7ZCNknOUstoj08= Received: from DU2PR04CA0240.eurprd04.prod.outlook.com (2603:10a6:10:2b1::35) by PAXPR08MB6735.eurprd08.prod.outlook.com (2603:10a6:102:138::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Thu, 16 Sep 2021 14:46:08 +0000 Received: from DB5EUR03FT020.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:2b1:cafe::cb) by DU2PR04CA0240.outlook.office365.com (2603:10a6:10:2b1::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16 via Frontend Transport; Thu, 16 Sep 2021 14:46:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT020.mail.protection.outlook.com (10.152.20.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4523.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:08 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.14; Thu, 16 Sep 2021 14:46:15 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Thu, 16 Sep 2021 14:46:06 +0000 Received: from e124191.cambridge.arm.com (10.11.7.12) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.14 via Frontend Transport; Thu, 16 Sep 2021 14:46:15 +0000 From: "Joey Gouly" To: CC: , , , , Subject: [PATCH v2 4/5] ShellPkg: add dot file generator functions Date: Thu, 16 Sep 2021 15:46:04 +0100 Message-ID: <20210916144605.42071-5-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210916144605.42071-1-joey.gouly@arm.com> References: <20210916144605.42071-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4e23cab-11c2-458c-92f0-08d97920bcfc X-MS-TrafficTypeDiagnostic: PAXPR08MB6735:|AM6PR08MB3016: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2043;OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: t7YpRioWES+6m/tzK+xgadVVuqPfcMAsXiaBdbCqtjjnEVw3HgC9ynbnMV35zuTh7kxpShsdZo+jKF3svGRnh6sN0cl9+vvlbx8V6d8ky33qPMUL6G2blcVG+uKJq/R5qi5jveZ6sGkwr/XQzgRnuoYAW+6/NoFHrVTedElVaLy/zmiitJgt84SdSeDn0utP41+YztZ1x9cLSnSvrOVS+75xYLxcWn+guFMjo9l0r0wI8JnZxeDT10+3NB2YI9WyHYjLoPXEFuzqeUKX/vUokdGivSxRqJf72D7EKxEB9pMIPvit8o6IRDvNhjODGSbZapvER/D7TDSoRTik2H3Rr75JmZ3gKQ2TQJ1qLyMkIIvCKqUsSTcTbx+y+P46rlrZAxwyibAc5erS0RrqQJkITurmmJrB1+X7tadtzxOjzR88hd4U4PJrgbpUDvZ1G9cRiUx3bXRWoX7OFTbHj+zGBsNoWmfN3G8M6LIihvWPemQu2rf2g5MV0j6zkRAXG/L5m07hsteqCvdPz6OmxaCWtWTFrq0jT7Ksw/GKbBturAtcF6iUaRZIwfdxlkJpCMIrTtP3WAghSG6DBEbIPigfZb9+PxWpSBMZHMQ/jLsIAlwv57Y9pPqepq61fp8zS5Lkm/zjmpfESae6TotkbhXsvOrXT9NHaRJys2zYgUIXaFhIgCUCBn34liHPw56wuplKdlKgr6nL+1AO2MTLJ6By5wGKuXZT5ExA+zO6PKzgwVSOlmw+l3+THFT7zsn6Oz+uV6UHXlqvZgoRT8sKG28AZdPuZ9k/C6orbdubBL73I/tfoTQJE5gw6ThH+KZC/Cn6 X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(39860400002)(376002)(346002)(136003)(396003)(46966006)(36840700001)(8936002)(30864003)(7696005)(2906002)(6666004)(44832011)(83380400001)(70206006)(356005)(70586007)(6916009)(82740400003)(26005)(1076003)(186003)(81166007)(36756003)(316002)(47076005)(86362001)(478600001)(4326008)(36860700001)(19627235002)(5660300002)(426003)(2616005)(8676002)(336012)(82310400003)(54906003)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6735 Return-Path: Joey.Gouly@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3ab04007-92db-4ae3-a9b3-08d97920b852 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZXNEv4DT1Wa7v+WD3UKccuY5ltur1xfHDpIFsTEzYQgN9Us8uM51SS+a3rv2QvKdiA8B6Z23r+U1w+2xJq+fD5B/BgdX9QJJrvB9Fictys/Cv9eh8RdoJEHCqjgKhS130nBmyiSb6j3YIsiwJgk8OKOrIyW9E9n3nrUCDACK1n5ltSO4cxZoPM0MOUkC47vHoGkma3gDgvyocIBS1dLD6dvF2jEaxTkDj1JhGFkP1PndMdJEEL292ufONbqK3ro/UfjViUEW52R/+g4rnTtY4uG+VfknzUGRV+aPPSHqqbsgVVRhLVqTa0bhcMzbs30cgx9So+l3dCQffKDJMQGF46+rNYVj8HD1pEBgYdtM/bA8rYYacox0GWMmVMvsdIt8zO+0LKAWRiHptoimvVZSwTbA9KM+HTqB2Qw8vVXUAbcg1GklFGm1lFYe/uTEIxRqXK9n+dLxi1xL+rjQWkVLYN2kfUbV2GYgveqcjtFfeh5EpR/3FcD6CBtpkzSiUDefK+8NIoLHgvuIik+A483BEgiTxInmkLNIYOR37CLiRqm9Br8DXTKoJhpokD+WViZdschqkXRcVtDz1yRVYqqMPFdY9jTeRg62eAODiSEnxo+m/aiWnsoSuA9EeW81tvHJ6A0qVS7J7/6gBx6cFmpE/+lbTCuUHVVj3oiLwK07Q19ZriDk7AksFmR3MKw2ixxOacnb+HKPdH0o8o8t9NqIHRlxyRbBlfpHxHLaARxLhRNV5e05I3SRYuVpk2RkJbn0/spcP7ACT/f7h9SYZa0dYQ== X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(4636009)(39860400002)(346002)(396003)(136003)(376002)(36840700001)(46966006)(5660300002)(82310400003)(47076005)(8936002)(86362001)(2616005)(6916009)(2906002)(36860700001)(30864003)(44832011)(70586007)(6666004)(19627235002)(54906003)(186003)(83380400001)(7696005)(82740400003)(26005)(336012)(426003)(4326008)(478600001)(36756003)(81166007)(316002)(70206006)(1076003)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2021 14:46:16.6149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a4e23cab-11c2-458c-92f0-08d97920bcfc X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3016 Content-Type: text/plain From: Marc Moisson-Franckhauser Bugzilla: 3378 (https://bugzilla.tianocore.org/show_bug.cgi?id=3378) These can be used to generate dot files, that can be used to visualise graphs in tables, such as PPTT. Signed-off-by: Joey Gouly --- ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 4 +- ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h | 101 +++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c | 283 ++++++++++++++++++++ 3 files changed, 387 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf index 63fc5a1281a894841dac704484c3d4f9481edb46..ffe4979b3ac5d0120bcf678cf7823afac6674e4f 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf @@ -1,7 +1,7 @@ ## @file # Provides Shell 'acpiview' command functions # -# Copyright (c) 2016 - 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -27,6 +27,8 @@ [Sources.common] AcpiView.h AcpiViewConfig.c AcpiViewConfig.h + DotGenerator.c + DotGenerator.h Parsers/Aest/AestParser.c Parsers/Bgrt/BgrtParser.c Parsers/Dbg2/Dbg2Parser.c diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h new file mode 100644 index 0000000000000000000000000000000000000000..8e196eee75417c0a422023c00b043441076ac599 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h @@ -0,0 +1,101 @@ +/** @file + Header file for Dot File Generation + + Copyright (c) 2021, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef DOT_GENERATOR_H_ +#define DOT_GENERATOR_H_ + +#include + +#define DOT_COLOR_MASK 0b111 +// Flags for color of arrow or node. +#define DOT_COLOR_BLACK 0b000 // default +#define DOT_COLOR_GRAY 0b001 +#define DOT_COLOR_BLUE 0b010 +#define DOT_COLOR_YELLOW 0b011 +#define DOT_COLOR_RED 0b100 + +#define DOT_ARROW_TYPE_MASK 0b1000 +// Flags for style of arrow. +#define DOT_ARROW_FULL 0b0000 // default +#define DOT_ARROW_DOTTED 0b1000 + +// Flag for reversing how the nodes will be ranked and displayed. +#define DOT_ARROW_RANK_REVERSE 0b10000 + +#define DOT_BOX_TYPE_MASK 0b1100000 +// Flag for shape of box +#define DOT_BOX_SQUARE 0b0000000 // default +#define DOT_BOX_DIAMOND 0b0100000 + +// Flag for adding the node's ID to the end of the label. +#define DOT_BOX_ADD_ID_TO_LABEL 0b10000000 + +// Valid flags for DotAddNode. +#define DOT_BOX_FLAGS_MASK (DOT_COLOR_MASK |\ + DOT_BOX_TYPE_MASK |\ + DOT_BOX_ADD_ID_TO_LABEL) +// Valid flags for DotAddLink. +#define DOT_ARROW_FLAGS_MASK (DOT_COLOR_MASK |\ + DOT_ARROW_TYPE_MASK |\ + DOT_ARROW_RANK_REVERSE) + + +/** + Opens a new dot file and writes a dot directional graph. + + @param [in] FileName Null terminated unicode string. +**/ +SHELL_FILE_HANDLE +DotOpenNewFile ( + IN CHAR16* FileName + ); + +/** + Writes a dot graph footer and closes the dot file. + + @param [in] DotFileHandle The handle of the dot file. +**/ +VOID +DotCloseFile ( + SHELL_FILE_HANDLE DotFileHandle + ); + +/** + Writes a line in the previously opened dot file describing a + new node. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] Id A unique identifier for the node. + @param [in] Flags Flags describing the node's characteristics. + @param [in] Label Label to be shown on the graph node. +**/ +VOID +DotAddNode ( + SHELL_FILE_HANDLE DotFileHandle, + IN UINT32 Id, + IN UINT16 Flags, + IN CONST CHAR16* Label + ); + +/** + Writes a line in the previously opened dot file describing a + new link between two nodes. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] IdSource An identifier for the source node of the link. + @param [in] IdTarget An identifier for the target node of the link. + @param [in] Flags Flags describing the node's characteristics. +**/ +VOID +DotAddLink ( + SHELL_FILE_HANDLE DotFileHandle, + IN UINT32 IdSource, + IN UINT32 IdTarget, + IN UINT16 Flags + ); + +#endif // DOT_GENERATOR_H_ diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c new file mode 100644 index 0000000000000000000000000000000000000000..e19b17537ca85babca5cda38025ae95701ff794f --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c @@ -0,0 +1,283 @@ +/** @file + Dot File Generator + + Copyright (c) 2021, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include "DotGenerator.h" +#include "AcpiView.h" + +#define MAX_DOT_BUFFER_SIZE 128 + +/** + Writes a Null terminated ASCII string to the dot file handle. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] String Null terminated ascii string. +**/ +STATIC +VOID +DotWriteFile ( + SHELL_FILE_HANDLE DotFileHandle, + IN CHAR8* String + ) +{ + UINTN TransferBytes; + EFI_STATUS Status; + + if (DotFileHandle == NULL) { + Print (L"ERROR: Failed to write to dot file\n"); + ASSERT (0); + return; + } + + TransferBytes = AsciiStrLen (String); + Status = ShellWriteFile ( + DotFileHandle, + &TransferBytes, + String + ); + ASSERT_EFI_ERROR (Status); + ASSERT (AsciiStrLen (String) == TransferBytes); +} + +/** + Writes a new parameter to a previously started parameter list. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] Name Null terminated string of the parameter's name. + @param [in] Value Null terminated string of the parameter's value. + @param [in] Quoted True if value needs to be quoted. +**/ +STATIC +VOID +DotAddParameter ( + SHELL_FILE_HANDLE DotFileHandle, + IN CHAR16* Name, + IN CHAR16* Value, + IN BOOLEAN Quoted + ) +{ + CHAR8 StringBuffer[MAX_DOT_BUFFER_SIZE]; + + ASSERT(DotFileHandle != NULL); + + if (Quoted) { + AsciiSPrint ( + StringBuffer, + sizeof (StringBuffer), + "[%s=\"%s\"]", + Name, + Value + ); + } else { + AsciiSPrint ( + StringBuffer, + sizeof (StringBuffer), + "[%s=%s]", + Name, + Value + ); + } + + DotWriteFile (DotFileHandle, StringBuffer); +} + +/** + Writes the color argument of nodes or links according to flags. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] Flags Flags describing the color (one of DOT_COLOR_...) +**/ +STATIC +VOID +WriteColor ( + SHELL_FILE_HANDLE DotFileHandle, + IN UINT16 Flags + ) +{ + ASSERT(DotFileHandle != NULL); + + switch (Flags & DOT_COLOR_MASK) { + case DOT_COLOR_GRAY: + DotAddParameter (DotFileHandle, L"color", L"gray", FALSE); + break; + case DOT_COLOR_YELLOW: + DotAddParameter (DotFileHandle, L"color", L"yellow", FALSE); + break; + case DOT_COLOR_BLUE: + DotAddParameter (DotFileHandle, L"color", L"blue", FALSE); + break; + case DOT_COLOR_RED: + DotAddParameter (DotFileHandle, L"color", L"red", FALSE); + break; + case DOT_COLOR_BLACK: + default: + DotAddParameter (DotFileHandle, L"color", L"black", FALSE); + break; + } +} + +/** + Opens a new dot file and writes a dot directional graph. + + @param [in] FileName Null terminated unicode string. +**/ +SHELL_FILE_HANDLE +DotOpenNewFile ( + IN CHAR16* FileName + ) +{ + SHELL_FILE_HANDLE DotFileHandle; + EFI_STATUS Status; + + Status = ShellOpenFileByName ( + FileName, + &DotFileHandle, + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, + 0 + ); + if (EFI_ERROR (Status)) { + Print (L"ERROR: Couldn't open dot file"); + return NULL;//Status; + } + Print (L"Creating DOT Graph in : %s... ", FileName); + DotWriteFile (DotFileHandle, "digraph {\n\trankdir=BT\n"); + return DotFileHandle; +} + +/** + Writes a dot graph footer and closes the dot file. + + @param [in] DotFileHandle The handle of the dot file. +**/ +VOID +DotCloseFile ( + SHELL_FILE_HANDLE DotFileHandle + ) +{ + ASSERT(DotFileHandle != NULL); + + DotWriteFile (DotFileHandle, "}\n"); + ShellCloseFile (&DotFileHandle); + Print (L"Done.\n"); +} + +/** + Writes a line in the previously opened dot file describing a + new node. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] Id A unique identifier for the node. + @param [in] Flags Flags describing the node's characteristics. + @param [in] Label Label to be shown on the graph node. +**/ +VOID +DotAddNode ( + SHELL_FILE_HANDLE DotFileHandle, + IN UINT32 Id, + IN UINT16 Flags, + IN CONST CHAR16* Label + ) +{ + CHAR8 LineBuffer[64]; + CHAR16 LabelBuffer[MAX_DOT_BUFFER_SIZE]; + + ASSERT ((Flags & ~DOT_BOX_FLAGS_MASK) == 0); + ASSERT(DotFileHandle != NULL); + + AsciiSPrint ( + LineBuffer, + sizeof (LineBuffer), + "\tx%x", + Id + ); + DotWriteFile (DotFileHandle, LineBuffer); + + switch (Flags & DOT_BOX_TYPE_MASK) { + case DOT_BOX_DIAMOND: + DotAddParameter (DotFileHandle, L"shape", L"diamond", FALSE); + break; + case DOT_BOX_SQUARE: + default: + DotAddParameter (DotFileHandle, L"shape", L"box", FALSE); + break; + } + + if (Label != NULL) { + if ((Flags & DOT_BOX_ADD_ID_TO_LABEL) != 0) { + UnicodeSPrint ( + LabelBuffer, + sizeof (LabelBuffer), + L"%s\\n0x%x", + Label, + Id + ); + } else { + UnicodeSPrint ( + LabelBuffer, + sizeof (LabelBuffer), + L"%s", + Label + ); + } + DotAddParameter (DotFileHandle, L"label", LabelBuffer, TRUE); + } + + WriteColor (DotFileHandle, Flags); + DotWriteFile (DotFileHandle, "\n"); +} + +/** + Writes a line in the previously opened dot file describing a + new link between two nodes. + + @param [in] DotFileHandle The handle of the dot file. + @param [in] IdSource An identifier for the source node of the link. + @param [in] IdTarget An identifier for the target node of the link. + @param [in] Flags Flags describing the node's characteristics. +**/ +VOID +DotAddLink ( + SHELL_FILE_HANDLE DotFileHandle, + IN UINT32 IdSource, + IN UINT32 IdTarget, + IN UINT16 Flags + ) +{ + CHAR8 LineBuffer[64]; + + ASSERT(DotFileHandle != NULL); + ASSERT ((Flags & ~DOT_ARROW_FLAGS_MASK) == 0); + + AsciiSPrint ( + LineBuffer, + sizeof (LineBuffer), + "\tx%x -> x%x", + IdSource, + IdTarget + ); + DotWriteFile (DotFileHandle, LineBuffer); + + if ((Flags & DOT_ARROW_RANK_REVERSE) != 0) { + DotAddParameter (DotFileHandle, L"dir", L"back", FALSE); + } + + switch (Flags & DOT_ARROW_TYPE_MASK) { + case DOT_ARROW_DOTTED: + DotAddParameter (DotFileHandle, L"style", L"dotted", FALSE); + break; + case DOT_ARROW_FULL: + default: + DotAddParameter (DotFileHandle, L"style", L"solid", FALSE); + break; + } + + WriteColor (DotFileHandle, Flags); + DotWriteFile (DotFileHandle, "\n"); +} -- Guid("CE165669-3EF3-493F-B85D-6190EE5B9759")