Improve SHOW_MEMORY accounting
This commit is contained in:
17
Internal.h
17
Internal.h
@@ -27,8 +27,8 @@ inline bool debugVerboseEnabled = true;
|
||||
// GCOVR_EXCL_START
|
||||
|
||||
#if SHOW_MEMORY
|
||||
inline int64_t mallocBytes = 0;
|
||||
inline int64_t peakMallocBytes = 0;
|
||||
inline __attribute__((visibility("default"))) int64_t mallocBytes = 0;
|
||||
inline __attribute__((visibility("default"))) int64_t peakMallocBytes = 0;
|
||||
#endif
|
||||
|
||||
inline thread_local int64_t mallocBytesDelta = 0;
|
||||
@@ -108,6 +108,19 @@ __attribute__((always_inline)) inline void safe_free(void *p, size_t s) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
#if SHOW_MEMORY
|
||||
inline __attribute__((visibility("default"))) bool showedMemory = false;
|
||||
static struct __attribute__((visibility("default"))) PeakPrinter {
|
||||
~PeakPrinter() {
|
||||
if (!std::exchange(showedMemory, true)) {
|
||||
printf("--- memory usage ---\n");
|
||||
printf("malloc bytes: %g\n", double(mallocBytes));
|
||||
printf("Peak malloc bytes: %g\n", double(peakMallocBytes));
|
||||
}
|
||||
}
|
||||
} peakPrinter;
|
||||
#endif
|
||||
|
||||
// ==================== BEGIN ARENA IMPL ====================
|
||||
|
||||
/// Group allocations with similar lifetimes to amortize the cost of malloc/free
|
||||
|
Reference in New Issue
Block a user