diff --git a/.gitignore b/.gitignore index f8b7f5eb..66450f80 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,8 @@ ide/vs20??/*.vcxproj.filters ide/vs20??/.vs ide/vs20??/VTune* out/ +bld/ +.cache* +compile_commands.json docs/ *.zip diff --git a/include/mimalloc.h b/include/mimalloc.h index 7f09d1aa..d00e5364 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -154,6 +154,8 @@ mi_decl_export void mi_stats_reset(void) mi_attr_noexcept; mi_decl_export void mi_stats_merge(void) mi_attr_noexcept; mi_decl_export void mi_stats_print(void* out) mi_attr_noexcept; // backward compatibility: `out` is ignored and should be NULL mi_decl_export void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept; +mi_decl_export void mi_thread_stats(int64_t *allocated, int64_t *committed, + int64_t *reserved) mi_attr_noexcept; mi_decl_export void mi_process_init(void) mi_attr_noexcept; mi_decl_export void mi_thread_init(void) mi_attr_noexcept; diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index 2005238a..f35f2af0 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -46,7 +46,7 @@ terms of the MIT license. A copy of the license can be found in the file // #define MI_TRACK_ETW 1 // Define MI_STAT as 1 to maintain statistics; set it to 2 to have detailed statistics (but costs some performance). -// #define MI_STAT 1 +#define MI_STAT 1 // Define MI_SECURE to enable security mitigations // #define MI_SECURE 1 // guard page around metadata diff --git a/src/alloc.c b/src/alloc.c index ffc1747d..84b01f1e 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -562,7 +562,8 @@ void mi_free(void* p) mi_attr_noexcept { if mi_unlikely(p == NULL) return; mi_segment_t* const segment = mi_checked_ptr_segment(p,"mi_free"); - const bool is_local= (_mi_prim_thread_id() == mi_atomic_load_relaxed(&segment->thread_id)); + const bool is_local = + (_mi_thread_id() == mi_atomic_load_relaxed(&segment->thread_id)); mi_page_t* const page = _mi_segment_page_of(segment, p); if mi_likely(is_local) { // thread-local free? diff --git a/src/stats.c b/src/stats.c index 300956ce..78b1cb7e 100644 --- a/src/stats.c +++ b/src/stats.c @@ -5,9 +5,10 @@ terms of the MIT license. A copy of the license can be found in the file "LICENSE" at the root of this distribution. -----------------------------------------------------------------------------*/ #include "mimalloc.h" -#include "mimalloc/internal.h" #include "mimalloc/atomic.h" +#include "mimalloc/internal.h" #include "mimalloc/prim.h" +#include "mimalloc/types.h" #include // snprintf #include // memset @@ -412,6 +413,18 @@ void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept { _mi_stats_print(mi_stats_get_default(), out, arg); } +void mi_thread_stats(int64_t *allocated, int64_t *committed, + int64_t *reserved) mi_attr_noexcept { + mi_stats_t *stat = mi_stats_get_default(); + if (stat != NULL) { + *reserved = stat->reserved.current; + *committed = stat->page_committed.current; + *allocated = 1; + *allocated += stat->normal.current; + *allocated += stat->large.current; + *allocated += stat->huge.current; + } +} // ---------------------------------------------------------------- // Basic timer for convenience; use milli-seconds to avoid doubles