Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
memory_profile.cpp
Go to the documentation of this file.
1#include "memory_profile.hpp"
2
3#ifndef __wasm__
5#endif
6
8
9#if defined(__linux__)
10#include <malloc.h>
11#endif
12
13namespace {
14
15size_t heap_allocated_mb()
16{
17#if defined(__linux__)
18 struct mallinfo2 info = mallinfo2();
19 return info.uordblks / (1024ULL * 1024ULL);
20#elif defined(__wasm__)
21 return 0;
22#else
23 // mallinfo2 is Linux-specific; fall back to peak RSS on other platforms
24 return peak_rss_bytes() / (1024ULL * 1024ULL);
25#endif
26}
27
28} // namespace
29
30namespace bb::detail {
31
32// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
33bool use_memory_profile = false;
34// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
36
37void MemoryProfile::add_checkpoint(const std::string& stage)
38{
40 checkpoints.push_back(MemoryCheckpoint{ stage, current_circuit_index, current_circuit_name, heap_allocated_mb() });
41}
42
43void MemoryProfile::set_circuit_name(const std::string& name)
44{
47}
48
54
62
63void MemoryProfile::serialize_json(std::ostream& os) const
64{
65 // Use msgpack round-trip to produce JSON (same pattern as bb_bench.cpp)
66 msgpack::sbuffer buffer;
67 msgpack::pack(buffer, checkpoints);
68 msgpack::object_handle oh = msgpack::unpack(buffer.data(), buffer.size());
69 os << oh.get() << std::endl;
70}
71
72} // namespace bb::detail
#define info(...)
Definition log.hpp:93
std::unique_ptr< uint8_t[]> buffer
Definition engine.cpp:60
std::size_t peak_rss_bytes()
Definition logstr.cpp:32
bool use_memory_profile
MemoryProfile GLOBAL_MEMORY_PROFILE
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
void add_checkpoint(const std::string &stage)
std::vector< MemoryCheckpoint > checkpoints
void serialize_json(std::ostream &os) const
void set_circuit_name(const std::string &name)