From f3af39ee42b954ec0486986c7cfac9ee44cd63e4 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Sun, 16 Jan 2022 12:47:33 +0100 Subject: Added performance tests tools --- src/include/ndpi_api.h.in | 3 ++- src/lib/ndpi_main.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/include/ndpi_api.h.in b/src/include/ndpi_api.h.in index 02436b285..f94fd4093 100644 --- a/src/include/ndpi_api.h.in +++ b/src/include/ndpi_api.h.in @@ -118,7 +118,8 @@ extern "C" { void ndpi_free(void *ptr); void * ndpi_flow_malloc(size_t size); void ndpi_flow_free(void *ptr); - + u_int32_t ndpi_get_tot_allocated_memory(); + /** * Search the first occurrence of substring -find- in -s- * The search is limited to the first -slen- characters of the string diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index 8d88b5c2e..20df63de6 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -139,9 +139,23 @@ static inline uint8_t flow_is_proto(struct ndpi_flow_struct *flow, u_int16_t p) /* ****************************************** */ +static u_int32_t ndpi_tot_allocated_memory; + +/* ****************************************** */ + +u_int32_t ndpi_get_tot_allocated_memory() { + return(ndpi_tot_allocated_memory); +} + +/* ****************************************** */ + void *ndpi_malloc(size_t size) { + ndpi_tot_allocated_memory += size; return(_ndpi_malloc ? _ndpi_malloc(size) : malloc(size)); } + +/* ****************************************** */ + void *ndpi_flow_malloc(size_t size) { return(_ndpi_flow_malloc ? _ndpi_flow_malloc(size) : ndpi_malloc(size)); } @@ -152,9 +166,11 @@ void *ndpi_calloc(unsigned long count, size_t size) { size_t len = count * size; void *p = ndpi_malloc(len); - if(p) + if(p) { memset(p, 0, len); - + ndpi_tot_allocated_memory += size; + } + return(p); } -- cgit v1.2.3