From e31d05232813695b5bc7d22758143eef333ddd3f Mon Sep 17 00:00:00 2001 From: "Naklicki, Mateusz" Date: Mon, 13 Oct 2025 15:07:40 +0000 Subject: [PATCH] fix: remove unnecessary comments from graph dump Add section comments only when corresponding edges are present. Related-To: NEO-15377 Signed-off-by: Naklicki, Mateusz --- .../experimental/test_graph_export.cpp | 36 +++++++++++++++++++ .../source/graph/graph_export.cpp | 17 ++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp b/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp index 3c59ce28ff..f0e37ee8c5 100644 --- a/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp +++ b/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp @@ -119,6 +119,22 @@ TEST_F(GraphDotExporterTest, GivenGraphWithMultipleCommandsWhenWriteEdgesThenGen EXPECT_NE(output.find("L0_S0_C0 -> L0_S0_C1"), std::string::npos); } +TEST_F(GraphDotExporterTest, GivenGraphWithSingleCommandWhenWriteEdgesThenDoesNotGenerateSequentialSectionComment) { + Graph testGraph{&ctx, true}; + Mock event; + Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; + + testGraph.capture(&cmdlist, &event, 0U, nullptr); + testGraph.stopCapturing(); + + std::ostringstream dot; + exporter.writeEdges(dot, testGraph, 0, 0); + std::string output = dot.str(); + + EXPECT_EQ(output.find("// Sequential edges:"), std::string::npos); +} + TEST_F(GraphDotExporterTest, GivenGraphWithCommandWhenGetCommandNodeLabelThenReturnsCorrectLabel) { Graph testGraph{&ctx, true}; Mock event; @@ -466,6 +482,16 @@ TEST_F(GraphDotExporterTest, GivenGraphWithEmptySubgraphWhenWriteForkJoinEdgesTh EXPECT_EQ(output.find("->"), std::string::npos); } +TEST_F(GraphDotExporterTest, GivenGraphWithNoJoinedForksWhenWriteForkJoinEdgesThenNoSectionComment) { + Graph testGraph{&ctx, true}; + + std::ostringstream dot; + exporter.writeForkJoinEdges(dot, testGraph, 0, 0); + std::string output = dot.str(); + + EXPECT_EQ(output.find("// Fork/Join edges:"), std::string::npos); +} + TEST_F(GraphDotExporterTest, GivenGraphWithUnjoinedForksWhenWriteUnjoinedForkEdgesThenGeneratesUnjoinedEdges) { Graph testGraph{&ctx, true}; Mock forkEvent; @@ -525,6 +551,16 @@ TEST_F(GraphDotExporterTest, GivenGraphWithEmptyUnjoinedSubgraphWhenWriteUnjoine testGraph.stopCapturing(); } +TEST_F(GraphDotExporterTest, GivenGraphWithNoUnjoinedForksWhenWriteUnjoinedForkEdgesThenNoSectionComment) { + Graph testGraph{&ctx, true}; + + std::ostringstream dot; + exporter.writeUnjoinedForkEdges(dot, testGraph, 0, 0); + std::string output = dot.str(); + + EXPECT_EQ(output.find("// Unjoined forks:"), std::string::npos); +} + class GraphDotExporterSimpleStyleTest : public ::testing::Test { protected: GraphsCleanupGuard graphCleanup; diff --git a/level_zero/experimental/source/graph/graph_export.cpp b/level_zero/experimental/source/graph/graph_export.cpp index e86dd9ebd5..d0b5ed54a6 100644 --- a/level_zero/experimental/source/graph/graph_export.cpp +++ b/level_zero/experimental/source/graph/graph_export.cpp @@ -102,7 +102,10 @@ void GraphDotExporter::writeSequentialEdges(std::ostringstream &dot, const Graph const std::string indent(static_cast(level + 1) * 2, ' '); const auto &commands = graph.getCapturedCommands(); - dot << indent << "// Sequential edges:\n"; + + if (commands.size() > 1) { + dot << indent << "// Sequential edges:\n"; + } for (CapturedCommandId cmdId = 1; cmdId < static_cast(commands.size()); ++cmdId) { const std::string fromNode = generateNodeId(level, subgraphId, cmdId - 1); @@ -117,8 +120,10 @@ void GraphDotExporter::writeForkJoinEdges(std::ostringstream &dot, const Graph & const auto &joinedForks = graph.getJoinedForks(); const auto &subGraphs = graph.getSubgraphs(); - dot << "\n" - << indent << "// Fork/Join edges:\n"; + if (!joinedForks.empty()) { + dot << "\n" + << indent << "// Fork/Join edges:\n"; + } for (const auto &[forkCmdId, forkJoinInfo] : joinedForks) { const auto subgraphIndex = findSubgraphIndex(subGraphs, forkJoinInfo.forkDestiny); @@ -141,8 +146,10 @@ void GraphDotExporter::writeUnjoinedForkEdges(std::ostringstream &dot, const Gra const auto &unjoinedForks = graph.getUnjoinedForks(); const auto &subGraphs = graph.getSubgraphs(); - dot << "\n" - << indent << "// Unjoined forks:\n"; + if (!unjoinedForks.empty()) { + dot << "\n" + << indent << "// Unjoined forks:\n"; + } for (const auto &[cmdList, forkInfo] : unjoinedForks) { const auto subgraphIndex = findSubgraphIndexByCommandList(subGraphs, cmdList);