1317461Sdim//===-- xray-graph-diff.h - XRay Graph Diff Renderer ------------*- C++ -*-===//
2317461Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6317461Sdim//
7317461Sdim//===----------------------------------------------------------------------===//
8317461Sdim//
9317461Sdim// Generate a DOT file to represent the difference between the function call
10317461Sdim// graph of two differnent traces.
11317461Sdim//
12317461Sdim//===----------------------------------------------------------------------===//
13317461Sdim
14317461Sdim#ifndef XRAY_GRAPH_DIFF_H
15317461Sdim#define XRAY_GRAPH_DIFF_H
16317461Sdim
17317461Sdim#include "xray-graph.h"
18317461Sdim#include "llvm/ADT/StringMap.h"
19317461Sdim#include "llvm/XRay/Graph.h"
20317461Sdim
21317461Sdimnamespace llvm {
22317461Sdimnamespace xray {
23317461Sdim
24317461Sdim// This class creates a graph representing the difference between two
25317461Sdim// xray-graphs And allows you to print it to a dot file, with optional color
26317461Sdim// coding.
27317461Sdimclass GraphDiffRenderer {
28317461Sdim  static const int N = 2;
29317461Sdim
30317461Sdimpublic:
31317461Sdim  using StatType = GraphRenderer::StatType;
32317461Sdim  using TimeStat = GraphRenderer::TimeStat;
33317461Sdim
34317461Sdim  using GREdgeValueType = GraphRenderer::GraphT::EdgeValueType;
35317461Sdim  using GRVertexValueType = GraphRenderer::GraphT::VertexValueType;
36317461Sdim
37317461Sdim  struct EdgeAttribute {
38317461Sdim    std::array<const GREdgeValueType *, N> CorrEdgePtr = {};
39317461Sdim  };
40317461Sdim
41317461Sdim  struct VertexAttribute {
42317461Sdim    std::array<const GRVertexValueType *, N> CorrVertexPtr = {};
43317461Sdim  };
44317461Sdim
45317461Sdim  using GraphT = Graph<VertexAttribute, EdgeAttribute, StringRef>;
46317461Sdim
47317461Sdim  class Factory {
48317461Sdim    std::array<std::reference_wrapper<const GraphRenderer::GraphT>, N> G;
49317461Sdim
50317461Sdim  public:
51317461Sdim    template <typename... Ts> Factory(Ts &... Args) : G{{Args...}} {}
52317461Sdim
53317461Sdim    Expected<GraphDiffRenderer> getGraphDiffRenderer();
54317461Sdim  };
55317461Sdim
56317461Sdimprivate:
57317461Sdim  GraphT G;
58317461Sdim
59317461Sdim  GraphDiffRenderer() = default;
60317461Sdim
61317461Sdimpublic:
62317461Sdim  void exportGraphAsDOT(raw_ostream &OS, StatType EdgeLabel = StatType::NONE,
63317461Sdim                        StatType EdgeColor = StatType::NONE,
64317461Sdim                        StatType VertexLabel = StatType::NONE,
65317461Sdim                        StatType VertexColor = StatType::NONE,
66317461Sdim                        int TruncLen = 40);
67317461Sdim
68317461Sdim  const GraphT &getGraph() { return G; }
69317461Sdim};
70317461Sdim} // namespace xray
71317461Sdim} // namespace llvm
72317461Sdim
73317461Sdim#endif
74