mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-01 01:04:37 +03:00
fix stats_add condition
This commit is contained in:
parent
56aba086ea
commit
18174400b2
2 changed files with 16 additions and 15 deletions
23
src/stats.c
23
src/stats.c
|
@ -38,10 +38,8 @@ static void mi_stat_update(mi_stat_count_t* stat, int64_t amount) {
|
|||
else {
|
||||
// add thread local
|
||||
stat->current += amount;
|
||||
if (stat->current > stat->peak) stat->peak = stat->current;
|
||||
if (amount > 0) {
|
||||
stat->total += amount;
|
||||
}
|
||||
if (stat->current > stat->peak) { stat->peak = stat->current; }
|
||||
if (amount > 0) { stat->total += amount; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,16 +65,17 @@ void _mi_stat_decrease(mi_stat_count_t* stat, size_t amount) {
|
|||
// must be thread safe as it is called from stats_merge
|
||||
static void mi_stat_add(mi_stat_count_t* stat, const mi_stat_count_t* src) {
|
||||
if (stat==src) return;
|
||||
if (src->total==0) return;
|
||||
mi_atomic_addi64_relaxed( &stat->total, src->total);
|
||||
mi_atomic_addi64_relaxed( &stat->current, src->current);
|
||||
if (src->total!=0) { mi_atomic_addi64_relaxed(&stat->total, src->total); }
|
||||
if (src->current!=0) { mi_atomic_addi64_relaxed(&stat->current, src->current); }
|
||||
// peak scores do really not work across threads ... we use conservative max
|
||||
mi_atomic_maxi64_relaxed( &stat->peak, src->peak); // or: mi_atomic_addi64_relaxed( &stat->peak, src->peak);
|
||||
if (src->peak > stat->peak) {
|
||||
mi_atomic_maxi64_relaxed(&stat->peak, src->peak); // or: mi_atomic_addi64_relaxed( &stat->peak, src->peak);
|
||||
}
|
||||
}
|
||||
|
||||
static void mi_stat_counter_add(mi_stat_counter_t* stat, const mi_stat_counter_t* src) {
|
||||
if (stat==src) return;
|
||||
mi_atomic_addi64_relaxed( &stat->total, src->total);
|
||||
if (src->total!=0) { mi_atomic_addi64_relaxed(&stat->total, src->total); }
|
||||
}
|
||||
|
||||
// must be thread safe as it is called from stats_merge
|
||||
|
@ -113,9 +112,9 @@ static void mi_stats_add(mi_stats_t* stats, const mi_stats_t* src) {
|
|||
mi_stat_counter_add(&stats->guarded_alloc_count, &src->guarded_alloc_count);
|
||||
#if MI_STAT>1
|
||||
for (size_t i = 0; i <= MI_BIN_HUGE; i++) {
|
||||
if (src->normal_bins[i].total > 0) {
|
||||
mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i]);
|
||||
}
|
||||
// if (src->normal_bins[i].total != 0 && src->normal_bins[i].current != 0) {
|
||||
mi_stat_add(&stats->normal_bins[i], &src->normal_bins[i]);
|
||||
//}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -285,9 +285,6 @@ int main(int argc, char** argv) {
|
|||
#if !defined(NDEBUG) && !defined(USE_STD_MALLOC)
|
||||
mi_option_set(mi_option_arena_reserve, 32 * 1024 /* in kib = 32MiB */);
|
||||
#endif
|
||||
#ifndef USE_STD_MALLOC
|
||||
mi_stats_reset();
|
||||
#endif
|
||||
|
||||
// > mimalloc-test-stress [THREADS] [SCALE] [ITER]
|
||||
if (argc >= 2) {
|
||||
|
@ -309,6 +306,11 @@ int main(int argc, char** argv) {
|
|||
allow_large_objects = true;
|
||||
}
|
||||
printf("Using %d threads with a %d%% load-per-thread and %d iterations %s\n", THREADS, SCALE, ITER, (allow_large_objects ? "(allow large objects)" : ""));
|
||||
|
||||
#if !defined(NDEBUG) && !defined(USE_STD_MALLOC)
|
||||
mi_stats_reset();
|
||||
#endif
|
||||
|
||||
//mi_reserve_os_memory(1024*1024*1024ULL, false, true);
|
||||
//int res = mi_reserve_huge_os_pages(4,1);
|
||||
//printf("(reserve huge: %i\n)", res);
|
||||
|
|
Loading…
Add table
Reference in a new issue