v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
type-stats.cc
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifdef V8_ENABLE_PRECISE_ZONE_STATS
6
7#if (defined(__clang__) || defined(__GLIBCXX__)) && !defined(_MSC_VER)
8#include <cxxabi.h>
9#endif // __GLIBCXX__
10#include <cinttypes>
11#include <cstdio>
12
15#include "src/utils/utils.h"
16#include "src/zone/type-stats.h"
17
18namespace v8 {
19namespace internal {
20
21void TypeStats::MergeWith(const TypeStats& other) {
22 for (auto const& item : other.map_) {
23 Add(item.first, item.second);
24 }
25}
26
27class Demangler {
28 public:
29 Demangler() = default;
30 ~Demangler() {
31 if (buffer_) base::Free(buffer_);
32 USE(buffer_len_); // In case demangling is not supported.
33 }
34
35 const char* demangle(std::type_index type_id) {
36#if (defined(__clang__) || defined(__GLIBCXX__)) && !defined(_MSC_VER)
37 int status = -1;
38 char* result =
39 abi::__cxa_demangle(type_id.name(), buffer_, &buffer_len_, &status);
40 if (status == 0) {
41 // Upon success, the buffer_ may be reallocated.
43 return buffer_;
44 }
45#endif
46 return type_id.name();
47 }
48
49 private:
50 char* buffer_ = nullptr;
51 size_t buffer_len_ = 0;
52};
53
54void TypeStats::Dump() const {
55 Demangler d;
56 PrintF("===== TypeStats =====\n");
57 PrintF("-------------+--------------+------------+--------+--------------\n");
58 PrintF(" alloc | dealloc | count | sizeof | name\n");
59 PrintF("-------------+--------------+------------+--------+--------------\n");
60 uint64_t total_allocation_count = 0;
61 uint64_t total_allocated_bytes = 0;
62 uint64_t total_deallocated_bytes = 0;
63 for (auto const& item : map_) {
64 const StatsEntry& entry = item.second;
65 total_allocation_count += entry.allocation_count;
66 total_allocated_bytes += entry.allocated_bytes;
67 total_deallocated_bytes += entry.deallocated_bytes;
68 PrintF("%12zu | %12zu | %10zu | %6zu | %s\n", entry.allocated_bytes,
69 entry.deallocated_bytes, entry.allocation_count, entry.instance_size,
70 d.demangle(item.first));
71 }
72 PrintF("%12" PRIu64 " | %12" PRIu64 " | %10" PRIu64
73 " | ===== TOTAL STATS =====\n",
74 total_allocated_bytes, total_deallocated_bytes,
75 total_allocation_count);
76}
77
78} // namespace internal
79} // namespace v8
80
81#endif // V8_ENABLE_PRECISE_ZONE_STATS
base::OwnedVector< uint8_t > buffer_
Definition assembler.cc:111
const MapRef map_
ZoneVector< RpoNumber > & result
void Add(RWDigits Z, Digits X, Digits Y)
void PrintF(const char *format,...)
Definition utils.cc:39
#define USE(...)
Definition macros.h:293