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