| 3352 | #endif |
| 3353 | |
| 3354 | void |
| 3355 | rpmalloc_dump_statistics(void* file) { |
| 3356 | #if ENABLE_STATISTICS |
| 3357 | for (size_t list_idx = 0; list_idx < HEAP_ARRAY_SIZE; ++list_idx) { |
| 3358 | heap_t* heap = _memory_heaps[list_idx]; |
| 3359 | while (heap) { |
| 3360 | int need_dump = 0; |
| 3361 | for (size_t iclass = 0; !need_dump && (iclass < SIZE_CLASS_COUNT); ++iclass) { |
| 3362 | if (!atomic_load32(&heap->size_class_use[iclass].alloc_total)) { |
| 3363 | rpmalloc_assert(!atomic_load32(&heap->size_class_use[iclass].free_total), "Heap statistics counter mismatch"); |
| 3364 | rpmalloc_assert(!atomic_load32(&heap->size_class_use[iclass].spans_map_calls), "Heap statistics counter mismatch"); |
| 3365 | continue; |
| 3366 | } |
| 3367 | need_dump = 1; |
| 3368 | } |
| 3369 | for (size_t iclass = 0; !need_dump && (iclass < LARGE_CLASS_COUNT); ++iclass) { |
| 3370 | if (!atomic_load32(&heap->span_use[iclass].high) && !atomic_load32(&heap->span_use[iclass].spans_map_calls)) |
| 3371 | continue; |
| 3372 | need_dump = 1; |
| 3373 | } |
| 3374 | if (need_dump) |
| 3375 | _memory_heap_dump_statistics(heap, file); |
| 3376 | heap = heap->next_heap; |
| 3377 | } |
| 3378 | } |
| 3379 | fprintf(file, "Global stats:\n"); |
| 3380 | size_t huge_current = (size_t)atomic_load32(&_huge_pages_current) * _memory_page_size; |
| 3381 | size_t huge_peak = (size_t)_huge_pages_peak * _memory_page_size; |
| 3382 | fprintf(file, "HugeCurrentMiB HugePeakMiB\n"); |
| 3383 | fprintf(file, "%14zu %11zu\n", huge_current / (size_t)(1024 * 1024), huge_peak / (size_t)(1024 * 1024)); |
| 3384 | |
| 3385 | #if ENABLE_GLOBAL_CACHE |
| 3386 | fprintf(file, "GlobalCacheMiB\n"); |
| 3387 | for (size_t iclass = 0; iclass < LARGE_CLASS_COUNT; ++iclass) { |
| 3388 | global_cache_t* cache = _memory_span_cache + iclass; |
| 3389 | size_t global_cache = (size_t)cache->count * iclass * _memory_span_size; |
| 3390 | |
| 3391 | size_t global_overflow_cache = 0; |
| 3392 | span_t* span = cache->overflow; |
| 3393 | while (span) { |
| 3394 | global_overflow_cache += iclass * _memory_span_size; |
| 3395 | span = span->next; |
| 3396 | } |
| 3397 | if (global_cache || global_overflow_cache || cache->insert_count || cache->extract_count) |
| 3398 | fprintf(file, "%4zu: %8zuMiB (%8zuMiB overflow) %14zu insert %14zu extract\n", iclass + 1, global_cache / (size_t)(1024 * 1024), global_overflow_cache / (size_t)(1024 * 1024), cache->insert_count, cache->extract_count); |
| 3399 | } |
| 3400 | #endif |
| 3401 | |
| 3402 | size_t mapped = (size_t)atomic_load32(&_mapped_pages) * _memory_page_size; |
| 3403 | size_t mapped_os = (size_t)atomic_load32(&_mapped_pages_os) * _memory_page_size; |
| 3404 | size_t mapped_peak = (size_t)_mapped_pages_peak * _memory_page_size; |
| 3405 | size_t mapped_total = (size_t)atomic_load32(&_mapped_total) * _memory_page_size; |
| 3406 | size_t unmapped_total = (size_t)atomic_load32(&_unmapped_total) * _memory_page_size; |
| 3407 | fprintf(file, "MappedMiB MappedOSMiB MappedPeakMiB MappedTotalMiB UnmappedTotalMiB\n"); |
| 3408 | fprintf(file, "%9zu %11zu %13zu %14zu %16zu\n", |
| 3409 | mapped / (size_t)(1024 * 1024), |
| 3410 | mapped_os / (size_t)(1024 * 1024), |
| 3411 | mapped_peak / (size_t)(1024 * 1024), |
nothing calls this directly
no test coverage detected