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/memory_allocator_node_id.h"
18 
19 #include <stdio.h>
20 
21 #include <cinttypes>
22 
23 #include "perfetto/base/logging.h"
24 #include "perfetto/ext/base/string_utils.h"
25 
26 namespace perfetto {
27 namespace trace_processor {
28 
MemoryAllocatorNodeId(uint64_t id)29 MemoryAllocatorNodeId::MemoryAllocatorNodeId(uint64_t id) : id_(id) {}
30 
MemoryAllocatorNodeId()31 MemoryAllocatorNodeId::MemoryAllocatorNodeId() : MemoryAllocatorNodeId(0u) {}
32 
ToString() const33 std::string MemoryAllocatorNodeId::ToString() const {
34   size_t max_size = 19;  // Max uint64 is 0xFFFFFFFFFFFFFFFF + 1 for null byte.
35   std::string buf;
36   buf.resize(max_size);
37   size_t final_size = base::SprintfTrunc(&buf[0], max_size, "%" PRIu64, id_);
38   buf.resize(final_size);  // Cuts off the final null byte.
39   return buf;
40 }
41 
42 }  // namespace trace_processor
43 }  // namespace perfetto
44