From 267375cfc92421feff2eee65fc4de99d9b500b80 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Wed, 12 May 2021 00:08:15 +0200 Subject: [PATCH] more alloc stats --- allocation_stats.hpp | 29 +++++++++++++++++++++++++++-- macros.hpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/allocation_stats.hpp b/allocation_stats.hpp index 50c40ba..1e3d204 100644 --- a/allocation_stats.hpp +++ b/allocation_stats.hpp @@ -3,6 +3,7 @@ #include #include "types.hpp" +#include "macros.hpp" #ifdef USE_FTB_MALLOC namespace Ftb_Malloc_Stats { @@ -21,8 +22,8 @@ namespace Ftb_Malloc_Stats { void print_malloc_stats() { printf("\n" - "Malloc Stats:\n" - "-------------\n" + "Global Malloc Stats:\n" + "--------------------\n" " ftb_malloc calls: %u\n" " ftb_free calls: %u\n" " ftb_realloc calls: %u\n" @@ -34,6 +35,30 @@ void print_malloc_stats() { Ftb_Malloc_Stats::calloc_calls, Ftb_Malloc_Stats::alloca_calls); } + +#define profile_mallocs \ + MPP_DECLARE(0, u32 MPI_LABEL(profile_mallocs, old_malloc_calls) = Ftb_Malloc_Stats::malloc_calls) \ + MPP_DECLARE(1, u32 MPI_LABEL(profile_mallocs, old_free_calls) = Ftb_Malloc_Stats::free_calls) \ + MPP_DECLARE(2, u32 MPI_LABEL(profile_mallocs, old_realloc_calls) = Ftb_Malloc_Stats::realloc_calls) \ + MPP_DECLARE(3, u32 MPI_LABEL(profile_mallocs, old_calloc_calls) = Ftb_Malloc_Stats::calloc_calls) \ + MPP_DECLARE(4, u32 MPI_LABEL(profile_mallocs, old_alloca_calls) = Ftb_Malloc_Stats::alloca_calls) \ + MPP_AFTER(5, { \ + printf("\n" \ + "Local Malloc Stats: (%s %s %d)\n" \ + "-------------------\n" \ + " ftb_malloc calls: %u\n" \ + " ftb_free calls: %u\n" \ + " ftb_realloc calls: %u\n" \ + " ftb_calloc calls: %u\n" \ + " ftb_alloca calls: %u\n" , \ + __func__, __FILE__, __LINE__, \ + Ftb_Malloc_Stats::malloc_calls - MPI_LABEL(profile_mallocs, old_malloc_calls) , \ + Ftb_Malloc_Stats::free_calls - MPI_LABEL(profile_mallocs, old_free_calls) , \ + Ftb_Malloc_Stats::realloc_calls - MPI_LABEL(profile_mallocs, old_realloc_calls) , \ + Ftb_Malloc_Stats::calloc_calls - MPI_LABEL(profile_mallocs, old_calloc_calls) , \ + Ftb_Malloc_Stats::alloca_calls - MPI_LABEL(profile_mallocs, old_alloca_calls)); \ + }) + #else # define ftb_malloc malloc # define ftb_realloc realloc diff --git a/macros.hpp b/macros.hpp index f2a67b5..692afea 100644 --- a/macros.hpp +++ b/macros.hpp @@ -13,6 +13,43 @@ #define label(x, y) concat(x, y) #define line_label(x) label(x, __LINE__) +#define MPI_LABEL(id1,id2) \ + concat(MPI_LABEL_ ## id1 ## _ ## id2 ## _, __LINE__) + +#define MPP_DECLARE(labid, declaration) \ + if (0) \ + ; \ + else \ + for (declaration;;) \ + if (1) { \ + goto MPI_LABEL(labid, body); \ + MPI_LABEL(labid, done): break; \ + } else \ + while (1) \ + if (1) \ + goto MPI_LABEL(labid, done); \ + else \ + MPI_LABEL(labid, body): + +#define MPP_BEFORE(labid,before) \ + if (1) { \ + before; \ + goto MPI_LABEL(labid, body); \ + } else \ + MPI_LABEL(labid, body): + +#define MPP_AFTER(labid,after) \ + if (1) \ + goto MPI_LABEL(labid, body); \ + else \ + while (1) \ + if (1) { \ + after; \ + break; \ + } else \ + MPI_LABEL(labid, body): + + // #ifndef min // #define min(a, b) ((a) < (b)) ? (a) : (b) // #endif