blob: 5d12c563f47c497a415ad3c2be55ed10192e57a1 [file] [log] [blame]
Dean Michael Berrisca780b52017-04-24 05:54:33 +00001//===-- xray-graph-diff.h - XRay Graph Diff Renderer ------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Dean Michael Berrisca780b52017-04-24 05:54:33 +00006//
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
21namespace llvm {
22namespace 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.
27class GraphDiffRenderer {
28 static const int N = 2;
29
30public:
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:
Dean Michael Berris01b880a2017-04-24 06:15:53 +000051 template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
Dean Michael Berrisca780b52017-04-24 05:54:33 +000052
53 Expected<GraphDiffRenderer> getGraphDiffRenderer();
54 };
55
56private:
57 GraphT G;
58
59 GraphDiffRenderer() = default;
60
61public:
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
Dean Michael Berris01b880a2017-04-24 06:15:53 +000068 const GraphT &getGraph() { return G; }
Dean Michael Berrisca780b52017-04-24 05:54:33 +000069};
70} // namespace xray
71} // namespace llvm
72
73#endif