mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-19 13:39:31 +03:00
Collect thread local stats
This commit is contained in:
parent
84f48a2715
commit
e47379461e
5 changed files with 22 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,5 +5,8 @@ ide/vs20??/*.vcxproj.filters
|
|||
ide/vs20??/.vs
|
||||
ide/vs20??/VTune*
|
||||
out/
|
||||
bld/
|
||||
.cache*
|
||||
compile_commands.json
|
||||
docs/
|
||||
*.zip
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
15
src/stats.c
15
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 <stdio.h> // snprintf
|
||||
#include <string.h> // 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
|
||||
|
|
Loading…
Add table
Reference in a new issue