mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-27 13:33:18 +08:00
Merge branch 'dev' into dev-slice
This commit is contained in:
commit
b59abce8ea
@ -8,7 +8,7 @@ terms of the MIT license. A copy of the license can be found in the file
|
|||||||
#ifndef MIMALLOC_H
|
#ifndef MIMALLOC_H
|
||||||
#define MIMALLOC_H
|
#define MIMALLOC_H
|
||||||
|
|
||||||
#define MI_MALLOC_VERSION 166 // major + 2 digits minor
|
#define MI_MALLOC_VERSION 167 // major + 2 digits minor
|
||||||
|
|
||||||
// ------------------------------------------------------
|
// ------------------------------------------------------
|
||||||
// Compiler specific attributes
|
// Compiler specific attributes
|
||||||
@ -153,7 +153,9 @@ mi_decl_export void mi_thread_init(void) mi_attr_noexcept;
|
|||||||
mi_decl_export void mi_thread_done(void) mi_attr_noexcept;
|
mi_decl_export void mi_thread_done(void) mi_attr_noexcept;
|
||||||
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
|
mi_decl_export void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept;
|
||||||
|
|
||||||
mi_decl_export void mi_process_info(size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
|
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs,
|
||||||
|
size_t* current_rss, size_t* peak_rss,
|
||||||
|
size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept;
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// Aligned allocation
|
// Aligned allocation
|
||||||
|
@ -73,7 +73,7 @@ Enjoy!
|
|||||||
|
|
||||||
### Releases
|
### Releases
|
||||||
|
|
||||||
* 2020-09-24, `v1.6.5`: stable release 1.6: using standard C atomics, passing tsan testing, improved
|
* 2020-09-24, `v1.6.6`: stable release 1.6: using standard C atomics, passing tsan testing, improved
|
||||||
handling of failing to commit on Windows, add `mi_process_info` api call.
|
handling of failing to commit on Windows, add `mi_process_info` api call.
|
||||||
* 2020-08-06, `v1.6.4`: stable release 1.6: improved error recovery in low-memory situations,
|
* 2020-08-06, `v1.6.4`: stable release 1.6: improved error recovery in low-memory situations,
|
||||||
support for IllumOS and Haiku, NUMA support for Vista/XP, improved NUMA detection for AMD Ryzen, ubsan support.
|
support for IllumOS and Haiku, NUMA support for Vista/XP, improved NUMA detection for AMD Ryzen, ubsan support.
|
||||||
|
42
src/stats.c
42
src/stats.c
@ -276,9 +276,9 @@ static void mi_buffered_out(const char* msg, void* arg) {
|
|||||||
// Print statistics
|
// Print statistics
|
||||||
//------------------------------------------------------------
|
//------------------------------------------------------------
|
||||||
|
|
||||||
static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults);
|
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults);
|
||||||
|
|
||||||
static void _mi_stats_print(mi_stats_t* stats, mi_msecs_t elapsed, mi_output_fun* out0, void* arg0) mi_attr_noexcept {
|
static void _mi_stats_print(mi_stats_t* stats, mi_output_fun* out0, void* arg0) mi_attr_noexcept {
|
||||||
// wrap the output function to be line buffered
|
// wrap the output function to be line buffered
|
||||||
char buf[256];
|
char buf[256];
|
||||||
buffered_t buffer = { out0, arg0, NULL, 0, 255 };
|
buffered_t buffer = { out0, arg0, NULL, 0, 255 };
|
||||||
@ -319,8 +319,8 @@ static void _mi_stats_print(mi_stats_t* stats, mi_msecs_t elapsed, mi_output_fun
|
|||||||
mi_stat_print(&stats->threads, "threads", -1, out, arg);
|
mi_stat_print(&stats->threads, "threads", -1, out, arg);
|
||||||
mi_stat_counter_print_avg(&stats->searches, "searches", out, arg);
|
mi_stat_counter_print_avg(&stats->searches, "searches", out, arg);
|
||||||
_mi_fprintf(out, arg, "%10s: %7i\n", "numa nodes", _mi_os_numa_node_count());
|
_mi_fprintf(out, arg, "%10s: %7i\n", "numa nodes", _mi_os_numa_node_count());
|
||||||
if (elapsed > 0) _mi_fprintf(out, arg, "%10s: %7ld.%03ld s\n", "elapsed", elapsed/1000, elapsed%1000);
|
|
||||||
|
mi_msecs_t elapsed;
|
||||||
mi_msecs_t user_time;
|
mi_msecs_t user_time;
|
||||||
mi_msecs_t sys_time;
|
mi_msecs_t sys_time;
|
||||||
size_t current_rss;
|
size_t current_rss;
|
||||||
@ -328,8 +328,9 @@ static void _mi_stats_print(mi_stats_t* stats, mi_msecs_t elapsed, mi_output_fun
|
|||||||
size_t current_commit;
|
size_t current_commit;
|
||||||
size_t peak_commit;
|
size_t peak_commit;
|
||||||
size_t page_faults;
|
size_t page_faults;
|
||||||
mi_stat_process_info(&user_time, &sys_time, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults);
|
mi_stat_process_info(&elapsed, &user_time, &sys_time, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults);
|
||||||
_mi_fprintf(out, arg, "%10s: user: %ld.%03ld s, system: %ld.%03ld s, faults: %lu, rss: ", "process",
|
_mi_fprintf(out, arg, "%10s: %7ld.%03ld s\n", "elapsed", elapsed/1000, elapsed%1000);
|
||||||
|
_mi_fprintf(out, arg, "%10s: user: %ld.%03ld s, system: %ld.%03ld s, faults: %lu, rss: ", "process",
|
||||||
user_time/1000, user_time%1000, sys_time/1000, sys_time%1000, (unsigned long)page_faults );
|
user_time/1000, user_time%1000, sys_time/1000, sys_time%1000, (unsigned long)page_faults );
|
||||||
mi_printf_amount((int64_t)peak_rss, 1, out, arg, "%s");
|
mi_printf_amount((int64_t)peak_rss, 1, out, arg, "%s");
|
||||||
if (peak_commit > 0) {
|
if (peak_commit > 0) {
|
||||||
@ -339,7 +340,7 @@ static void _mi_stats_print(mi_stats_t* stats, mi_msecs_t elapsed, mi_output_fun
|
|||||||
_mi_fprintf(out, arg, "\n");
|
_mi_fprintf(out, arg, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static mi_msecs_t mi_time_start; // = 0
|
static mi_msecs_t mi_process_start; // = 0
|
||||||
|
|
||||||
static mi_stats_t* mi_stats_get_default(void) {
|
static mi_stats_t* mi_stats_get_default(void) {
|
||||||
mi_heap_t* heap = mi_heap_get_default();
|
mi_heap_t* heap = mi_heap_get_default();
|
||||||
@ -357,7 +358,7 @@ void mi_stats_reset(void) mi_attr_noexcept {
|
|||||||
mi_stats_t* stats = mi_stats_get_default();
|
mi_stats_t* stats = mi_stats_get_default();
|
||||||
if (stats != &_mi_stats_main) { memset(stats, 0, sizeof(mi_stats_t)); }
|
if (stats != &_mi_stats_main) { memset(stats, 0, sizeof(mi_stats_t)); }
|
||||||
memset(&_mi_stats_main, 0, sizeof(mi_stats_t));
|
memset(&_mi_stats_main, 0, sizeof(mi_stats_t));
|
||||||
mi_time_start = _mi_clock_start();
|
if (mi_process_start == 0) { mi_process_start = _mi_clock_start(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
void mi_stats_merge(void) mi_attr_noexcept {
|
void mi_stats_merge(void) mi_attr_noexcept {
|
||||||
@ -369,9 +370,8 @@ void _mi_stats_done(mi_stats_t* stats) { // called from `mi_thread_done`
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
|
void mi_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
|
||||||
mi_msecs_t elapsed = _mi_clock_end(mi_time_start);
|
|
||||||
mi_stats_merge_from(mi_stats_get_default());
|
mi_stats_merge_from(mi_stats_get_default());
|
||||||
_mi_stats_print(&_mi_stats_main, elapsed, out, arg);
|
_mi_stats_print(&_mi_stats_main, out, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mi_stats_print(void* out) mi_attr_noexcept {
|
void mi_stats_print(void* out) mi_attr_noexcept {
|
||||||
@ -380,8 +380,7 @@ void mi_stats_print(void* out) mi_attr_noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
|
void mi_thread_stats_print_out(mi_output_fun* out, void* arg) mi_attr_noexcept {
|
||||||
mi_msecs_t elapsed = _mi_clock_end(mi_time_start);
|
_mi_stats_print(mi_stats_get_default(), out, arg);
|
||||||
_mi_stats_print(mi_stats_get_default(), elapsed, out, arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -456,8 +455,9 @@ static mi_msecs_t filetime_msecs(const FILETIME* ftime) {
|
|||||||
return msecs;
|
return msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
||||||
{
|
{
|
||||||
|
*elapsed = _mi_clock_end(mi_process_start);
|
||||||
FILETIME ct;
|
FILETIME ct;
|
||||||
FILETIME ut;
|
FILETIME ut;
|
||||||
FILETIME st;
|
FILETIME st;
|
||||||
@ -491,8 +491,9 @@ static mi_msecs_t timeval_secs(const struct timeval* tv) {
|
|||||||
return ((mi_msecs_t)tv->tv_sec * 1000L) + ((mi_msecs_t)tv->tv_usec / 1000L);
|
return ((mi_msecs_t)tv->tv_sec * 1000L) + ((mi_msecs_t)tv->tv_usec / 1000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
||||||
{
|
{
|
||||||
|
*elapsed = _mi_clock_end(mi_process_start);
|
||||||
struct rusage rusage;
|
struct rusage rusage;
|
||||||
getrusage(RUSAGE_SELF, &rusage);
|
getrusage(RUSAGE_SELF, &rusage);
|
||||||
*utime = timeval_secs(&rusage.ru_utime);
|
*utime = timeval_secs(&rusage.ru_utime);
|
||||||
@ -532,8 +533,9 @@ static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* c
|
|||||||
#pragma message("define a way to get process info")
|
#pragma message("define a way to get process info")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
static void mi_stat_process_info(mi_msecs_t* elapsed, mi_msecs_t* utime, mi_msecs_t* stime, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults)
|
||||||
{
|
{
|
||||||
|
*elapsed = _mi_clock_end(mi_process_start);
|
||||||
*peak_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.peak));
|
*peak_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.peak));
|
||||||
*current_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.current));
|
*current_commit = (size_t)(mi_atomic_loadi64_relaxed((_Atomic(int64_t)*)&_mi_stats_main.committed.current));
|
||||||
*peak_rss = *peak_commit;
|
*peak_rss = *peak_commit;
|
||||||
@ -545,8 +547,9 @@ static void mi_stat_process_info(mi_msecs_t* utime, mi_msecs_t* stime, size_t* c
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
mi_decl_export void mi_process_info(size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept
|
mi_decl_export void mi_process_info(size_t* elapsed_msecs, size_t* user_msecs, size_t* system_msecs, size_t* current_rss, size_t* peak_rss, size_t* current_commit, size_t* peak_commit, size_t* page_faults) mi_attr_noexcept
|
||||||
{
|
{
|
||||||
|
mi_msecs_t elapsed = 0;
|
||||||
mi_msecs_t utime = 0;
|
mi_msecs_t utime = 0;
|
||||||
mi_msecs_t stime = 0;
|
mi_msecs_t stime = 0;
|
||||||
size_t current_rss0 = 0;
|
size_t current_rss0 = 0;
|
||||||
@ -554,9 +557,10 @@ mi_decl_export void mi_process_info(size_t* user_msecs, size_t* system_msecs, si
|
|||||||
size_t current_commit0 = 0;
|
size_t current_commit0 = 0;
|
||||||
size_t peak_commit0 = 0;
|
size_t peak_commit0 = 0;
|
||||||
size_t page_faults0 = 0;
|
size_t page_faults0 = 0;
|
||||||
mi_stat_process_info(&utime, &stime, ¤t_rss0, &peak_rss0, ¤t_commit0, &peak_commit0, &page_faults0);
|
mi_stat_process_info(&elapsed,&utime, &stime, ¤t_rss0, &peak_rss0, ¤t_commit0, &peak_commit0, &page_faults0);
|
||||||
if (user_msecs!=NULL) *user_msecs = (utime < 0 ? 0 : (utime < (mi_msecs_t)SIZE_MAX ? (size_t)utime : SIZE_MAX));
|
if (elapsed_msecs!=NULL) *elapsed_msecs = (elapsed < 0 ? 0 : (elapsed < (mi_msecs_t)PTRDIFF_MAX ? (size_t)elapsed : PTRDIFF_MAX));
|
||||||
if (system_msecs!=NULL) *system_msecs = (stime < 0 ? 0 : (stime < (mi_msecs_t)SIZE_MAX ? (size_t)stime : SIZE_MAX));
|
if (user_msecs!=NULL) *user_msecs = (utime < 0 ? 0 : (utime < (mi_msecs_t)PTRDIFF_MAX ? (size_t)utime : PTRDIFF_MAX));
|
||||||
|
if (system_msecs!=NULL) *system_msecs = (stime < 0 ? 0 : (stime < (mi_msecs_t)PTRDIFF_MAX ? (size_t)stime : PTRDIFF_MAX));
|
||||||
if (current_rss!=NULL) *current_rss = current_rss0;
|
if (current_rss!=NULL) *current_rss = current_rss0;
|
||||||
if (peak_rss!=NULL) *peak_rss = peak_rss0;
|
if (peak_rss!=NULL) *peak_rss = peak_rss0;
|
||||||
if (current_commit!=NULL) *current_commit = current_commit0;
|
if (current_commit!=NULL) *current_commit = current_commit0;
|
||||||
|
@ -305,6 +305,7 @@ static void test_aslr(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_process_info(void) {
|
static void test_process_info(void) {
|
||||||
|
size_t elapsed = 0;
|
||||||
size_t user_msecs = 0;
|
size_t user_msecs = 0;
|
||||||
size_t system_msecs = 0;
|
size_t system_msecs = 0;
|
||||||
size_t current_rss = 0;
|
size_t current_rss = 0;
|
||||||
@ -316,8 +317,8 @@ static void test_process_info(void) {
|
|||||||
void* p = calloc(100,10);
|
void* p = calloc(100,10);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
mi_process_info(&user_msecs, &system_msecs, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults);
|
mi_process_info(&elapsed, &user_msecs, &system_msecs, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults);
|
||||||
printf("\n\n*** process info: user: %3zd.%03zd s, rss: %zd b, commit: %zd b\n\n", user_msecs/1000, user_msecs%1000, peak_rss, peak_commit);
|
printf("\n\n*** process info: elapsed %3zd.%03zd s, user: %3zd.%03zd s, rss: %zd b, commit: %zd b\n\n", elapsed/1000, elapsed%1000, user_msecs/1000, user_msecs%1000, peak_rss, peak_commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_reserved(void) {
|
static void test_reserved(void) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user