]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-xray/xray-graph-diff.h
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r301441, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-xray / xray-graph-diff.h
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:
52     template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
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
69   const GraphT &getGraph() { return G; }
70 };
71 } // namespace xray
72 } // namespace llvm
73
74 #endif