diff --git a/apps/decoder.c b/apps/decoder.c index 64779c92b1ab628784c1afa4cb90af417e8c7d1c..6f73723af1b7d21049c50acc6502adb70ba72c8b 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1484,6 +1484,11 @@ static ivas_error decodeG192( } #ifdef WMOPS update_wmops(); +#endif +#ifdef DEBUGGING +#ifdef RAM_ANALYSIS + mem_analyze(); +#endif #endif } @@ -1840,6 +1845,11 @@ static ivas_error decodeVoIP( #ifdef WMOPS update_wmops(); +#endif +#ifdef DEBUGGING +#ifdef RAM_ANALYSIS + mem_analyze(); +#endif #endif } diff --git a/apps/encoder.c b/apps/encoder.c index e9325ded5945c2f368a97517505d7a862e9da9c6..0bad34878bedc00a8d67d921b9a953db0af9531f 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -765,6 +765,11 @@ int main( #ifdef WMOPS update_wmops(); +#endif +#ifdef DEBUGGING +#ifdef RAM_ANALYSIS + mem_analyze(); +#endif #endif } diff --git a/lib_com/options.h b/lib_com/options.h index 4e0d5ba58fea090c47e0bb8dcd73d38d9c422229..68e801b352a368a5240b03fa358873a31eaceaa9 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -55,6 +55,7 @@ /*#define WMOPS_PER_FRAME*/ /* Output complexity in WMOPS per frame to the file "res/wmops" (one float value per frame) */ /*#define WMOPS_DETAIL*/ /* Activate complexity detail printout for every function. Increases runtime overhead */ /*#define WMOPS_WC_FRAME_ANALYSIS*/ /* Output WMOPS analysis for worst case frame */ +/*#define RAM_ANALYSIS*/ /* Output memory allocated with count_malloc each frame. Can be parsed and plotted with scripts/mem_analysis.m */ #ifdef DEBUGGING diff --git a/lib_debug/mem_count.c b/lib_debug/mem_count.c index ca4832399fa4708b45e0da4ef4274ba31aaf5dd3..278126d35e0b25bff1bad675f77a36f38e8bcc42 100644 --- a/lib_debug/mem_count.c +++ b/lib_debug/mem_count.c @@ -49,6 +49,10 @@ typedef INT64 int64_t; #define FALSE 0 #endif +#ifdef RAM_ANALYSIS +#include "debug.h" +#endif + /* How to use the tool notes ========================= @@ -906,4 +910,24 @@ size_t mem_count_summary( Counting_Size cnt_size ) return size; } +#ifdef DEBUGGING +#ifdef RAM_ANALYSIS +void mem_analyze( void ) +{ + unsigned int i; + char buffer[1024]; + + for ( i = 0; i < Num_Records_Cur_RAM; i++ ) + { + sprintf( buffer, "%s:%d,%ld;", Current_Allocations[i].name, Current_Allocations[i].lineno, Current_Allocations[i].block_size ); + dbgwrite( buffer, sizeof( char ), strlen( buffer ), 1, "mem_analysis.csv" ); + } + sprintf( buffer, "\n" ); + dbgwrite( buffer, sizeof( char ), strlen( buffer ), 1, "mem_analysis.csv" ); + + return; +} +#endif +#endif + #endif diff --git a/lib_debug/mem_count.h b/lib_debug/mem_count.h index d30fc3ab1ada926bbbeb4aaa4ed2eedc8ca4359b..38ccb0bac6ca236d970888f4461281830fa9f235 100644 --- a/lib_debug/mem_count.h +++ b/lib_debug/mem_count.h @@ -95,6 +95,12 @@ extern "C" extern void *mem_alloc( const char *func_name, int func_lineno, size_t size, char *alloc_str ); extern void mem_free( const char *func_name, int func_lineno, void *ptr ); +#ifdef DEBUGGING +#ifdef RAM_ANALYSIS + extern void mem_analyze( void ); +#endif +#endif + #ifdef __cplusplus } #endif diff --git a/scripts/mem_analysis.m b/scripts/mem_analysis.m new file mode 100644 index 0000000000000000000000000000000000000000..ad75efa1c759ee613a1a5784b13a12b6c4325c7d --- /dev/null +++ b/scripts/mem_analysis.m @@ -0,0 +1,38 @@ +%% + +lines = readlines('../mem_analysis.csv','EmptyLineRule','skip'); + +names = {}; +Nframes = length(lines); + +mem = zeros(1,Nframes); + +% Load mem_analysis.csv into matrix +for i = 1:Nframes + entries = split(lines(i),';'); + for j = 1:length(entries) + a = split(entries(j),','); + if(length(a)==2) + name = a{1}; + num = str2double(a{2}); + I = find(strcmp(names,name)); + if isempty(I) + names{end+1} = name; + I = length(names); + end + mem(I,i) = num; + end + end +end + +% Reorder the matrix such that the fixed allocations are at the bottom: +% --> Find all rows which are constant (sum of abs diff is zero). The >0 is +% to limit the reordering to constant values only. +[~,indx] = sort(sum(abs(diff(mem,[],2)),2)>0); +mem = mem(indx,:); +names = names(indx); + +bar(mem',1,'stacked') +legend(names,'location','eastoutside','interpreter','none') +xlabel('frame') +ylabel('memory size') \ No newline at end of file