use core::ffi::c_char;
use core::ffi::c_int;
use core::ffi::c_void;
pub type MiProfWriteFun = unsafe extern "C" fn(*mut c_void, *const c_char, usize);
pub const MI_PROF_STAT_VERSION: c_int = 3;
pub const MI_DHAT_STATS_VERSION: c_int = 1;
#[repr(C)]
#[allow(non_camel_case_types)]
pub struct mi_dhat_stats_t {
pub size: usize,
pub version: c_int,
pub enabled: bool,
pub incomplete: bool,
pub total_bytes: u64,
pub total_blocks: u64,
pub live_bytes: u64,
pub live_blocks: u64,
pub peak_bytes: u64,
pub peak_blocks: u64,
pub dropped: u64,
pub internal_bytes: u64,
}
#[repr(C)]
#[allow(non_camel_case_types)]
pub struct mi_prof_stats_t {
pub size: usize,
pub version: c_int,
pub enabled: bool,
pub accum: bool,
pub sample_rate: usize,
pub live_samples: usize,
pub live_bytes: usize,
pub accum_samples: usize,
pub accum_bytes: usize,
pub unique_stacks: usize,
pub arena_committed: usize,
pub stack_table_overflows: usize,
pub dropped_samples: usize,
pub heap_committed: usize,
pub heap_reserved: usize,
pub heap_malloc_requested: usize,
pub heap_pages: usize,
pub heap_pages_abandoned: usize,
pub heap_count: usize,
pub theap_count: usize,
pub heap_purged: usize,
pub heap_stats_detailed: bool,
}
pub const MI_PROF_CONFIG_VERSION: c_int = 1;
pub const MI_PROF_FORMAT_TEXT: c_int = 0;
pub const MI_PROF_FORMAT_PROTO: c_int = 1;
pub const MI_PROF_CONFIG_FALLBACK: c_int = 0;
pub const MI_PROF_CONFIG_OVERRIDE: c_int = 1;
#[repr(C)]
#[allow(non_camel_case_types)]
pub struct mi_prof_config_t {
pub size: usize,
pub version: c_int,
pub mode: c_int, pub sample_interval: usize,
pub max_profiler_bytes: usize,
pub seed: u64,
pub accum: bool,
pub max_stack_depth: usize,
pub dump_at_exit: *const c_char,
pub dump_format: c_int,
}
#[repr(C)]
#[allow(non_camel_case_types)]
pub struct mi_prof_sample_info_t {
pub stack: *const *const c_void,
pub depth: usize,
pub live_objects: usize,
pub live_bytes: usize,
pub accum_objects: usize,
pub accum_bytes: usize,
}
#[allow(non_camel_case_types)]
pub type mi_prof_visit_fun =
unsafe extern "C" fn(info: *const mi_prof_sample_info_t, arg: *mut c_void) -> bool;
#[allow(non_camel_case_types)]
pub enum mi_prof_snapshot_t {}
#[repr(C)]
#[allow(non_camel_case_types)]
pub struct mi_prof_module_info_t {
pub path: *const c_char,
pub base: usize,
pub size: usize,
}
#[allow(non_camel_case_types)]
pub type mi_prof_module_visit_fun =
unsafe extern "C" fn(info: *const mi_prof_module_info_t, arg: *mut c_void) -> bool;
#[allow(non_camel_case_types)]
pub enum mi_heap_t {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct MiPurgeHolesStats {
pub purged_bytes: usize,
pub purged_blocks: usize,
pub purged_bytes_total: usize,
pub discard_calls: usize,
pub reuse_calls: usize,
pub pages_freed: usize,
pub ineligible_pages: usize,
pub ineligible_bytes: usize,
pub ineligible_free_bytes: usize,
pub unformed_bytes: usize,
pub unformed_bytes_total: usize,
pub unformed_discard_calls: usize,
pub unformed_reuse_calls: usize,
pub pages_skipped: usize,
pub blocks_visited: usize,
pub full_sweeps: usize,
}
pub const MI_STAT_VERSION: usize = 5;
pub const MI_BIN_HUGE: usize = 73;
pub const MI_CBIN_COUNT: usize = 6;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub struct mi_stat_count_t {
pub total: i64,
pub peak: i64,
pub current: i64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub struct mi_stat_counter_t {
pub total: i64,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
#[allow(non_camel_case_types)]
pub struct mi_stats_t {
pub size: usize,
pub version: usize,
pub pages: mi_stat_count_t,
pub reserved: mi_stat_count_t,
pub committed: mi_stat_count_t,
pub reset: mi_stat_counter_t,
pub purged: mi_stat_counter_t,
pub page_committed: mi_stat_count_t,
pub pages_abandoned: mi_stat_count_t,
pub threads: mi_stat_count_t,
pub malloc_normal: mi_stat_count_t,
pub malloc_huge: mi_stat_count_t,
pub malloc_requested: mi_stat_count_t,
pub mmap_calls: mi_stat_counter_t,
pub commit_calls: mi_stat_counter_t,
pub reset_calls: mi_stat_counter_t,
pub purge_calls: mi_stat_counter_t,
pub arena_count: mi_stat_counter_t,
pub malloc_normal_count: mi_stat_counter_t,
pub malloc_huge_count: mi_stat_counter_t,
pub malloc_guarded_count: mi_stat_counter_t,
pub arena_rollback_count: mi_stat_counter_t,
pub arena_purges: mi_stat_counter_t,
pub pages_extended: mi_stat_counter_t,
pub pages_retire: mi_stat_counter_t,
pub page_searches: mi_stat_counter_t,
pub page_searches_count: mi_stat_counter_t,
pub segments: mi_stat_count_t,
pub segments_abandoned: mi_stat_count_t,
pub segments_cache: mi_stat_count_t,
pub _segments_reserved: mi_stat_count_t,
pub heaps: mi_stat_count_t,
pub theaps: mi_stat_count_t,
pub pages_reclaim_on_alloc: mi_stat_counter_t,
pub pages_reclaim_on_free: mi_stat_counter_t,
pub pages_reabandon_full: mi_stat_counter_t,
pub pages_unabandon_busy_wait: mi_stat_counter_t,
pub heaps_delete_wait: mi_stat_counter_t,
pub _stat_reserved: [mi_stat_count_t; 4],
pub _stat_counter_reserved: [mi_stat_counter_t; 4],
pub malloc_bins: [mi_stat_count_t; MI_BIN_HUGE + 1],
pub page_bins: [mi_stat_count_t; MI_BIN_HUGE + 1],
pub chunk_bins: [mi_stat_count_t; MI_CBIN_COUNT],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub struct mi_subproc_id_t {
pub _mi_subproc_id: *mut c_void,
}
#[allow(non_camel_case_types)]
pub type mi_output_fun = unsafe extern "C" fn(msg: *const c_char, arg: *mut c_void);
pub const MI_MEMORY_SNAPSHOT_VERSION: c_int = 1;
#[allow(non_camel_case_types)]
pub type mi_memory_change_kind_t = c_int;
pub const MI_MEMORY_ALLOCATE: mi_memory_change_kind_t = 0;
pub const MI_MEMORY_FREE: mi_memory_change_kind_t = 1;
pub const MI_MEMORY_RESIZE: mi_memory_change_kind_t = 2;
pub const MI_MEMORY_CHANGE_COUNT: usize = 3;
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub struct mi_memory_change_t {
pub kind: mi_memory_change_kind_t,
pub total_bytes: u64,
pub delta_bytes: i64,
pub request_size: u64,
}
#[allow(non_camel_case_types)]
pub type mi_memory_change_fun =
unsafe extern "C" fn(change: *const mi_memory_change_t, arg: *mut c_void);
#[repr(C)]
#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
pub struct mi_memory_callbacks_t {
pub handlers: [Option<mi_memory_change_fun>; MI_MEMORY_CHANGE_COUNT],
pub args: [*mut c_void; MI_MEMORY_CHANGE_COUNT],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub struct mi_memory_snapshot_t {
pub size: usize,
pub version: c_int,
pub live_bytes: u64,
pub accum_bytes: u64,
pub live_count: u64,
pub accum_count: u64,
}
#[allow(non_camel_case_types)]
pub type mi_memory_allocation_visit_fun =
unsafe extern "C" fn(allocation: *mut c_void, usable_size: usize, arg: *mut c_void) -> bool;
#[allow(non_camel_case_types)]
pub type mi_option_t = c_int;
macro_rules! mi_options {
($($(#[$attr:meta])* $name:ident = $value:expr;)*) => {
$(
$(#[$attr])*
#[allow(non_upper_case_globals)]
pub const $name: mi_option_t = $value;
)*
pub const MI_OPTIONS_IN_ORDER: &[(&str, mi_option_t)] = &[$((stringify!($name), $name)),*];
};
}
mi_options! {
mi_option_show_errors = 0;
mi_option_show_stats = 1;
mi_option_verbose = 2;
mi_option_deprecated_eager_commit = 3;
mi_option_arena_eager_commit = 4;
mi_option_purge_decommits = 5;
mi_option_allow_large_os_pages = 6;
mi_option_reserve_huge_os_pages = 7;
mi_option_reserve_huge_os_pages_at = 8;
mi_option_reserve_os_memory = 9;
mi_option_deprecated_segment_cache = 10;
mi_option_deprecated_page_reset = 11;
mi_option_deprecated_abandoned_page_purge = 12;
mi_option_deprecated_segment_reset = 13;
mi_option_deprecated_eager_commit_delay = 14;
mi_option_purge_delay = 15;
mi_option_use_numa_nodes = 16;
mi_option_disallow_os_alloc = 17;
mi_option_os_tag = 18;
mi_option_max_errors = 19;
mi_option_max_warnings = 20;
mi_option_deprecated_max_segment_reclaim = 21;
mi_option_destroy_on_exit = 22;
mi_option_arena_reserve = 23;
mi_option_arena_purge_mult = 24;
mi_option_deprecated_purge_extend_delay = 25;
mi_option_disallow_arena_alloc = 26;
mi_option_retry_on_oom = 27;
mi_option_deprecated_visit_abandoned = 28;
mi_option_guarded_min = 29;
mi_option_guarded_max = 30;
mi_option_guarded_precise = 31;
mi_option_guarded_sample_rate = 32;
mi_option_guarded_sample_seed = 33;
mi_option_generic_collect = 34;
mi_option_page_reclaim_on_free = 35;
mi_option_page_full_retain = 36;
mi_option_page_max_candidates = 37;
mi_option_max_vabits = 38;
mi_option_pagemap_commit = 39;
mi_option_page_commit_on_demand = 40;
mi_option_page_max_reclaim = 41;
mi_option_page_cross_thread_max_reclaim = 42;
mi_option_allow_thp = 43;
mi_option_minimal_purge_size = 44;
mi_option_arena_max_object_size = 45;
mi_option_arena_is_numa_local = 46;
mi_option_prof = 47;
mi_option_prof_sample_rate = 48;
mi_option_prof_bt_max = 49;
mi_option_prof_accum = 50;
mi_option_prof_seed = 51;
mi_option_prof_max_bytes = 52;
mi_option_memory_events = 53;
mi_option_purge_zeroes = 54;
mi_option_scavenger = 55;
mi_option_purge_holes = 56;
mi_option_purge_holes_eager_zero = 57;
mi_option_purge_holes_min_interval = 58;
mi_option_purge_holes_full_every = 59;
_mi_option_last = 60;
}
#[allow(non_upper_case_globals)]
pub const mi_option_large_os_pages: mi_option_t = mi_option_allow_large_os_pages;
#[allow(non_upper_case_globals)]
pub const mi_option_eager_region_commit: mi_option_t = mi_option_arena_eager_commit;
#[allow(non_upper_case_globals)]
pub const mi_option_reset_decommits: mi_option_t = mi_option_purge_decommits;
#[allow(non_upper_case_globals)]
pub const mi_option_reset_delay: mi_option_t = mi_option_purge_delay;
#[allow(non_upper_case_globals)]
pub const mi_option_limit_os_alloc: mi_option_t = mi_option_disallow_os_alloc;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct MiRsLayoutEntry {
pub name: *const c_char,
pub value: usize,
}
unsafe extern "C" {
pub fn mi_malloc(size: usize) -> *mut c_void;
pub fn mi_zalloc(size: usize) -> *mut c_void;
pub fn mi_calloc(count: usize, size: usize) -> *mut c_void;
pub fn mi_realloc(p: *mut c_void, newsize: usize) -> *mut c_void;
pub fn mi_free(p: *mut c_void);
pub fn mi_malloc_aligned(size: usize, alignment: usize) -> *mut c_void;
pub fn mi_zalloc_aligned(size: usize, alignment: usize) -> *mut c_void;
pub fn mi_realloc_aligned(p: *mut c_void, newsize: usize, alignment: usize) -> *mut c_void;
pub fn mi_rezalloc(p: *mut c_void, newsize: usize) -> *mut c_void;
pub fn mi_recalloc(p: *mut c_void, newcount: usize, size: usize) -> *mut c_void;
pub fn mi_rezalloc_aligned(p: *mut c_void, newsize: usize, alignment: usize) -> *mut c_void;
pub fn mi_recalloc_aligned(
p: *mut c_void,
newcount: usize,
size: usize,
alignment: usize,
) -> *mut c_void;
pub fn mi_expand(p: *mut c_void, newsize: usize) -> *mut c_void;
pub fn mi_usable_size(p: *const c_void) -> usize;
pub fn mi_dhat_start() -> bool;
pub fn mi_dhat_stop();
pub fn mi_dhat_is_enabled() -> bool;
pub fn mi_dhat_stats_get(stats: *mut mi_dhat_stats_t) -> bool;
pub fn mi_dhat_dump(path: *const c_char) -> bool;
pub fn mi_prof_start(sample_rate: usize) -> bool;
pub fn mi_prof_start_seeded(sample_rate: usize, seed: u64) -> bool;
pub fn mi_prof_start_ex(config: *const mi_prof_config_t) -> bool;
pub fn mi_prof_stop();
pub fn mi_prof_is_enabled() -> bool;
pub fn mi_prof_dump(path: *const c_char) -> bool;
pub fn mi_prof_dump_writer(write: Option<MiProfWriteFun>, arg: *mut c_void) -> bool;
pub fn mi_prof_dump_proto(path: *const c_char) -> bool;
pub fn mi_prof_dump_proto_writer(write: Option<MiProfWriteFun>, arg: *mut c_void) -> bool;
pub fn mi_prof_reset();
pub fn mi_prof_debug_stats(records: *mut usize, bytes: *mut usize, unique_stacks: *mut usize);
pub fn mi_prof_stats_get(stats: *mut mi_prof_stats_t) -> bool;
pub fn mi_prof_visit(visitor: mi_prof_visit_fun, arg: *mut c_void) -> bool;
pub fn mi_prof_snapshot_new() -> *mut mi_prof_snapshot_t;
pub fn mi_prof_snapshot_visit(
snap: *const mi_prof_snapshot_t,
visitor: mi_prof_visit_fun,
arg: *mut c_void,
) -> bool;
pub fn mi_prof_snapshot_free(snap: *mut mi_prof_snapshot_t);
pub fn mi_prof_modules_visit(visitor: mi_prof_module_visit_fun, arg: *mut c_void) -> bool;
pub fn mi_unwrapped_malloc(size: usize, alignment: usize) -> *mut c_void;
pub fn mi_unwrapped_free(p: *mut c_void);
pub fn mi_unwrapped_realloc(p: *mut c_void, new_size: usize, alignment: usize) -> *mut c_void;
pub fn mi_heap_dump_json(include_blocks: bool, hash_addresses: bool) -> *mut c_char;
pub fn mi_heap_get_seq(heap: *mut mi_heap_t) -> usize;
pub fn mi_on_thread_idle();
pub fn mi_on_thread_idle_start() -> bool;
pub fn mi_on_thread_idle_end();
pub fn mi_scavenger_stop();
pub fn mi_purge_holes_stats_get(stats: *mut MiPurgeHolesStats);
pub fn mi_purge_holes_report();
pub fn mi_option_is_enabled(option: mi_option_t) -> bool;
pub fn mi_option_enable(option: mi_option_t);
pub fn mi_option_disable(option: mi_option_t);
pub fn mi_option_set_enabled(option: mi_option_t, enable: bool);
pub fn mi_option_set_enabled_default(option: mi_option_t, enable: bool);
pub fn mi_option_get(option: mi_option_t) -> core::ffi::c_long;
pub fn mi_option_get_clamp(
option: mi_option_t,
min: core::ffi::c_long,
max: core::ffi::c_long,
) -> core::ffi::c_long;
pub fn mi_option_get_size(option: mi_option_t) -> usize;
pub fn mi_option_set(option: mi_option_t, value: core::ffi::c_long);
pub fn mi_option_set_default(option: mi_option_t, value: core::ffi::c_long);
pub fn mi_options_print_out(out: Option<mi_output_fun>, arg: *mut c_void);
pub fn mi_stats_get(stats: *mut mi_stats_t) -> bool;
pub fn mi_stats_get_json(buf_size: usize, buf: *mut c_char) -> *mut c_char;
pub fn mi_stats_as_json(
stats: *mut mi_stats_t,
buf_size: usize,
buf: *mut c_char,
) -> *mut c_char;
pub fn mi_stats_print_out(out: Option<mi_output_fun>, arg: *mut c_void);
pub fn mi_stats_get_bin_size(bin: usize) -> usize;
pub fn mi_heap_stats_get(heap: *mut mi_heap_t, stats: *mut mi_stats_t) -> bool;
pub fn mi_heap_stats_get_json(
heap: *mut mi_heap_t,
buf_size: usize,
buf: *mut c_char,
) -> *mut c_char;
pub fn mi_heap_stats_print_out(
heap: *mut mi_heap_t,
out: Option<mi_output_fun>,
arg: *mut c_void,
);
pub fn mi_heap_stats_merge_to_subproc(heap: *mut mi_heap_t);
pub fn mi_subproc_stats_get(subproc_id: mi_subproc_id_t, stats: *mut mi_stats_t) -> bool;
pub fn mi_subproc_stats_get_exclusive(
subproc_id: mi_subproc_id_t,
stats: *mut mi_stats_t,
) -> bool;
pub fn mi_subproc_stats_get_json(
subproc_id: mi_subproc_id_t,
buf_size: usize,
buf: *mut c_char,
) -> *mut c_char;
pub fn mi_subproc_stats_print_out(
subproc_id: mi_subproc_id_t,
out: Option<mi_output_fun>,
arg: *mut c_void,
);
pub fn mi_subproc_heap_stats_print_out(
subproc_id: mi_subproc_id_t,
out: Option<mi_output_fun>,
arg: *mut c_void,
);
pub fn mi_subproc_main() -> mi_subproc_id_t;
pub fn mi_subproc_current() -> mi_subproc_id_t;
pub fn mi_memory_tracking_set_enabled(enabled: bool) -> bool;
pub fn mi_memory_tracking_is_enabled() -> bool;
pub fn mi_memory_set_callbacks(callbacks: *const mi_memory_callbacks_t) -> bool;
pub fn mi_memory_snapshot(out: *mut mi_memory_snapshot_t) -> bool;
pub fn mi_memory_visit_live_allocations(
visitor: mi_memory_allocation_visit_fun,
arg: *mut c_void,
) -> bool;
pub fn mi_rs_layout_table(count: *mut usize) -> *const MiRsLayoutEntry;
}