From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (EUR04-DB3-obe.outbound.protection.outlook.com [40.107.6.80]) by mx.groups.io with SMTP id smtpd.web09.8491.1620383909343578885 for ; Fri, 07 May 2021 03:38:29 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=wM7xnhNo; spf=pass (domain: arm.com, ip: 40.107.6.80, 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=4ujfq/MHx4Yx/0SYxpzXrlyqFS9/rN0eC4wHw4WwLR4=; b=wM7xnhNowxojQ/XsfrJkbRwBeqeWh2wMU1DtD3InGB6U2FhtFq0qovqKAXeOfhpxMe1JQiA3pCS4i+q3dMghgMaOdUZnYhIgNIJqVNVPefMIwJvPs3J/m0cQdYEd/le7i5/24gmoO8lRua0MJRimUAbnd1kwlpv12XCYSNNeiik= Received: from AM6P193CA0058.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::35) by DB6PR08MB2647.eurprd08.prod.outlook.com (2603:10a6:6:22::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Fri, 7 May 2021 10:38:23 +0000 Received: from AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8e:cafe::66) by AM6P193CA0058.outlook.office365.com (2603:10a6:209:8e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:23 +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 AM5EUR03FT062.mail.protection.outlook.com (10.152.17.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:22 +0000 Received: ("Tessian outbound 6c4b4bc1cefb:v91"); Fri, 07 May 2021 10:38:22 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: a4b4145823cb3ab3 X-CR-MTA-TID: 64aa7808 Received: from d07be2646f68.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BC77BA92-2D1B-4E2A-A65B-FEC92F6FBF90.1; Fri, 07 May 2021 10:38:15 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d07be2646f68.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 07 May 2021 10:38:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dau66Y2hh5gkoPq2QS9ExV9NA6IyIRjBhRXnml8S1x/itz1TmTspNHVZVJ5bCnYy4p4hLe4ek6tUI4To9dm5ZILALIB10JMY19kcyUkRUBPDVFaGuEsEIZekRnM3GappL2JJSAxenE51PNGph+wSUcdmypqqtZcW1Xh22WVhQKcd9G4L5qk8SdUv6iqEqNa6IFWsCNXC3zXvv/j7StbNPxh3ucy4lL8ED6lQVhqw/aal2JdnRL5wh60jVg/Ldre3O8kqm8xWV7d/2g0v1Ijy6zMvU85LBDgioD/K+uLs9qiW1qaloy+kHnaRNZx/r/XVIGtmIq5lh1SZ45KK+8SEGQ== 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-SenderADCheck; bh=4ujfq/MHx4Yx/0SYxpzXrlyqFS9/rN0eC4wHw4WwLR4=; b=M5idu//EXzN9CrlmhaeBKVhZk0/XDgSdMwdrsvkpsy/cNLTEyLXXBnvaVzq6f6nCM06/Yk9gMbsA908+nrkwW6jJbpvAWGuK2o3Oz51nuYcx6A70Qxq4WixJVA47hxPQ1CBlXclvJjLUTvImwvWkL9sWTETnfuOLk3cYld1mFwdYifEMZiYRapJdVEPZLcDc1pTandbRYwFc5XeuJN/6NjFFKl3aE3kedkdKcGV6Yt/DldSLHJcMFs6cOtJGYrc4Xc5iL8ODx35qlC8yTi5cgvSM5Fwk8F5ONVhodiob+7nlYGLLaDDe2gPh/MsqGdYv9l+VK7ewVGERtbcixnKLRQ== 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=4ujfq/MHx4Yx/0SYxpzXrlyqFS9/rN0eC4wHw4WwLR4=; b=wM7xnhNowxojQ/XsfrJkbRwBeqeWh2wMU1DtD3InGB6U2FhtFq0qovqKAXeOfhpxMe1JQiA3pCS4i+q3dMghgMaOdUZnYhIgNIJqVNVPefMIwJvPs3J/m0cQdYEd/le7i5/24gmoO8lRua0MJRimUAbnd1kwlpv12XCYSNNeiik= Received: from AM5PR1001CA0057.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::34) by DB9PR08MB6796.eurprd08.prod.outlook.com (2603:10a6:10:2ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Fri, 7 May 2021 10:38:14 +0000 Received: from AM5EUR03FT051.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:15:cafe::e4) by AM5PR1001CA0057.outlook.office365.com (2603:10a6:206:15::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:14 +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 AM5EUR03FT051.mail.protection.outlook.com (10.152.16.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4108.25 via Frontend Transport; Fri, 7 May 2021 10:38:14 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 7 May 2021 10:38:05 +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.2176.2 via Frontend Transport; Fri, 7 May 2021 10:38:05 +0000 From: "Joey Gouly" To: CC: , , , , Subject: [PATCH v1 4/5] ShellPkg: add dot file generator functions Date: Fri, 7 May 2021 11:38:03 +0100 Message-ID: <20210507103804.8131-5-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210507103804.8131-1-joey.gouly@arm.com> References: <20210507103804.8131-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d2c627b7-4d87-4a4e-b853-08d911443cfa X-MS-TrafficTypeDiagnostic: DB9PR08MB6796:|DB6PR08MB2647: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:2043;OLM:2043; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: leeOr9gMjdhcQKTyZvwULIH+1ynIffDtw9UOPRhbx9fOw3dqPUV9sBqA8KiyZjRrCz96z5tPxxWL58AIeerCRwMsiBE4H9FV7n8r3gy2YLY41lHYcIn7qrMDir6zx0xjMYfcImlQo4Y8SzamQAgVsuJSng18zZLSRoVVlhmUeq9Mz2DCaFrr85KY2pfD+5gP5SazctPwlN9y2/BkJVYahELl1nAQzM4IbdKoHU1KYm2zvectaBViTgOL51Capg0TQsXgnIWNEg0QnlonppfO9N+7C1nKlKzP4zeTRtyth3+eENU+oHamXglqdEVWCJWAzn63yCpeMhOtUJJpmJq1GdkW5FVH1CY275YWFytLMRkmv4f4h6oVwbz5WdyfLyxsZnLPX3RBJ29AIn6R6C+qsiqbbQMjAIVXVr2Svxi0qSbPV+CVdUAunjlhEOJv0TE9PG4Kp/4RxT11EpXHs7OIFKEW4QZYFVOcrUpypAhbMZjtqN4BO7bw6RwOIHh1NjvBvEoG3klLWxBjA+5y7Xtj0MgteE2vap0RCq6zG9AIlPZHtvtQneogqHRRNV6UTE5CJ0IrE+WAXH8WPBnp2VFYDhQBAcoGfKchEHy6h+Y114LoS8AeKWY0uzZpgXgI2SMdXz0GkOBOytqVi9rrKhAhkwZhnShZ3+JCOr3T9ijKLeKhB/lgqnD0WMwMapxtQwLVHAa+7a0sWeNTq1El0BbNqzQDHwtrPoV9rlVJCG6LTxC/f9eoopQyOeKtJ8iUkadlibBJfdD1JaqyArRPDGHtKg== 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)(346002)(39850400004)(376002)(136003)(396003)(36840700001)(46966006)(70586007)(316002)(44832011)(7696005)(36860700001)(2616005)(70206006)(82740400003)(478600001)(26005)(5660300002)(81166007)(356005)(186003)(19627235002)(8936002)(83380400001)(54906003)(36756003)(86362001)(8676002)(6916009)(30864003)(4326008)(426003)(82310400003)(336012)(1076003)(2906002)(47076005)(36900700001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6796 Return-Path: Joey.Gouly@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 530d7bf6-6078-4085-0553-08d911443835 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v8geN6DB0ijbFG8Fx8ZbNtOwqRWk2RCSe7T3UtobjGMsflCUFcWMsp2X0WMntpgUlYs4Wsc5ME0A+c5w4gStaWdO+cX8l6H+B8kF+TNsmdzm8ZU76l3993hht6QZprzvFDOH3/Jj7JPhwt9kDltrMNJQlTdAX+mu7qrYR9zXwAc8Ul1iwqfYBJUKHKxtul3e4sfr2jtwHvbxqIxMnDwj1rgIKZqp+kDtqK2ec//5YtM1pDV6onM6LVJLRSWf/MOfCZ/sWXJBKGPmVl6ANGfyiDufJJwVXnsQ6fb6kjPgQILkmeRzk4mxRLHb6V6FDlt9ypuRBJJy4fkb3lfADyoagxjZ4LAwZ8AeluIQTF1hEnb8M+AvD2eEjxqquFZckr4ew/ZMdsebEpGHd3x2uFzSaw8wQdwJ3QCK8fc7HQBcrPK9AaquQzYim0tYRb3M3dGTvUXTldMANN6zUIGGJ3DkFH8MZD37Te/KC9t4pd32hrDE0WxzDP21suLEY1D8g+tROz/f3CDn+ghPz2fJc3mQpelkNOSMm7Wy3/y/YcPiH/HOHprthQ+Zp4ZCoVvD4evtPksnl2bUHEtKywEN6j/TqBVapd9vrY4ntL0rf+VMP0Dq5DoupH7TnsdDqQUkMT9cA2Nv+xXYQ4irCvcpFZY8DOdimBOLHi0HEwvRy3U3jkNZsKdR34eMUro5/7zka/8nR6k8EEEjxiduOa4/TVTq4CIVwJ6yXK6sL0jqGBFTI4Q= 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)(39850400004)(396003)(136003)(376002)(346002)(46966006)(36840700001)(26005)(36860700001)(4326008)(336012)(86362001)(2906002)(6916009)(8676002)(478600001)(82310400003)(186003)(426003)(8936002)(30864003)(70206006)(36756003)(2616005)(5660300002)(83380400001)(81166007)(44832011)(19627235002)(70586007)(7696005)(47076005)(1076003)(82740400003)(54906003)(316002);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 10:38:22.7288 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2c627b7-4d87-4a4e-b853-08d911443cfa 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: AM5EUR03FT062.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR08MB2647 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: Marc Moisson-Franckhauser Signed-off-by: Joey Gouly --- ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.inf | 4 +- ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h | 97 +++++++ ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c | 276 ++++++++++++++++++++ 3 files changed, 376 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..7a8e2fdc2d2024ae54fdce963d751ab53a8a5758 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.h @@ -0,0 +1,97 @@ +/** @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. +**/ +VOID +DotCloseFile ( + SHELL_FILE_HANDLE DotFile + ); + +/** + Writes a line in the previously opened dot file describing a + new node. + + @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 DotFile, + 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] 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 DotFile, + 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..8c644d96af30ca4b1160bc892fe391ae1ff5211b --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/DotGenerator.c @@ -0,0 +1,276 @@ +/** @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] String Null terminated ascii string. +**/ +STATIC +VOID +DotWriteFile ( + SHELL_FILE_HANDLE DotFileHandle, + IN CHAR8* String + ) +{ + UINTN TransferBytes; + EFI_STATUS Status; + + if (DotFileHandle == NULL) { + Print ("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] 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] 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. +**/ +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] 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] 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")