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