• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INCLUDE_PERFETTO_EXT_TRACE_PROCESSOR_IMPORTERS_MEMORY_TRACKER_RAW_PROCESS_MEMORY_NODE_H_
18 #define INCLUDE_PERFETTO_EXT_TRACE_PROCESSOR_IMPORTERS_MEMORY_TRACKER_RAW_PROCESS_MEMORY_NODE_H_
19 
20 #include <stdint.h>
21 
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "perfetto/base/export.h"
28 #include "perfetto/ext/trace_processor/importers/memory_tracker/memory_allocator_node_id.h"
29 #include "perfetto/ext/trace_processor/importers/memory_tracker/memory_graph_edge.h"
30 #include "perfetto/ext/trace_processor/importers/memory_tracker/raw_memory_graph_node.h"
31 
32 namespace perfetto {
33 namespace trace_processor {
34 
35 // ProcessMemoryNode is as a strongly typed container which holds the nodes
36 // produced by the MemoryNodeProvider(s) for a specific process.
37 class PERFETTO_EXPORT_COMPONENT RawProcessMemoryNode {
38  public:
39   // Maps allocator nodes absolute names (allocator_name/heap/subheap) to
40   // MemoryAllocatorNode instances.
41   using MemoryNodesMap =
42       std::map<std::string, std::unique_ptr<RawMemoryGraphNode>>;
43 
44   // Stores allocator node edges indexed by source allocator node GUID.
45   using AllocatorNodeEdgesMap =
46       std::map<MemoryAllocatorNodeId, std::unique_ptr<MemoryGraphEdge>>;
47 
48   explicit RawProcessMemoryNode(
49       LevelOfDetail level_of_detail,
50       AllocatorNodeEdgesMap&& edges_map = AllocatorNodeEdgesMap{},
51       MemoryNodesMap&& nodes_map = MemoryNodesMap{});
52   RawProcessMemoryNode(RawProcessMemoryNode&&);
53   ~RawProcessMemoryNode();
54   RawProcessMemoryNode& operator=(RawProcessMemoryNode&&);
55 
56   // Looks up a MemoryAllocatorNode given its allocator and heap names, or
57   // nullptr if not found.
58   RawMemoryGraphNode* GetAllocatorNode(const std::string& absolute_name) const;
59 
60   // Returns the map of the MemoryAllocatorNodes added to this node.
allocator_nodes()61   const MemoryNodesMap& allocator_nodes() const { return allocator_nodes_; }
62 
allocator_nodes_edges()63   const AllocatorNodeEdgesMap& allocator_nodes_edges() const {
64     return allocator_nodes_edges_;
65   }
66 
level_of_detail()67   const LevelOfDetail& level_of_detail() const { return level_of_detail_; }
68 
69  private:
70   LevelOfDetail level_of_detail_;
71 
72   // Keeps track of relationships between MemoryAllocatorNode(s).
73   AllocatorNodeEdgesMap allocator_nodes_edges_;
74 
75   // Level of detail of the current node.
76   MemoryNodesMap allocator_nodes_;
77 
78   // This class is uncopyable and unassignable.
79   RawProcessMemoryNode(const RawProcessMemoryNode&) = delete;
80   RawProcessMemoryNode& operator=(const RawProcessMemoryNode&) = delete;
81 };
82 
83 }  // namespace trace_processor
84 }  // namespace perfetto
85 
86 #endif  // INCLUDE_PERFETTO_EXT_TRACE_PROCESSOR_IMPORTERS_MEMORY_TRACKER_RAW_PROCESS_MEMORY_NODE_H_
87