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/XRay/Graph.h"
19
20namespace llvm {
21namespace xray {
22
23// This class creates a graph representing the difference between two
24// xray-graphs And allows you to print it to a dot file, with optional color
25// coding.
26class GraphDiffRenderer {
27 static const int N = 2;
28
29public:
30 using StatType = GraphRenderer::StatType;
31 using TimeStat = GraphRenderer::TimeStat;
32
33 using GREdgeValueType = GraphRenderer::GraphT::EdgeValueType;
34 using GRVertexValueType = GraphRenderer::GraphT::VertexValueType;
35
36 struct EdgeAttribute {
37 std::array<const GREdgeValueType *, N> CorrEdgePtr = {};
38 };
39
40 struct VertexAttribute {
41 std::array<const GRVertexValueType *, N> CorrVertexPtr = {};
42 };
43
44 using GraphT = Graph<VertexAttribute, EdgeAttribute, StringRef>;
45
46 class Factory {
47 std::array<std::reference_wrapper<const GraphRenderer::GraphT>, N> G;
48
49 public:
50 template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
51
52 Expected<GraphDiffRenderer> getGraphDiffRenderer();
53 };
54
55private:
56 GraphT G;
57
58 GraphDiffRenderer() = default;
59
60public:
61 void exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel = StatType::NONE,
62 StatType EdgeColor = StatType::NONE,
63 StatType VertexLabel = StatType::NONE,
64 StatType VertexColor = StatType::NONE,
65 int TruncLen = 40);
66
67 const GraphT &getGraph() { return G; }
68};
69} // namespace xray
70} // namespace llvm
71
72#endif
73