Loading lib_debug/wmc_auto.c +87 −14 Original line number Diff line number Diff line Loading @@ -491,9 +491,9 @@ typedef struct void* block_ptr; int block_size; int max_block_size; /* Maximum block size allocated */ int32_t wc_heap_size[2]; /* Worst-Case Heap [Frame#, Size] */ int32_t wc_heap_size_intra_frame[2]; /* Worst-Case Intra-Frame Heap [Frame#, Size] */ int32_t wc_heap_size_inter_frame[2]; /* Worst-Case Inter-Frame Heap [Frame#, Size] */ int32_t wc_heap_size[3]; /* Worst-Case Heap [Frame#, Size, Count] */ int32_t wc_heap_size_intra_frame[3]; /* Worst-Case Intra-Frame Heap [Frame#, Size, Count] */ int32_t wc_heap_size_inter_frame[3]; /* Worst-Case Inter-Frame Heap [Frame#, Size, Count] */ int frame_allocated; /* Frame number in which the Memory Block has been allocated */ float ave_usage; /* Average Usage of memory block calculated as ratio of used size and allocated size */ int OOB_Flag; Loading Loading @@ -784,10 +784,13 @@ void* mem_alloc( ptr_record->OOB_Flag = 0; ptr_record->wc_heap_size[0] = -1; ptr_record->wc_heap_size[1] = 0; ptr_record->wc_heap_size[2] = 1; ptr_record->wc_heap_size_intra_frame[0] = -1; ptr_record->wc_heap_size_intra_frame[1] = 0; ptr_record->wc_heap_size_intra_frame[2] = 1; ptr_record->wc_heap_size_inter_frame[0] = -1; ptr_record->wc_heap_size_inter_frame[1] = 0; ptr_record->wc_heap_size_inter_frame[2] = 1; Num_Records++; } Loading Loading @@ -1102,6 +1105,7 @@ allocator_record* get_mem_record(unsigned long* hash, const char* func_name, int return NULL; } /*-------------------------------------------------------------------* * mem_free() * Loading Loading @@ -1158,11 +1162,11 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) } /* Update Worst-Case Intra-Frame Heap Size, if Exceeded */ if (ptr_record->frame_allocated == update_cnt && current_heap_size_intra_frame > wc_heap_size_intra_frame[1]) if (current_heap_size_intra_frame > wc_heap_size_intra_frame[1]) { for (i = 0; i < Num_Records; i++) { if (allocation_list[i].block_ptr != NULL) if ( allocation_list[i].frame_allocated == update_cnt ) { allocation_list[i].wc_heap_size_intra_frame[0] = update_cnt; allocation_list[i].wc_heap_size_intra_frame[1] = allocation_list[i].block_size; Loading @@ -1179,11 +1183,11 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) } /* Update Worst-Case Inter-Frame Heap Size, if Exceeded */ if (ptr_record->frame_allocated < update_cnt && current_heap_size_inter_frame > wc_heap_size_inter_frame[1]) if (current_heap_size_inter_frame > wc_heap_size_inter_frame[1]) { for (i = 0; i < Num_Records; i++) { if (allocation_list[i].block_ptr != NULL) if ( allocation_list[i].frame_allocated < update_cnt ) { allocation_list[i].wc_heap_size_inter_frame[0] = update_cnt; allocation_list[i].wc_heap_size_inter_frame[1] = allocation_list[i].block_size; Loading @@ -1197,7 +1201,6 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) wc_heap_size_inter_frame[0] = update_cnt; wc_heap_size_inter_frame[1] = current_heap_size_inter_frame; } /* Update the Average Usage of Memory Block (Look for Signature) */ Loading Loading @@ -1249,12 +1252,12 @@ static void mem_count_summary(void) { int i, j, flag_intra_frame_memory; size_t length; char format_str[50], name_str[MAX_FUNCTION_NAME_LENGTH + 1], parms_str[MAX_PARAMS_LENGTH + 1], type_str[10], usage_str[20], size_str[20], line_str[10]; char format_str[50], name_str[MAX_FUNCTION_NAME_LENGTH + 3], parms_str[MAX_PARAMS_LENGTH + 1], type_str[10], usage_str[20], size_str[20], line_str[10]; char buf[300]; allocator_record* record_ptr; allocator_record* record_ptr, *ptr; /* Prepare format string */ sprintf(format_str, "%%-%ds %%5s %%6s %%-%ds %%14s %%6s ", MAX_FUNCTION_NAME_LENGTH, MAX_PARAMS_LENGTH); sprintf(format_str, "%%-%ds %%5s %%6s %%-%ds %%20s %%6s ", MAX_FUNCTION_NAME_LENGTH, MAX_PARAMS_LENGTH); /* Check, if we have at least one Intra-Frame Heap memory block in the list */ flag_intra_frame_memory = 0; Loading @@ -1268,6 +1271,37 @@ static void mem_count_summary(void) } } /* Find duplicate records (same hash and worst-case heap size) */ for ( i = 0; i < Num_Records; i++ ) { record_ptr = &( allocation_list[i] ); for ( j = i + 1; j < Num_Records; j++ ) { ptr = &( allocation_list[j] ); if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size[1] == record_ptr->wc_heap_size[1] ) { ptr->wc_heap_size[0] = -1; ptr->wc_heap_size[1] = 0; record_ptr->wc_heap_size[2]++; } if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size_intra_frame[1] == record_ptr->wc_heap_size_intra_frame[1] ) { ptr->wc_heap_size_intra_frame[0] = -1; ptr->wc_heap_size_intra_frame[1] = 0; record_ptr->wc_heap_size_intra_frame[2]++; } if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size_inter_frame[1] == record_ptr->wc_heap_size_inter_frame[1] ) { ptr->wc_heap_size_inter_frame[0] = -1; ptr->wc_heap_size_inter_frame[1] = 0; record_ptr->wc_heap_size_inter_frame[2]++; } } } for (j = 0; j < 2; j++) { if ( !flag_intra_frame_memory ) Loading Loading @@ -1315,6 +1349,7 @@ static void mem_count_summary(void) ) { strncpy(name_str, record_ptr->name, MAX_FUNCTION_NAME_LENGTH); strcat( name_str, "()" ); name_str[MAX_FUNCTION_NAME_LENGTH] = '\0'; strncpy(parms_str, &(record_ptr->params[2]), MAX_PARAMS_LENGTH); parms_str[MAX_PARAMS_LENGTH] = '\0'; Loading @@ -1330,7 +1365,40 @@ static void mem_count_summary(void) sprintf(usage_str, "%d%%", (int)(record_ptr->ave_usage * 100.0f)); sprintf(line_str, "%d", record_ptr->lineno); sprintf(size_str, "%d %s", (int)(record_ptr->max_block_size >> Stat_Cnt_Size), Count_Unit[Stat_Cnt_Size]); if ( !flag_intra_frame_memory && j == 0 && record_ptr->wc_heap_size[1] > 0 ) { if ( record_ptr->wc_heap_size[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size[2], ( int )( record_ptr->wc_heap_size[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } else if ( flag_intra_frame_memory && j == 0 && record_ptr->wc_heap_size_intra_frame[1] > 0 ) { if ( record_ptr->wc_heap_size_intra_frame[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size_intra_frame[2], ( int )( record_ptr->wc_heap_size_intra_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size_intra_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } else if ( flag_intra_frame_memory && j == 1 && record_ptr->wc_heap_size_inter_frame[1] > 0 ) { if ( record_ptr->wc_heap_size_inter_frame[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size_inter_frame[2], ( int )( record_ptr->wc_heap_size_inter_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size_inter_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } sprintf(buf, format_str, name_str, line_str, type_str, parms_str, size_str, usage_str); puts(buf); Loading Loading @@ -1376,7 +1444,7 @@ void export_mem( const char *csv_filename ) for ( i = 0; i < Num_Records; i++ ) { record_ptr = &( allocation_list[i] ); fprintf( fid, "%s:%d,%ld;", record_ptr->name, record_ptr->lineno, record_ptr->block_size ); fprintf( fid, "%s:%d,%d;", record_ptr->name, record_ptr->lineno, record_ptr->block_size ); } fprintf( fid, "\n" ); Loading Loading @@ -1487,7 +1555,12 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[]) if (Stat_Cnt_Size > 0) { fprintf(stdout, "\nNote: 1 word = %d bits\n", 8 << Stat_Cnt_Size); fprintf(stdout, "This is an optimistic estimate of memory consumption assuming that each variable type is stored with sizeof(type) bits\n\n"); fprintf( stdout, "This is an optimistic estimate of memory consumption assuming that each variable type is stored with sizeof(type) bits\n" ); } if ( wc_heap_size[1] > 0 ) { fprintf( stdout, "Intra-frame heap memory is allocated and de-allocated in the same frame\n" ); } /* De-allocate list of heap memory blocks */ Loading Loading
lib_debug/wmc_auto.c +87 −14 Original line number Diff line number Diff line Loading @@ -491,9 +491,9 @@ typedef struct void* block_ptr; int block_size; int max_block_size; /* Maximum block size allocated */ int32_t wc_heap_size[2]; /* Worst-Case Heap [Frame#, Size] */ int32_t wc_heap_size_intra_frame[2]; /* Worst-Case Intra-Frame Heap [Frame#, Size] */ int32_t wc_heap_size_inter_frame[2]; /* Worst-Case Inter-Frame Heap [Frame#, Size] */ int32_t wc_heap_size[3]; /* Worst-Case Heap [Frame#, Size, Count] */ int32_t wc_heap_size_intra_frame[3]; /* Worst-Case Intra-Frame Heap [Frame#, Size, Count] */ int32_t wc_heap_size_inter_frame[3]; /* Worst-Case Inter-Frame Heap [Frame#, Size, Count] */ int frame_allocated; /* Frame number in which the Memory Block has been allocated */ float ave_usage; /* Average Usage of memory block calculated as ratio of used size and allocated size */ int OOB_Flag; Loading Loading @@ -784,10 +784,13 @@ void* mem_alloc( ptr_record->OOB_Flag = 0; ptr_record->wc_heap_size[0] = -1; ptr_record->wc_heap_size[1] = 0; ptr_record->wc_heap_size[2] = 1; ptr_record->wc_heap_size_intra_frame[0] = -1; ptr_record->wc_heap_size_intra_frame[1] = 0; ptr_record->wc_heap_size_intra_frame[2] = 1; ptr_record->wc_heap_size_inter_frame[0] = -1; ptr_record->wc_heap_size_inter_frame[1] = 0; ptr_record->wc_heap_size_inter_frame[2] = 1; Num_Records++; } Loading Loading @@ -1102,6 +1105,7 @@ allocator_record* get_mem_record(unsigned long* hash, const char* func_name, int return NULL; } /*-------------------------------------------------------------------* * mem_free() * Loading Loading @@ -1158,11 +1162,11 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) } /* Update Worst-Case Intra-Frame Heap Size, if Exceeded */ if (ptr_record->frame_allocated == update_cnt && current_heap_size_intra_frame > wc_heap_size_intra_frame[1]) if (current_heap_size_intra_frame > wc_heap_size_intra_frame[1]) { for (i = 0; i < Num_Records; i++) { if (allocation_list[i].block_ptr != NULL) if ( allocation_list[i].frame_allocated == update_cnt ) { allocation_list[i].wc_heap_size_intra_frame[0] = update_cnt; allocation_list[i].wc_heap_size_intra_frame[1] = allocation_list[i].block_size; Loading @@ -1179,11 +1183,11 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) } /* Update Worst-Case Inter-Frame Heap Size, if Exceeded */ if (ptr_record->frame_allocated < update_cnt && current_heap_size_inter_frame > wc_heap_size_inter_frame[1]) if (current_heap_size_inter_frame > wc_heap_size_inter_frame[1]) { for (i = 0; i < Num_Records; i++) { if (allocation_list[i].block_ptr != NULL) if ( allocation_list[i].frame_allocated < update_cnt ) { allocation_list[i].wc_heap_size_inter_frame[0] = update_cnt; allocation_list[i].wc_heap_size_inter_frame[1] = allocation_list[i].block_size; Loading @@ -1197,7 +1201,6 @@ void mem_free(const char* func_name, int func_lineno, void* ptr) wc_heap_size_inter_frame[0] = update_cnt; wc_heap_size_inter_frame[1] = current_heap_size_inter_frame; } /* Update the Average Usage of Memory Block (Look for Signature) */ Loading Loading @@ -1249,12 +1252,12 @@ static void mem_count_summary(void) { int i, j, flag_intra_frame_memory; size_t length; char format_str[50], name_str[MAX_FUNCTION_NAME_LENGTH + 1], parms_str[MAX_PARAMS_LENGTH + 1], type_str[10], usage_str[20], size_str[20], line_str[10]; char format_str[50], name_str[MAX_FUNCTION_NAME_LENGTH + 3], parms_str[MAX_PARAMS_LENGTH + 1], type_str[10], usage_str[20], size_str[20], line_str[10]; char buf[300]; allocator_record* record_ptr; allocator_record* record_ptr, *ptr; /* Prepare format string */ sprintf(format_str, "%%-%ds %%5s %%6s %%-%ds %%14s %%6s ", MAX_FUNCTION_NAME_LENGTH, MAX_PARAMS_LENGTH); sprintf(format_str, "%%-%ds %%5s %%6s %%-%ds %%20s %%6s ", MAX_FUNCTION_NAME_LENGTH, MAX_PARAMS_LENGTH); /* Check, if we have at least one Intra-Frame Heap memory block in the list */ flag_intra_frame_memory = 0; Loading @@ -1268,6 +1271,37 @@ static void mem_count_summary(void) } } /* Find duplicate records (same hash and worst-case heap size) */ for ( i = 0; i < Num_Records; i++ ) { record_ptr = &( allocation_list[i] ); for ( j = i + 1; j < Num_Records; j++ ) { ptr = &( allocation_list[j] ); if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size[1] == record_ptr->wc_heap_size[1] ) { ptr->wc_heap_size[0] = -1; ptr->wc_heap_size[1] = 0; record_ptr->wc_heap_size[2]++; } if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size_intra_frame[1] == record_ptr->wc_heap_size_intra_frame[1] ) { ptr->wc_heap_size_intra_frame[0] = -1; ptr->wc_heap_size_intra_frame[1] = 0; record_ptr->wc_heap_size_intra_frame[2]++; } if ( ptr->hash != 0 && ptr->hash == record_ptr->hash && ptr->wc_heap_size_inter_frame[1] == record_ptr->wc_heap_size_inter_frame[1] ) { ptr->wc_heap_size_inter_frame[0] = -1; ptr->wc_heap_size_inter_frame[1] = 0; record_ptr->wc_heap_size_inter_frame[2]++; } } } for (j = 0; j < 2; j++) { if ( !flag_intra_frame_memory ) Loading Loading @@ -1315,6 +1349,7 @@ static void mem_count_summary(void) ) { strncpy(name_str, record_ptr->name, MAX_FUNCTION_NAME_LENGTH); strcat( name_str, "()" ); name_str[MAX_FUNCTION_NAME_LENGTH] = '\0'; strncpy(parms_str, &(record_ptr->params[2]), MAX_PARAMS_LENGTH); parms_str[MAX_PARAMS_LENGTH] = '\0'; Loading @@ -1330,7 +1365,40 @@ static void mem_count_summary(void) sprintf(usage_str, "%d%%", (int)(record_ptr->ave_usage * 100.0f)); sprintf(line_str, "%d", record_ptr->lineno); sprintf(size_str, "%d %s", (int)(record_ptr->max_block_size >> Stat_Cnt_Size), Count_Unit[Stat_Cnt_Size]); if ( !flag_intra_frame_memory && j == 0 && record_ptr->wc_heap_size[1] > 0 ) { if ( record_ptr->wc_heap_size[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size[2], ( int )( record_ptr->wc_heap_size[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } else if ( flag_intra_frame_memory && j == 0 && record_ptr->wc_heap_size_intra_frame[1] > 0 ) { if ( record_ptr->wc_heap_size_intra_frame[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size_intra_frame[2], ( int )( record_ptr->wc_heap_size_intra_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size_intra_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } else if ( flag_intra_frame_memory && j == 1 && record_ptr->wc_heap_size_inter_frame[1] > 0 ) { if ( record_ptr->wc_heap_size_inter_frame[2] > 1 ) { sprintf( size_str, "%dx%d %s", record_ptr->wc_heap_size_inter_frame[2], ( int )( record_ptr->wc_heap_size_inter_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } else { sprintf( size_str, "%d %s", (int) ( record_ptr->wc_heap_size_inter_frame[1] >> Stat_Cnt_Size ), Count_Unit[Stat_Cnt_Size] ); } } sprintf(buf, format_str, name_str, line_str, type_str, parms_str, size_str, usage_str); puts(buf); Loading Loading @@ -1376,7 +1444,7 @@ void export_mem( const char *csv_filename ) for ( i = 0; i < Num_Records; i++ ) { record_ptr = &( allocation_list[i] ); fprintf( fid, "%s:%d,%ld;", record_ptr->name, record_ptr->lineno, record_ptr->block_size ); fprintf( fid, "%s:%d,%d;", record_ptr->name, record_ptr->lineno, record_ptr->block_size ); } fprintf( fid, "\n" ); Loading Loading @@ -1487,7 +1555,12 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[]) if (Stat_Cnt_Size > 0) { fprintf(stdout, "\nNote: 1 word = %d bits\n", 8 << Stat_Cnt_Size); fprintf(stdout, "This is an optimistic estimate of memory consumption assuming that each variable type is stored with sizeof(type) bits\n\n"); fprintf( stdout, "This is an optimistic estimate of memory consumption assuming that each variable type is stored with sizeof(type) bits\n" ); } if ( wc_heap_size[1] > 0 ) { fprintf( stdout, "Intra-frame heap memory is allocated and de-allocated in the same frame\n" ); } /* De-allocate list of heap memory blocks */ Loading