Commit 628ea712 authored by malenov's avatar malenov
Browse files

compact memory printout

parent f10127ea
Loading
Loading
Loading
Loading
+49 −30
Original line number Diff line number Diff line
@@ -540,7 +540,7 @@ void reset_mem(Counting_Size cnt_size)
    tmp_size = sizeof(int32_t);
    if (tmp_size != 4)
    {
        printf("Error: Expecting 'int32_t' to be a 32 Bits Integer!");
        fprintf( stderr, "Error: Expecting 'int32_t' to be a 32 Bits Integer!" );
        exit(-1);
    }

@@ -552,7 +552,7 @@ void reset_mem(Counting_Size cnt_size)

    if (allocation_list == NULL)
    {
        printf("Error: Unable to Create List of Memory Blocks!");
        fprintf( stderr, "Error: Unable to Create List of Memory Blocks!" );
        exit(-1);
    }

@@ -759,7 +759,7 @@ void* mem_alloc(

    if (size == 0)
    {
        printf("Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Size of Zero not Supported");
        fprintf( stderr, "Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Size of Zero not Supported" );
        exit(-1);
    }

@@ -797,7 +797,7 @@ void* mem_alloc(

    if (ptr_record->block_ptr == NULL)
    {
        printf("Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Cannot Allocate Memory!");
        fprintf( stderr, "Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Cannot Allocate Memory!" );
        exit(-1);
    }

@@ -816,7 +816,7 @@ void* mem_alloc(

    if (ptr_record->frame_allocated != -1)
    {
        printf("Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Attempt to Allocate the Same Memory Block with Freeing it First!");
        fprintf( stderr, "Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Attempt to Allocate the Same Memory Block with Freeing it First!" );
        exit(-1);
    }

@@ -1132,7 +1132,7 @@ void mem_free(const char* func_name, int func_lineno, void* ptr)

    if (ptr_record == NULL)
    {
        printf("Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Unable to Find Record Corresponding to the Allocated Memory Block!");
        fprintf( stderr, "Fct=%s, Ln=%i: %s!\n", func_name, func_lineno, "Error: Unable to Find Record Corresponding to the Allocated Memory Block!" );
        exit(-1);
    }

@@ -1275,7 +1275,7 @@ static void mem_count_summary(void)
            if ( j == 0 )
            {
                /* Total Heap Size */
                printf( "\nList of memory blocks when maximum inter-frame heap size is reached:\n\n" );
                fprintf( stdout, "\nList of memory blocks when maximum inter-frame heap size is reached:\n\n" );
            }
            else
            {
@@ -1287,12 +1287,12 @@ static void mem_count_summary(void)
            if ( j == 0 )
            {
                /* Intra-Frame Heap Size */
                printf( "\nList of memory blocks when maximum intra-frame heap size is reached:\n\n" );
                fprintf( stdout, "\nList of memory blocks when maximum intra-frame heap size is reached:\n\n" );
            }
            else
            {
                /* Inter-Frame Heap Size */
                printf( "\nList of memory blocks when maximum inter-frame heap size is reached:\n\n" );
                fprintf( stdout, "\nList of memory blocks when maximum inter-frame heap size is reached:\n\n" );
            }
        }

@@ -1337,7 +1337,7 @@ static void mem_count_summary(void)
            }
        }

        printf("\n\n");
        fprintf( stdout, "\n" );
    }

    return;
