Commit 77da6f38 authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

Replaced old files with wmc_auto.h and wmc_auto.c

parent 240c139c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -146,12 +146,14 @@
    <ClCompile Include="..\lib_debug\segsnr.c" />
    <ClCompile Include="..\lib_debug\snr.c" />
    <ClCompile Include="..\lib_debug\sba_debug.c" />
    <ClCompile Include="..\lib_debug\wmc_auto.c" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="..\lib_debug\debug.h" />
    <ClInclude Include="..\lib_debug\deb_out.h" />
    <ClInclude Include="..\lib_debug\errorhnd.h" />
    <ClInclude Include="..\lib_debug\sba_debug.h" />
    <ClInclude Include="..\lib_debug\wmc_auto.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">

lib_debug/mem_count.c

deleted100644 → 0
+0 −909

File deleted.

Preview size limit exceeded, changes collapsed.

lib_debug/mem_count.h

deleted100644 → 0
+0 −104
Original line number Diff line number Diff line
/*
 * mem_count.h
 *
 * Copyright 2022 VoiceAge Corporation. All Rights Reserved.
 *
 * This software is protected by copyright law and by international treaties.
 * VoiceAge Corporation retains full ownership rights in their respective contributions in the software.
 * No license of any kind, including but not limited to patent license, of any foregoing parties is
 * hereby granted by implication, estoppel or otherwise.
 *
 * This software is provided "AS IS", without any express or implied warranties. The software is in the
 * development stage. It is intended exclusively for experts who have experience with such software and
 * solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
 * and/or fitness for a particular purpose are hereby disclaimed and excluded.
 *
 *      Written by :  Guy J. Richard - August 2017
 *
 */

#ifndef __MEM_COUNT_H__
#define __MEM_COUNT_H__

#include <stdint.h>
#include "options.h"
#include <stdlib.h> /* for size_t, ... */

#ifdef RAM_COUNTING_TOOL
/*-------------------------------------------------------------------*
 * Global Constants
 *-------------------------------------------------------------------*/

#define NO_RAM_LIMIT 0

/* Define this when using 64 Bits values in the code (ex: double) */
/*#define MEM_ALIGN_64BITS */ /* Will Align on 32 Bits if not Defined */

/*#define DISABLE_NULL_PTR_FREE_WARNING*/

/*#define MEM_COUNT_DETAILS*/

/*#define MEM_COUNT_SEPARATE_OTHER_BLOCKS */ /* Print separate lines with location details if the same block is allocated in multiple places and is not a part of the Peak memory */
                                             /* if not defined, MULTIPLE LOCATIONS is printed instead */

/*-------------------------------------------------------------------*
 * Global Types
 *-------------------------------------------------------------------*/

typedef enum
{
    USE_DEFAULT = -1,
    USE_BYTES,
    USE_16BITS,
    USE_32BITS
} Counting_Size;

/*-------------------------------------------------------------------*
 * Global Macros
 *-------------------------------------------------------------------*/

#define STRINGIFY( x ) #x
#define TO_STRING( x ) STRINGIFY( x )

#if ( defined( _WIN32 ) && ( _MSC_VER <= 1800 ) && ( _MSC_VER >= 1300 ) )
#define __func__ __FUNCTION__
#elif defined( __STDC_VERSION__ ) && __STDC_VERSION__ < 199901L
#if ( __GNUC__ >= 2 )
#define __func__ __FUNCTION__
#else
#define __func__ "<unknown>"
#endif
#elif defined( __GNUC__ )
#define __func__ __extension__ __FUNCTION__
#endif

/* MALLOC_FCT_CALL, FREE_FCT_CALL, ... are defined here because 'wmc_auto.h' uses */
/* them to map malloc, free & calloc to a Memory Counting Mechanism. If the WMC Tool */
/* is not used, then these definitions will have no effect and are harmless. */
#define MALLOC_FCT_CALL( size )  mem_alloc( __func__, __LINE__, size, "m:" TO_STRING( size ) )
#define FREE_FCT_CALL( ptr )     mem_free( __func__, __LINE__, ptr )
#define CALLOC_FCT_CALL( n, sz ) mem_alloc( __func__, __LINE__, ( n ) * ( sz ), "c:" TO_STRING( n ) ", " TO_STRING( sz ) )


/*-------------------------------------------------------------------*
 * Prototypes
 *-------------------------------------------------------------------*/

#ifdef __cplusplus
extern "C"
{
#endif

    extern void mem_count_init( size_t limit, Counting_Size cnt_size );
    extern size_t mem_count_summary( Counting_Size cnt_size );

    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 __cplusplus
}
#endif

#endif

#endif

lib_debug/memory.c

deleted100644 → 0
+0 −187
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/

#include "options.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include "prot.h"
#include "debug.h"
#include "wmops.h"
#include "rom_enc.h"
#include "rom_dec.h"
#include "rom_com.h"
#include "stat_enc.h"
#include "stat_dec.h"

#ifdef WMOPS

