#pragma once
#ifndef MIMALLOC_PROFILE_H
#define MIMALLOC_PROFILE_H
#include "mimalloc.h"
#include <stdbool.h>
#include <stdint.h>
#define MI_PROFILE_SAMPLE_DATA_MAX_SIZE (1024)
typedef struct mi_profiler_s mi_profiler_t;
typedef struct mi_profiler_sample_data_s {
size_t user_data_size; void* user_data[1]; } mi_profiler_sample_data_t;
typedef size_t (mi_cdecl mi_profiler_on_alloc_fun)(mi_profiler_t* profiler, mi_profiler_sample_data_t* profiler_data, void* ptr, size_t requested_size, size_t bytes_sample_rate, uint64_t bytes_since_last_sample, mi_heap_t* heap);
typedef size_t (mi_cdecl mi_profiler_on_realloc_inplace_fun)(mi_profiler_t* profiler, mi_profiler_sample_data_t* profiler_data, void* ptr, size_t old_size, mi_heap_t* heap);
typedef void (mi_cdecl mi_profiler_on_free_fun)(mi_profiler_t* profiler, mi_profiler_sample_data_t* profiler_data, void* ptr, mi_heap_t* heap);
typedef void (mi_cdecl mi_profiler_on_snapshot_fun)(mi_profiler_t* profiler);
struct mi_profiler_s {
void* reserved; size_t sample_data_size; size_t initial_sample_rate; mi_profiler_on_alloc_fun* on_alloc; mi_profiler_on_free_fun* on_free; mi_profiler_on_realloc_inplace_fun* on_realloc_inplace; mi_profiler_on_snapshot_fun* on_snapshot; };
#ifdef __cplusplus
extern "C" {
#endif
mi_decl_export bool mi_heap_profile(mi_heap_t* heap, mi_profiler_t* profiler);
mi_decl_export void mi_heap_profile_disable(mi_heap_t* heap);
mi_decl_export bool mi_subproc_profile(mi_subproc_id_t subproc_id, mi_profiler_t* profiler);
mi_decl_export bool mi_profile(mi_profiler_t* profiler);
mi_decl_export bool mi_profiler_start(mi_profiler_t* profiler);
mi_decl_export bool mi_profiler_stop(mi_profiler_t* profiler);
mi_decl_export void mi_profiler_snapshot(mi_profiler_t* profiler);
mi_decl_export mi_profiler_t* mi_pprof_profiler_new(size_t initial_threshold, const char* base_file_name, size_t alloc_interval_size, size_t inuse_interval_size, size_t time_interval_secs);
mi_decl_export void mi_pprof_profiler_delete(mi_profiler_t* profiler);
#ifdef __cplusplus
}
#endif
#endif