@@ -1394,10 +1394,10 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[])
{
    int i, nElem;

    fprintf( stdout, "\n\n --- Memory usage ---  \n\n" );

    if (Const_Data_PROM_Table != NULL)
    {
        fprintf(stdout, "\n\n --- Program ROM usage ---  \n\n");

        nElem = 0;
        while (strcmp(Const_Data_PROM_Table[nElem].file_spec, "") != 0) nElem++;

@@ -1406,8 +1406,6 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[])
            fprintf(stdout, "Program ROM size (%s): %d instruction words\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].PROM_size);
        }

        fprintf(stdout, "\n\n --- Table ROM (const data) usage ---  \n\n");

        for (i = 0; i < nElem; i++)
        {
            if (Const_Data_PROM_Table[i].Get_Const_Data_Size_Func == NULL)
@@ -1415,24 +1413,32 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[])
                fprintf(stdout, "Error: Cannot retrieve or calculate Table ROM size of (%s)!\n", Const_Data_PROM_Table[i].file_spec);
            }

            fprintf(stdout, "Table ROM size (%s): %d %s\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].Get_Const_Data_Size_Func() >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size]);
            fprintf(stdout, "Table ROM (const data) size (%s): %d %s\n", Const_Data_PROM_Table[i].file_spec, Const_Data_PROM_Table[i].Get_Const_Data_Size_Func() >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size]);
        }
    }
    else
    {
        fprintf( stdout, "Program ROM size: not available\n");
        fprintf( stdout, "Table ROM (const data) size: not available\n");
    }

    if (wc_ram_size > 0)
    {
        fprintf(stdout, "\n\n --- RAM usage (Stack + Heap) ---  \n\n");
        fprintf(stdout, "Maximum RAM size: %d %s in frame %d\n", wc_ram_size >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_ram_frame);
        fprintf(stdout, "Maximum RAM (stack + heap) size: %d %s in frame %d\n", wc_ram_size >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_ram_frame);
    }
    else
    {
        fprintf( stdout, "Maximum RAM (stack + heap) size: not available\n" );
    }

    if (ptr_base_stack - ptr_max_stack > 0)
    {
        fprintf(stdout, "\n\n --- Stack usage ---  \n\n");
        fprintf(stdout, "Maximum stack size: %lu %s in frame %d\n", ((ptr_base_stack - ptr_max_stack) * sizeof(int16_t)) >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size],
            wc_frame);
#ifdef MEM_COUNT_DETAILS
        print_stack_call_tree();
#endif
    }
    else
    {
        fprintf( stdout, "Maximum stack size: not available\n" );
    }

    /* check, if all memory blocks have been deallocated (freed) */
@@ -1440,30 +1446,43 @@ void print_mem(ROM_Size_Lookup_Table Const_Data_PROM_Table[])
    {
        if (allocation_list[i].block_ptr != NULL)
        {
            printf("Fct=%s, Ln=%i: %s!\n", allocation_list[i].name, allocation_list[i].lineno, "Error: Memory Block has not been De-Allocated with free()!");
            fprintf( stderr, "Fct=%s, Ln=%i: %s!\n", allocation_list[i].name, allocation_list[i].lineno, "Error: Memory Block has not been De-Allocated with free()!" );
            exit(-1);
        }
    }

    if ( wc_heap_size[1] > 0 )
    {
        fprintf( stdout, "\n\n --- Heap usage (malloc/calloc) ---  \n\n" );

        if ( wc_heap_size_intra_frame[1] > 0 )
        {
            printf( "Maximum intra-frame heap size: %d %s in frame %d\n", wc_heap_size_intra_frame[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size_intra_frame[0] );
            printf( "Maximum inter-frame heap size: %d %s in frame %d\n", wc_heap_size_inter_frame[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size_inter_frame[0] );
            fprintf( stdout, "Maximum intra-frame heap size: %d %s in frame %d\n", wc_heap_size_intra_frame[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size_intra_frame[0] );
            fprintf( stdout, "Maximum inter-frame heap size: %d %s in frame %d\n", wc_heap_size_inter_frame[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size_inter_frame[0] );
        }
        else
        {
            fprintf( stdout, "Maximum intra-frame heap size: 0\n" );
            fprintf( stdout, "Maximum inter-frame heap size: %d %s in frame %d\n", wc_heap_size[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size[0] );
        }
    }
    else
    {
            printf( "Maximum inter-frame heap size: %d %s in frame %d\n", wc_heap_size[1] >> Stat_Cnt_Size, Count_Unit[Stat_Cnt_Size], wc_heap_size[0] );
        fprintf( stdout, "Maximum intra-frame heap size: not available\n" );
        fprintf( stdout, "Maximum inter-frame heap size: not available\n" );
    }

#ifdef MEM_COUNT_DETAILS
        /* Print detailed information abour heap memory usage */
    /* Print detailed information about worst-case stack usage */
    if ( ptr_base_stack - ptr_max_stack > 0 )
    {
        print_stack_call_tree();
    }

    /* Print detailed information about worst-case heap usage */
    if ( wc_heap_size[1] > 0 )
    {
        mem_count_summary();
#endif
    }
#endif

    if (Stat_Cnt_Size > 0)
    {