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