blob: 5abec91d858258c976f0f9b9244a7484103d071a [file] [log] [blame]
Dean Michael Berrisae0fbfb2017-04-24 05:54:33 +00001//===-- 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
22namespace llvm {
23namespace 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.
28class GraphDiffRenderer {
29 static const int N = 2;
30
31public:
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 Berris0d479b02017-04-24 06:15:53 +000052 template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
Dean Michael Berrisae0fbfb2017-04-24 05:54:33 +000053
54 Expected<GraphDiffRenderer> getGraphDiffRenderer();
55 };
56
57private:
58 GraphT G;
59
60 GraphDiffRenderer() = default;
61
62public:
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 Berris0d479b02017-04-24 06:15:53 +000069 const GraphT &getGraph() { return G; }
Dean Michael Berrisae0fbfb2017-04-24 05:54:33 +000070};
71} // namespace xray
72} // namespace llvm
73
74#endif