aboutsummaryrefslogtreecommitdiff
path: root/src/trace_processor/importers/memory_tracker/memory_allocator_node_id.cc
blob: 9d801016a1f9915d5bdeaadc077ed7d53df6d76e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "perfetto/ext/trace_processor/importers/memory_tracker/memory_allocator_node_id.h"

#include <inttypes.h>
#include <stdio.h>

#include "perfetto/base/logging.h"

namespace perfetto {
namespace trace_processor {

MemoryAllocatorNodeId::MemoryAllocatorNodeId(uint64_t id) : id_(id) {}

MemoryAllocatorNodeId::MemoryAllocatorNodeId() : MemoryAllocatorNodeId(0u) {}

std::string MemoryAllocatorNodeId::ToString() const {
  size_t max_size = 19;  // Max uint64 is 0xFFFFFFFFFFFFFFFF + 1 for null byte.
  std::string buf;
  buf.resize(max_size);
  auto final_size = snprintf(&buf[0], max_size, "%" PRIu64, id_);
  PERFETTO_DCHECK(final_size >= 0);
  buf.resize(static_cast<size_t>(final_size));  // Cuts off the final null byte.
  return buf;
}

}  // namespace trace_processor
}  // namespace perfetto