1 //===-- xray-graph-diff.h - XRay Graph Diff Renderer ------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Generate a DOT file to represent the difference between the function call 10 // graph of two differnent traces. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef XRAY_GRAPH_DIFF_H 15 #define XRAY_GRAPH_DIFF_H 16 17 #include "xray-graph.h" 18 #include "llvm/ADT/StringMap.h" 19 #include "llvm/XRay/Graph.h" 20 21 namespace llvm { 22 namespace xray { 23 24 // This class creates a graph representing the difference between two 25 // xray-graphs And allows you to print it to a dot file, with optional color 26 // coding. 27 class GraphDiffRenderer { 28 static const int N = 2; 29 30 public: 31 using StatType = GraphRenderer::StatType; 32 using TimeStat = GraphRenderer::TimeStat; 33 34 using GREdgeValueType = GraphRenderer::GraphT::EdgeValueType; 35 using GRVertexValueType = GraphRenderer::GraphT::VertexValueType; 36 37 struct EdgeAttribute { 38 std::array<const GREdgeValueType *, N> CorrEdgePtr = {}; 39 }; 40 41 struct VertexAttribute { 42 std::array<const GRVertexValueType *, N> CorrVertexPtr = {}; 43 }; 44 45 using GraphT = Graph<VertexAttribute, EdgeAttribute, StringRef>; 46 47 class Factory { 48 std::array<std::reference_wrapper<const GraphRenderer::GraphT>, N> G; 49 50 public: 51 template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {} 52 53 Expected<GraphDiffRenderer> getGraphDiffRenderer(); 54 }; 55 56 private: 57 GraphT G; 58 59 GraphDiffRenderer() = default; 60 61 public: 62 void exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel = StatType::NONE, 63 StatType EdgeColor = StatType::NONE, 64 StatType VertexLabel = StatType::NONE, 65 StatType VertexColor = StatType::NONE, 66 int TruncLen = 40); 67 68 const GraphT &getGraph() { return G; } 69 }; 70 } // namespace xray 71 } // namespace llvm 72 73 #endif 74