Commit 4659e364 authored by James Zern's avatar James Zern Committed by Gerrit Code Review

vpx_mem: remove mem tracker

vestigial. there are tools better suited for this

Change-Id: I7a72a2cfe32377f07c8cd0973ddb18842720a225
parent 4a29474c
......@@ -40,7 +40,6 @@ Advanced options:
${toggle_vp8} VP8 codec support
${toggle_vp9} VP9 codec support
${toggle_internal_stats} output of encoder internal stats for debug, if supported (encoders)
${toggle_mem_tracker} track memory usage
${toggle_postproc} postprocessing
${toggle_vp9_postproc} vp9 specific postprocessing
${toggle_multithread} multithreaded encoding and decoding
......@@ -296,7 +295,6 @@ CONFIG_LIST="
codec_srcs
debug_libs
fast_unaligned
mem_tracker
dequant_tokens
dc_recon
......@@ -371,7 +369,6 @@ CMDLINE_SELECT="
${CODECS}
${CODEC_FAMILIES}
static_msvcrt
mem_tracker
spatial_resampling
realtime_only
onthefly_bitpacking
......
......@@ -13,21 +13,10 @@
#define VPX_MEM_INCLUDE_VPX_MEM_INTRNL_H_
#include "./vpx_config.h"
#ifndef CONFIG_MEM_TRACKER
# define CONFIG_MEM_TRACKER 1 /*include xvpx_* calls in the lib*/
#endif
#ifndef USE_GLOBAL_FUNCTION_POINTERS
# define USE_GLOBAL_FUNCTION_POINTERS 0 /*use function pointers instead of compiled functions.*/
#endif
#if CONFIG_MEM_TRACKER
# include "vpx_mem_tracker.h"
# if VPX_MEM_TRACKER_VERSION_CHIEF != 2 || VPX_MEM_TRACKER_VERSION_MAJOR != 5
# error "vpx_mem requires memory tracker version 2.5 to track memory usage"
# endif
#endif
#define ADDRESS_STORAGE_SIZE sizeof(size_t)
#ifndef DEFAULT_ALIGNMENT
......@@ -40,41 +29,6 @@ than vpx_memalign*/
# endif
#endif
#if CONFIG_MEM_TRACKER
# define TRY_BOUNDS_CHECK 1 /*when set to 1 pads each allocation,
integrity can be checked using
vpx_memory_tracker_check_integrity
or on free by defining*/
/*TRY_BOUNDS_CHECK_ON_FREE*/
#else
# define TRY_BOUNDS_CHECK 0
#endif /*CONFIG_MEM_TRACKER*/
#if TRY_BOUNDS_CHECK
# define TRY_BOUNDS_CHECK_ON_FREE 0 /*checks mem integrity on every
free, very expensive*/
# define BOUNDS_CHECK_VALUE 0xdeadbeef /*value stored before/after ea.
mem addr for bounds checking*/
# define BOUNDS_CHECK_PAD_SIZE 32 /*size of the padding before and
after ea allocation to be filled
with BOUNDS_CHECK_VALUE.
this should be a multiple of 4*/
#else
# define BOUNDS_CHECK_VALUE 0
# define BOUNDS_CHECK_PAD_SIZE 0
#endif /*TRY_BOUNDS_CHECK*/
#ifndef REMOVE_PRINTFS
# define REMOVE_PRINTFS 0
#endif
/* Should probably use a vpx_mem logger function. */
#if REMOVE_PRINTFS
# define _P(x)
#else
# define _P(x) x
#endif
/*returns an addr aligned to the byte boundary specified by align*/
#define align_addr(addr,align) (void*)(((size_t)(addr) + ((align) - 1)) & (size_t)-(align))
......
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VPX_MEM_INCLUDE_VPX_MEM_TRACKER_H_
#define VPX_MEM_INCLUDE_VPX_MEM_TRACKER_H_
/* vpx_mem_tracker version info */
#define vpx_mem_tracker_version "2.5.1.1"
#define VPX_MEM_TRACKER_VERSION_CHIEF 2
#define VPX_MEM_TRACKER_VERSION_MAJOR 5
#define VPX_MEM_TRACKER_VERSION_MINOR 1
#define VPX_MEM_TRACKER_VERSION_PATCH 1
/* END - vpx_mem_tracker version info */
#include <stdarg.h>
struct mem_block {
size_t addr;
unsigned int size,
line;
char *file;
struct mem_block *prev,
* next;
int padded; // This mem_block has padding for integrity checks.
// As of right now, this should only be 0 if
// using vpx_mem_alloc to allocate cache memory.
// 2005-01-11 tjf
};
#if defined(__cplusplus)
extern "C" {
#endif
/*
vpx_memory_tracker_init(int padding_size, int pad_value)
padding_size - the size of the padding before and after each mem addr.
Values > 0 indicate that integrity checks can be performed
by inspecting these areas.
pad_value - the initial value within the padding area before and after
each mem addr.
Initializes the memory tracker interface. Should be called before any
other calls to the memory tracker.
*/
int vpx_memory_tracker_init(int padding_size, int pad_value);
/*
vpx_memory_tracker_destroy()
Deinitializes the memory tracker interface
*/
void vpx_memory_tracker_destroy();
/*
vpx_memory_tracker_add(size_t addr, unsigned int size,
char * file, unsigned int line)
addr - memory address to be added to list
size - size of addr
file - the file addr was referenced from
line - the line in file addr was referenced from
Adds memory address addr, it's size, file and line it came from
to the memory tracker allocation table
*/
void vpx_memory_tracker_add(size_t addr, unsigned int size,
char *file, unsigned int line,
int padded);
/*
vpx_memory_tracker_add(size_t addr, unsigned int size, char * file, unsigned int line)
addr - memory address to be added to be removed
padded - if 0, disables bounds checking on this memory block even if bounds
checking is enabled. (for example, when allocating cache memory, we still want
to check for memory leaks, but we do not waste cache space for bounds check padding)
Removes the specified address from the memory tracker's allocation
table
Return:
0: on success
-1: if memory allocation table's mutex could not be locked
-2: if the addr was not found in the list
*/
int vpx_memory_tracker_remove(size_t addr);
/*
vpx_memory_tracker_find(unsigned int addr)
addr - address to be found in the memory tracker's
allocation table
Return:
If found, pointer to the memory block that matches addr
NULL otherwise
*/
struct mem_block *vpx_memory_tracker_find(size_t addr);
/*
vpx_memory_tracker_dump()
Dumps the current contents of the memory
tracker allocation table
*/
void vpx_memory_tracker_dump();
/*
vpx_memory_tracker_check_integrity()
If a padding_size was provided to vpx_memory_tracker_init()
This function will verify that the region before and after each
memory address contains the specified pad_value. Should the check
fail, the filename and line of the check will be printed out.
*/
void vpx_memory_tracker_check_integrity(char *file, unsigned int line);
/*
vpx_memory_tracker_set_log_type
type - value representing the logging type to use
option - type specific option. This will be interpreted differently
based on the type.
Sets the logging type for the memory tracker.
Values currently supported:
0: if option is NULL, log to stderr, otherwise interpret option as a
filename and attempt to open it.
1: Use output_debug_string (WIN32 only), option ignored
Return:
0: on success
-1: if the logging type could not be set, because the value was invalid
or because a file could not be opened
*/
int vpx_memory_tracker_set_log_type(int type, char *option);
/*
vpx_memory_tracker_set_log_func
userdata - ptr to be passed to the supplied logfunc, can be NULL
logfunc - the logging function to be used to output data from
vpx_memory_track_dump/check_integrity
Sets a logging function to be used by the memory tracker.
Return:
0: on success
-1: if the logging type could not be set because logfunc was NULL
*/
int vpx_memory_tracker_set_log_func(void *userdata,
void(*logfunc)(void *userdata,
const char *fmt, va_list args));
/* Wrappers to standard library functions. */
typedef void *(* mem_track_malloc_func)(size_t);
typedef void *(* mem_track_calloc_func)(size_t, size_t);
typedef void *(* mem_track_realloc_func)(void *, size_t);
typedef void (* mem_track_free_func)(void *);
typedef void *(* mem_track_memcpy_func)(void *, const void *, size_t);
typedef void *(* mem_track_memset_func)(void *, int, size_t);
typedef void *(* mem_track_memmove_func)(void *, const void *, size_t);
/*
vpx_memory_tracker_set_functions
Sets the function pointers for the standard library functions.
Return:
0: on success
-1: if the use global function pointers is not set.
*/
int vpx_memory_tracker_set_functions(mem_track_malloc_func g_malloc_l
, mem_track_calloc_func g_calloc_l
, mem_track_realloc_func g_realloc_l
, mem_track_free_func g_free_l
, mem_track_memcpy_func g_memcpy_l
, mem_track_memset_func g_memset_l
, mem_track_memmove_func g_memmove_l);
#if defined(__cplusplus)
}
#endif
#endif // VPX_MEM_INCLUDE_VPX_MEM_TRACKER_H_
......@@ -18,15 +18,6 @@
#include "include/vpx_mem_intrnl.h"
#include "vpx/vpx_integer.h"
#if CONFIG_MEM_TRACKER
#ifndef VPX_NO_GLOBALS
static unsigned long g_alloc_count = 0;
#else
#include "vpx_global_handling.h"
#define g_alloc_count vpxglobalm(vpxmem,g_alloc_count)
#endif
#endif
#if USE_GLOBAL_FUNCTION_POINTERS
struct GLOBAL_FUNC_POINTERS {
g_malloc_func g_malloc;
......@@ -134,194 +125,6 @@ void vpx_free(void *memblk) {
}
}
#if CONFIG_MEM_TRACKER
void *xvpx_memalign(size_t align, size_t size, char *file, int line) {
#if TRY_BOUNDS_CHECK
unsigned char *x_bounds;
#endif
void *x;
if (g_alloc_count == 0) {
#if TRY_BOUNDS_CHECK
int i_rv = vpx_memory_tracker_init(BOUNDS_CHECK_PAD_SIZE, BOUNDS_CHECK_VALUE);
#else
int i_rv = vpx_memory_tracker_init(0, 0);
#endif
if (i_rv < 0) {
_P(printf("ERROR xvpx_malloc MEM_TRACK_USAGE error vpx_memory_tracker_init().\n");)
}
}
#if TRY_BOUNDS_CHECK
{
int i;
unsigned int tempme = BOUNDS_CHECK_VALUE;
x_bounds = vpx_memalign(align, size + (BOUNDS_CHECK_PAD_SIZE * 2));
if (x_bounds) {
/*we're aligning the address twice here but to keep things
consistent we want to have the padding come before the stored
address so no matter what free function gets called we will
attempt to free the correct address*/
x_bounds = (unsigned char *)(((size_t *)x_bounds)[-1]);
x = align_addr(x_bounds + BOUNDS_CHECK_PAD_SIZE + ADDRESS_STORAGE_SIZE,
(int)align);
/* save the actual malloc address */
((size_t *)x)[-1] = (size_t)x_bounds;
for (i = 0; i < BOUNDS_CHECK_PAD_SIZE; i += sizeof(unsigned int)) {
VPX_MEMCPY_L(x_bounds + i, &tempme, sizeof(unsigned int));
VPX_MEMCPY_L((unsigned char *)x + size + i,
&tempme, sizeof(unsigned int));
}
} else
x = NULL;
}
#else
x = vpx_memalign(align, size);
#endif /*TRY_BOUNDS_CHECK*/
g_alloc_count++;
vpx_memory_tracker_add((size_t)x, (unsigned int)size, file, line, 1);
return x;
}
void *xvpx_malloc(size_t size, char *file, int line) {
return xvpx_memalign(DEFAULT_ALIGNMENT, size, file, line);
}
void *xvpx_calloc(size_t num, size_t size, char *file, int line) {
void *x = xvpx_memalign(DEFAULT_ALIGNMENT, num * size, file, line);
if (x)
VPX_MEMSET_L(x, 0, num * size);
return x;
}
void *xvpx_realloc(void *memblk, size_t size, char *file, int line) {
struct mem_block *p = NULL;
int orig_size = 0,
orig_line = 0;
char *orig_file = NULL;
#if TRY_BOUNDS_CHECK
unsigned char *x_bounds = memblk ?
(unsigned char *)(((size_t *)memblk)[-1]) :
NULL;
#endif
void *x;
if (g_alloc_count == 0) {
#if TRY_BOUNDS_CHECK
if (!vpx_memory_tracker_init(BOUNDS_CHECK_PAD_SIZE, BOUNDS_CHECK_VALUE))
#else
if (!vpx_memory_tracker_init(0, 0))
#endif
{
_P(printf("ERROR xvpx_malloc MEM_TRACK_USAGE error vpx_memory_tracker_init().\n");)
}
}
if ((p = vpx_memory_tracker_find((size_t)memblk))) {
orig_size = p->size;
orig_file = p->file;
orig_line = p->line;
}
#if TRY_BOUNDS_CHECK_ON_FREE
vpx_memory_tracker_check_integrity(file, line);
#endif
/* have to do this regardless of success, because
* the memory that does get realloc'd may change
* the bounds values of this block
*/
vpx_memory_tracker_remove((size_t)memblk);
#if TRY_BOUNDS_CHECK
{
int i;
unsigned int tempme = BOUNDS_CHECK_VALUE;
x_bounds = vpx_realloc(memblk, size + (BOUNDS_CHECK_PAD_SIZE * 2));
if (x_bounds) {
x_bounds = (unsigned char *)(((size_t *)x_bounds)[-1]);
x = align_addr(x_bounds + BOUNDS_CHECK_PAD_SIZE + ADDRESS_STORAGE_SIZE,
(int)DEFAULT_ALIGNMENT);
/* save the actual malloc address */
((size_t *)x)[-1] = (size_t)x_bounds;
for (i = 0; i < BOUNDS_CHECK_PAD_SIZE; i += sizeof(unsigned int)) {
VPX_MEMCPY_L(x_bounds + i, &tempme, sizeof(unsigned int));
VPX_MEMCPY_L((unsigned char *)x + size + i,
&tempme, sizeof(unsigned int));
}
} else
x = NULL;
}
#else
x = vpx_realloc(memblk, size);
#endif /*TRY_BOUNDS_CHECK*/
if (!memblk) ++g_alloc_count;
if (x)
vpx_memory_tracker_add((size_t)x, (unsigned int)size, file, line, 1);
else
vpx_memory_tracker_add((size_t)memblk, orig_size, orig_file, orig_line, 1);
return x;
}
void xvpx_free(void *p_address, char *file, int line) {
#if TRY_BOUNDS_CHECK
unsigned char *p_bounds_address = (unsigned char *)p_address;
/*p_bounds_address -= BOUNDS_CHECK_PAD_SIZE;*/
#endif
#if !TRY_BOUNDS_CHECK_ON_FREE
(void)file;
(void)line;
#endif
if (p_address) {
#if TRY_BOUNDS_CHECK_ON_FREE
vpx_memory_tracker_check_integrity(file, line);
#endif
/* if the addr isn't found in the list, assume it was allocated via
* vpx_ calls not xvpx_, therefore it does not contain any padding
*/
if (vpx_memory_tracker_remove((size_t)p_address) == -2) {
p_bounds_address = p_address;
_P(fprintf(stderr, "[vpx_mem][xvpx_free] addr: %p not found in"
" list; freed from file:%s"
" line:%d\n", p_address, file, line));
} else
--g_alloc_count;
#if TRY_BOUNDS_CHECK
vpx_free(p_bounds_address);
#else
vpx_free(p_address);
#endif
if (!g_alloc_count)
vpx_memory_tracker_destroy();
}
}
#endif /*CONFIG_MEM_TRACKER*/
void *vpx_memcpy(void *dest, const void *source, size_t length) {
return VPX_MEMCPY_L(dest, source, length);
}
......@@ -345,17 +148,6 @@ void *vpx_memmove(void *dest, const void *src, size_t count) {
return VPX_MEMMOVE_L(dest, src, count);
}
#if USE_GLOBAL_FUNCTION_POINTERS
# if CONFIG_MEM_TRACKER
extern int vpx_memory_tracker_set_functions(g_malloc_func g_malloc_l
, g_calloc_func g_calloc_l
, g_realloc_func g_realloc_l
, g_free_func g_free_l
, g_memcpy_func g_memcpy_l
, g_memset_func g_memset_l
, g_memmove_func g_memmove_l);
# endif
#endif /*USE_GLOBAL_FUNCTION_POINTERS*/
int vpx_mem_set_functions(g_malloc_func g_malloc_l
, g_calloc_func g_calloc_l
, g_realloc_func g_realloc_l
......@@ -378,23 +170,6 @@ int vpx_mem_set_functions(g_malloc_func g_malloc_l
}
}
#if CONFIG_MEM_TRACKER
{
int rv = 0;
rv = vpx_memory_tracker_set_functions(g_malloc_l
, g_calloc_l
, g_realloc_l
, g_free_l
, g_memcpy_l
, g_memset_l
, g_memmove_l);
if (rv < 0) {
return rv;
}
}
#endif
g_func->g_malloc = g_malloc_l;
g_func->g_calloc = g_calloc_l;
g_func->g_realloc = g_realloc_l;
......
......@@ -26,9 +26,6 @@
#define VPX_MEM_VERSION_PATCH 5
/* end - vpx_mem version info */
#ifndef VPX_TRACK_MEM_USAGE
# define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks */
#endif
#ifndef REPLACE_BUILTIN_FUNCTIONS
# define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their
vpx_ equivalents */
......@@ -62,10 +59,6 @@ extern "C" {
#endif
void *vpx_memmove(void *dest, const void *src, size_t count);
/* special memory functions */
void *vpx_mem_alloc(int id, size_t size, size_t align);
void vpx_mem_free(int id, void *mem, size_t size);
/* Wrappers to standard library functions. */
typedef void *(* g_malloc_func)(size_t);
typedef void *(* g_calloc_func)(size_t, size_t);
......@@ -103,43 +96,6 @@ extern "C" {
# endif
#endif
#if CONFIG_MEM_TRACKER
#include <stdarg.h>
/*from vpx_mem/vpx_mem_tracker.c*/
extern void vpx_memory_tracker_dump();
extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line);
extern int vpx_memory_tracker_set_log_type(int type, char *option);
extern int vpx_memory_tracker_set_log_func(void *userdata,
void(*logfunc)(void *userdata,
const char *fmt, va_list args));
# ifndef __VPX_MEM_C__
# define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __LINE__)
# define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__)
# define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__)
# define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__)
# define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__)
# define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrity(__FILE__, __LINE__)
# define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__, __LINE__)
# define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LINE__)
# endif
void *xvpx_memalign(size_t align, size_t size, char *file, int line);
void *xvpx_malloc(size_t size, char *file, int line);
void *xvpx_calloc(size_t num, size_t size, char *file, int line);
void *xvpx_realloc(void *memblk, size_t size, char *file, int line);
void xvpx_free(void *memblk, char *file, int line);
void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line);
void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line);
#else
# ifndef __VPX_MEM_C__
# define vpx_memory_tracker_dump()
# define vpx_memory_tracker_check_integrity()
# define vpx_memory_tracker_set_log_type(t,o) 0
# define vpx_memory_tracker_set_log_func(u,f) 0
# endif
#endif
#ifndef __VPX_MEM_C__
# include <string.h>
# define vpx_memcpy memcpy
......
......@@ -2,6 +2,3 @@ MEM_SRCS-yes += vpx_mem.mk
MEM_SRCS-yes += vpx_mem.c
MEM_SRCS-yes += vpx_mem.h
MEM_SRCS-yes += include/vpx_mem_intrnl.h
MEM_SRCS-$(CONFIG_MEM_TRACKER) += vpx_mem_tracker.c
MEM_SRCS-$(CONFIG_MEM_TRACKER) += include/vpx_mem_tracker.h
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment