xray-graph-diff.h 2.1 KB

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