global_dump_graph_converter.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_GLOBAL_DUMP_GRAPH_CONVERTER_H_
  5. #define SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_GLOBAL_DUMP_GRAPH_CONVERTER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <vector>
  9. #include "services/resource_coordinator/memory_instrumentation/graph.h"
  10. #include "third_party/perfetto/include/perfetto/ext/trace_processor/importers/memory_tracker/graph_processor.h"
  11. namespace memory_instrumentation {
  12. // Converts the Perfetto GlobalNodeGraph to the corresponding defined in
  13. // Chromium type GlobalDumpGraph.
  14. //
  15. // Example usage:
  16. //
  17. // {
  18. // perfetto::trace_processor::GlobalNodeGraph graph;
  19. //
  20. // GlobalDumpGraphConverter converter;
  21. // std::unique_ptr<GlobalDumpGraph> dumpGraph = converter.Convert(graph);
  22. // }
  23. class GlobalDumpGraphConverter {
  24. public:
  25. GlobalDumpGraphConverter();
  26. ~GlobalDumpGraphConverter();
  27. GlobalDumpGraphConverter(const GlobalDumpGraphConverter&) = delete;
  28. void operator=(const GlobalDumpGraphConverter&) = delete;
  29. std::unique_ptr<GlobalDumpGraph> Convert(
  30. const perfetto::trace_processor::GlobalNodeGraph& input) const;
  31. private:
  32. // Map is used during conversion from Perfetto GlobalNodeGraph to Chromium
  33. // GlobalDumpGraph. It simplifies finding matching nodes during conversion of
  34. // graph edges.
  35. using NodePointerPerfettoToChromeMap =
  36. std::map<const perfetto::trace_processor::GlobalNodeGraph::Node*,
  37. GlobalDumpGraph::Node*>;
  38. void CopyAndConvertProcessDumps(
  39. const perfetto::trace_processor::GlobalNodeGraph& input,
  40. GlobalDumpGraph* output,
  41. NodePointerPerfettoToChromeMap* pointer_map) const;
  42. void CopyAndConvertSharedMemoryGraph(
  43. const perfetto::trace_processor::GlobalNodeGraph& input,
  44. GlobalDumpGraph* output,
  45. NodePointerPerfettoToChromeMap* pointer_map) const;
  46. void CopyAndConvertNodeTree(
  47. const perfetto::trace_processor::GlobalNodeGraph::Node* input,
  48. GlobalDumpGraph::Process* output,
  49. const std::string& node_path,
  50. NodePointerPerfettoToChromeMap* pointer_map) const;
  51. base::trace_event::MemoryAllocatorDumpGuid ConvertMemoryAllocatorDumpGuid(
  52. const perfetto::trace_processor::MemoryAllocatorNodeId& input) const;
  53. void CopyNodeMembers(
  54. const perfetto::trace_processor::GlobalNodeGraph::Node& input,
  55. GlobalDumpGraph::Node* output) const;
  56. void CopyAndConvertEdges(
  57. const perfetto::trace_processor::GlobalNodeGraph& input,
  58. GlobalDumpGraph* output,
  59. NodePointerPerfettoToChromeMap* pointer_map) const;
  60. void CopyAndConvertEdge(
  61. const perfetto::trace_processor::GlobalNodeGraph::Edge& input,
  62. GlobalDumpGraph* output,
  63. const NodePointerPerfettoToChromeMap* pointer_map) const;
  64. GlobalDumpGraph::Node::Entry::ScalarUnits ConvertScalarUnits(
  65. const perfetto::trace_processor::GlobalNodeGraph::Node::Entry::ScalarUnits
  66. input) const;
  67. };
  68. } // namespace memory_instrumentation
  69. #endif // SERVICES_RESOURCE_COORDINATOR_MEMORY_INSTRUMENTATION_GLOBAL_DUMP_GRAPH_CONVERTER_H_