v / vlib / v2 / transformer / mem_darwin.c.v
25 lines · 21 sloc · 844 bytes · de365a1fc6ab9c8cecbfd38bb4333bd24f887344
Raw
1// Copyright (c) 2020-2024 Joe Conigliaro. All rights reserved.
2// Use of this source code is governed by an MIT license
3// that can be found in the LICENSE file.
4module transformer
5
6#include <malloc/malloc.h>
7
8struct C.malloc_statistics_t {
9 blocks_in_use u32
10 size_in_use usize
11 max_size_in_use usize
12 size_allocated usize
13}
14
15fn C.malloc_default_zone() voidptr
16fn C.malloc_zone_statistics(zone voidptr, stats &C.malloc_statistics_t)
17
18// darwin_transform_live_mb returns the process's currently live malloc bytes
19// (in MB) on macOS. Used by t_print_mem; only referenced from its `$if macos`
20// branch, so the macOS-only C calls here never reach other platforms.
21fn darwin_transform_live_mb() u64 {
22 mut st := C.malloc_statistics_t{}
23 C.malloc_zone_statistics(C.malloc_default_zone(), &st)
24 return u64(st.size_in_use) / (1024 * 1024)
25}
26