/*-------------------------------------------------------------------*
 * Memory counting tool
 *--------------------------------------------------------------------*/

int16_t *ptr_base_stack = 0; /* Pointer to the bottom of stack (base pointer). Stack grows up. */
int16_t *ptr_max_stack = 0;  /* Pointer to the maximum stack pointer (the farest point from the bottom of stack) */
int32_t wc_frame = 0;        /* Frame corresponding to the worst-case stack usage */
char location_max_stack[256] = "undefined";
#define MAX_FCT_NAME_LENGTH 30
typedef struct
{
    char function_name[MAX_FCT_NAME_LENGTH + 1];
    int16_t *stack_ptr;
} caller_info;
int current_calls = 0;
#define MAX_RECORDABLE_CALLS 40
caller_info stack_callers[2][MAX_RECORDABLE_CALLS];


/*-------------------------------------------------------------------*
 * reset_stack()
 *
 * Initialize/reset the base stack counter..
 *--------------------------------------------------------------------*/

void reset_stack()
{
    int16_t something;

    ptr_base_stack = &something;
    ptr_max_stack = ptr_base_stack;
}

/*-------------------------------------------------------------------*
 * push_stack()
 *
 * Check the current stack pointer and update the maximum stack pointer, if new maximum found.
 *--------------------------------------------------------------------*/

int push_stack( const char *filename, const char *fctname )
{
    int16_t something;

    (void) *filename; /* to avoid compilation warning */

    /* Is there room to save the caller's information? */
    if ( current_calls >= MAX_RECORDABLE_CALLS )
    { /* No */
        fprintf( stderr, "memory.c: No more room to store call stack info. Please increase MAX_RECORDABLE_CALLS" );
        exit( -1 );
    }
    /* Valid Function Name? */
    if ( fctname[0] == 0 )
    { /* No */
        fprintf( stderr, "memory.c: Invalid function name for call stack info." );
        exit( -1 );
    }
    /* Save the Name of the Calling Function in the Table */
    strncpy( stack_callers[0][current_calls].function_name, fctname, MAX_FCT_NAME_LENGTH );
    stack_callers[0][current_calls].function_name[MAX_FCT_NAME_LENGTH] = 0; /* Nul Terminate */
    /* Save the Stack Pointer */
    stack_callers[0][current_calls].stack_ptr = &something;
    /* Increase Stack Calling Tree Level */
    current_calls++;
    /* Is this the First Time or the Worst Case? */
    if ( &something < ptr_max_stack || ptr_max_stack == NULL )
    { /* Yes */
        /* Save Info about it */
        ptr_max_stack = &something;
        wc_frame = frame;
        strncpy( location_max_stack, fctname, sizeof( location_max_stack ) - 1 );
        location_max_stack[sizeof( location_max_stack ) - 1] = '\0';

        /* Save Call Tree */
        memmove( stack_callers[1], stack_callers[0], sizeof( caller_info ) * current_calls );

        /* Terminate the List (Unless Full) */
        if ( current_calls < MAX_RECORDABLE_CALLS )
        {
            stack_callers[1][current_calls].function_name[0] = 0;
        }
    }
    return 0 /* for Now */;
}

int pop_stack( const char *filename, const char *fctname )
{
    caller_info *caller_info_ptr;

    (void) *filename; /* to avoid compilation warning */

    /* Decrease Stack Calling */
    current_calls--;

    /* Get Pointer to Caller Information */
    caller_info_ptr = &stack_callers[0][current_calls];

    /* Check if Names Match */
    if ( strncmp( caller_info_ptr->function_name, fctname, MAX_FCT_NAME_LENGTH ) != 0 )
    {
        fprintf( stderr, "memory.c: Invalid pop_stack()" );
        exit( -1 );
    }

    /* Erase Entry */
    caller_info_ptr->function_name[0] = 0;

    return 0 /* for Now */;
}

void print_stack_call_tree( void )
{
    caller_info *caller_info_ptr;
    int call_level;

    fprintf( stdout, "Stack Call Tree (frame #%5d)            Stack Usage in words\n", wc_frame );
    caller_info_ptr = &stack_callers[1][0];
    for ( call_level = 0; call_level < MAX_RECORDABLE_CALLS; call_level++ )
    {
        /* Done? */
        if ( caller_info_ptr->function_name[0] == 0 )
            break;
        /* Print Name */
        fprintf( stdout, "%-42s", caller_info_ptr->function_name );
        /* Print Stack Usage (Based on Difference) */
        if ( call_level != 0 )
        {
            fprintf( stdout, "%ld\n", ( ( caller_info_ptr - 1 )->stack_ptr - caller_info_ptr->stack_ptr ) * sizeof( int16_t ) / sizeof( float ) );
        }
        else
            fprintf( stdout, "\n" );
        /* Advance */
        caller_info_ptr++;
    }
    fprintf( stdout, "\n" );
}

#endif /* WMOPS */

lib_debug/wmc_auto.c

0 → 100644
+1450 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading