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 #include "perfetto/ext/trace_processor/importers/memory_tracker/raw_memory_graph_node.h"
18 
19 namespace perfetto {
20 namespace trace_processor {
21 
22 const char RawMemoryGraphNode::kNameSize[] = "size";
23 const char RawMemoryGraphNode::kNameObjectCount[] = "object_count";
24 const char RawMemoryGraphNode::kTypeScalar[] = "scalar";
25 const char RawMemoryGraphNode::kTypeString[] = "string";
26 const char RawMemoryGraphNode::kUnitsBytes[] = "bytes";
27 const char RawMemoryGraphNode::kUnitsObjects[] = "objects";
28 
MemoryNodeEntry(const std::string & n,const std::string & u,uint64_t v)29 RawMemoryGraphNode::MemoryNodeEntry::MemoryNodeEntry(const std::string& n,
30                                                      const std::string& u,
31                                                      uint64_t v)
32     : name(n), units(u), entry_type(kUint64), value_uint64(v) {}
33 
MemoryNodeEntry(const std::string & n,const std::string & u,const std::string & v)34 RawMemoryGraphNode::MemoryNodeEntry::MemoryNodeEntry(const std::string& n,
35                                                      const std::string& u,
36                                                      const std::string& v)
37     : name(n), units(u), entry_type(kString), value_string(v) {}
38 
operator ==(const MemoryNodeEntry & rhs) const39 bool RawMemoryGraphNode::MemoryNodeEntry::operator==(
40     const MemoryNodeEntry& rhs) const {
41   if (!(name == rhs.name && units == rhs.units && entry_type == rhs.entry_type))
42     return false;
43   switch (entry_type) {
44     case EntryType::kUint64:
45       return value_uint64 == rhs.value_uint64;
46     case EntryType::kString:
47       return value_string == rhs.value_string;
48   }
49   return false;
50 }
51 
RawMemoryGraphNode(const std::string & absolute_name,LevelOfDetail level,MemoryAllocatorNodeId id)52 RawMemoryGraphNode::RawMemoryGraphNode(const std::string& absolute_name,
53                                        LevelOfDetail level,
54                                        MemoryAllocatorNodeId id)
55     : absolute_name_(absolute_name),
56       level_of_detail_(level),
57       id_(id),
58       flags_(Flags::kDefault) {}
59 
RawMemoryGraphNode(const std::string & absolute_name,LevelOfDetail level,MemoryAllocatorNodeId id,std::vector<RawMemoryGraphNode::MemoryNodeEntry> && entries)60 RawMemoryGraphNode::RawMemoryGraphNode(
61     const std::string& absolute_name,
62     LevelOfDetail level,
63     MemoryAllocatorNodeId id,
64     std::vector<RawMemoryGraphNode::MemoryNodeEntry>&& entries)
65     : absolute_name_(absolute_name),
66       level_of_detail_(level),
67       entries_(std::move(entries)),
68       id_(id),
69       flags_(Flags::kDefault) {}
70 
71 }  // namespace trace_processor
72 }  // namespace perfetto
73