Removed ENABLE_MEMORY_STATUS CMake option as it's now enabled for **all** builds

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2024-10-22 13:12:59 +02:00
parent ae36f8df6c
commit 7d58703bdb
4 changed files with 7 additions and 32 deletions

View File

@@ -222,20 +222,20 @@ jobs:
run: | run: |
pkg-config --cflags --libs libndpi pkg-config --cflags --libs libndpi
cc -Wall -Wextra -std=gnu99 \ cc -Wall -Wextra -std=gnu99 \
${{ matrix.poll }} -DENABLE_MEMORY_STATUS=1 -DENABLE_MEMORY_PROFILING=1 \ ${{ matrix.poll }} -DENABLE_MEMORY_PROFILING=1 \
nDPId.c nio.c utils.c \ nDPId.c nio.c utils.c \
$(pkg-config --cflags libndpi) -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \ $(pkg-config --cflags libndpi) -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \
-o /tmp/a.out \ -o /tmp/a.out \
-lpcap $(pkg-config --libs libndpi) -pthread -lm -lpcap $(pkg-config --libs libndpi) -pthread -lm
cc -Wall -Wextra -std=gnu99 \ cc -Wall -Wextra -std=gnu99 \
${{ matrix.poll }} -DENABLE_MEMORY_STATUS=1 -DENABLE_MEMORY_PROFILING=1 \ ${{ matrix.poll }} -DENABLE_MEMORY_PROFILING=1 \
nDPIsrvd.c nio.c utils.c \ nDPIsrvd.c nio.c utils.c \
-I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \ -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \
-o /tmp/a.out -o /tmp/a.out
- name: Build single nDPId/nDPIsrvd executables (invoke CC directly - static nDPI lib) - name: Build single nDPId/nDPIsrvd executables (invoke CC directly - static nDPI lib)
if: endsWith(matrix.compiler, 'gcc-7') == false && startsWith(matrix.ndpi_build, '-DBUILD_NDPI=ON') && startsWith(matrix.coverage, '-DENABLE_COVERAGE=OFF') && startsWith(matrix.sanitizer, '-DENABLE_SANITIZER=ON') && startsWith(matrix.ndpid_gcrypt, '-DNDPI_WITH_GCRYPT=OFF') && startsWith(matrix.ndpid_zlib, '-DENABLE_ZLIB=ON') if: endsWith(matrix.compiler, 'gcc-7') == false && startsWith(matrix.ndpi_build, '-DBUILD_NDPI=ON') && startsWith(matrix.coverage, '-DENABLE_COVERAGE=OFF') && startsWith(matrix.sanitizer, '-DENABLE_SANITIZER=ON') && startsWith(matrix.ndpid_gcrypt, '-DNDPI_WITH_GCRYPT=OFF') && startsWith(matrix.ndpid_zlib, '-DENABLE_ZLIB=ON')
run: | run: |
cc -Wall -Wextra -std=gnu99 ${{ matrix.poll }} -DENABLE_ZLIB=1 -DENABLE_MEMORY_STATUS=1 -DENABLE_MEMORY_PROFILING=1 \ cc -Wall -Wextra -std=gnu99 ${{ matrix.poll }} -DENABLE_ZLIB=1 -DENABLE_MEMORY_PROFILING=1 \
-fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak \ -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak \
nDPId.c nio.c utils.c \ nDPId.c nio.c utils.c \
-I./build/libnDPI/include/ndpi -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \ -I./build/libnDPI/include/ndpi -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \
@@ -294,7 +294,7 @@ jobs:
git clone --depth=1 https://github.com/ntop/PF_RING.git git clone --depth=1 https://github.com/ntop/PF_RING.git
cd PF_RING && make all && sudo make install prefix=/usr cd PF_RING && make all && sudo make install prefix=/usr
cd .. cd ..
cc -Wall -Wextra -std=gnu99 ${{ matrix.poll }} -DENABLE_PFRING=1 -DENABLE_ZLIB=1 -DENABLE_MEMORY_STATUS=1 -DENABLE_MEMORY_PROFILING=1 \ cc -Wall -Wextra -std=gnu99 ${{ matrix.poll }} -DENABLE_PFRING=1 -DENABLE_ZLIB=1 -DENABLE_MEMORY_PROFILING=1 \
-fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak \ -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fsanitize=enum -fsanitize=leak \
nDPId.c npfring.c nio.c utils.c \ nDPId.c npfring.c nio.c utils.c \
-I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \ -I. -I./dependencies -I./dependencies/jsmn -I./dependencies/uthash/include \

View File

@@ -83,7 +83,6 @@ endif()
option(ENABLE_COVERAGE "Generate a code coverage report using lcov/genhtml." OFF) option(ENABLE_COVERAGE "Generate a code coverage report using lcov/genhtml." OFF)
option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF) option(ENABLE_SANITIZER "Enable ASAN/LSAN/UBSAN." OFF)
option(ENABLE_SANITIZER_THREAD "Enable TSAN (does not work together with ASAN)." OFF) option(ENABLE_SANITIZER_THREAD "Enable TSAN (does not work together with ASAN)." OFF)
option(ENABLE_MEMORY_STATUS "Enable malloc/free wrapper to gather and send heap memory statistics." ON)
option(ENABLE_MEMORY_PROFILING "Enable dynamic memory tracking." OFF) option(ENABLE_MEMORY_PROFILING "Enable dynamic memory tracking." OFF)
option(ENABLE_ZLIB "Enable zlib support for nDPId (experimental)." OFF) option(ENABLE_ZLIB "Enable zlib support for nDPId (experimental)." OFF)
option(ENABLE_SYSTEMD "Install systemd components." OFF) option(ENABLE_SYSTEMD "Install systemd components." OFF)
@@ -187,13 +186,6 @@ else()
unset(NDPI_WITH_MAXMINDDB CACHE) unset(NDPI_WITH_MAXMINDDB CACHE)
endif() endif()
if (ENABLE_MEMORY_STATUS)
set(MEMORY_STATUS_DEFS "-DENABLE_MEMORY_STATUS=1")
endif()
if (ENABLE_MEMORY_PROFILING AND NOT ENABLE_MEMORY_STATUS)
message(FATAL_ERROR "ENABLE_MEMORY_PROFILING requires ENABLE_MEMORY_STATUS to make it work!")
endif()
if(ENABLE_PFRING) if(ENABLE_PFRING)
set(NDPID_PFRING_SRCS npfring.c) set(NDPID_PFRING_SRCS npfring.c)
endif() endif()
@@ -430,7 +422,7 @@ if(NOT pkgcfg_lib_PCAP_pcap)
endif() endif()
target_compile_options(nDPId PRIVATE "-pthread") target_compile_options(nDPId PRIVATE "-pthread")
target_compile_definitions(nDPId PRIVATE -D_GNU_SOURCE=1 -DPKG_VERSION=\"${PKG_VERSION}\" -DGIT_VERSION=\"${GIT_VERSION}\" ${NDPID_DEFS} ${EPOLL_DEFS} ${ZLIB_DEFS} ${PFRING_DEFS} ${MEMORY_STATUS_DEFS}) target_compile_definitions(nDPId PRIVATE -D_GNU_SOURCE=1 -DPKG_VERSION=\"${PKG_VERSION}\" -DGIT_VERSION=\"${GIT_VERSION}\" ${NDPID_DEFS} ${EPOLL_DEFS} ${ZLIB_DEFS} ${PFRING_DEFS})
target_include_directories(nDPId PRIVATE "${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" ${NDPID_DEPS_INC} ${PFRING_KERNEL_INC} ${PFRING_INC}) target_include_directories(nDPId PRIVATE "${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" ${NDPID_DEPS_INC} ${PFRING_KERNEL_INC} ${PFRING_INC})
target_link_libraries(nDPId "${STATIC_LIBNDPI_LIB}" "${STATIC_PFRING_LIB}" "${pkgcfg_lib_PCAP_pcap}" "${pkgcfg_lib_NDPI_ndpi}" target_link_libraries(nDPId "${STATIC_LIBNDPI_LIB}" "${STATIC_PFRING_LIB}" "${pkgcfg_lib_PCAP_pcap}" "${pkgcfg_lib_NDPI_ndpi}"
"${pkgcfg_lib_PCRE_pcre2-8}" "${pkgcfg_lib_MAXMINDDB_maxminddb}" "${pkgcfg_lib_ZLIB_z}" "${pkgcfg_lib_PCRE_pcre2-8}" "${pkgcfg_lib_MAXMINDDB_maxminddb}" "${pkgcfg_lib_ZLIB_z}"
@@ -442,7 +434,7 @@ target_include_directories(nDPIsrvd PRIVATE ${NDPID_DEPS_INC})
target_compile_options(nDPId-test PRIVATE "-Wno-unused-function" "-pthread") target_compile_options(nDPId-test PRIVATE "-Wno-unused-function" "-pthread")
target_compile_definitions(nDPId-test PRIVATE -D_GNU_SOURCE=1 -DNO_MAIN=1 -DPKG_VERSION=\"${PKG_VERSION}\" -DGIT_VERSION=\"${GIT_VERSION}\" target_compile_definitions(nDPId-test PRIVATE -D_GNU_SOURCE=1 -DNO_MAIN=1 -DPKG_VERSION=\"${PKG_VERSION}\" -DGIT_VERSION=\"${GIT_VERSION}\"
${NDPID_DEFS} ${EPOLL_DEFS} ${ZLIB_DEFS} ${PFRING_DEFS} ${MEMORY_STATUS_DEFS} ${NDPID_TEST_MPROF_DEFS}) ${NDPID_DEFS} ${EPOLL_DEFS} ${ZLIB_DEFS} ${PFRING_DEFS} ${NDPID_TEST_MPROF_DEFS})
target_include_directories(nDPId-test PRIVATE target_include_directories(nDPId-test PRIVATE
"${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" ${NDPID_DEPS_INC} ${PFRING_KERNEL_INC} ${PFRING_INC}) "${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" ${NDPID_DEPS_INC} ${PFRING_KERNEL_INC} ${PFRING_INC})
target_link_libraries(nDPId-test "${STATIC_LIBNDPI_LIB}" "${STATIC_PFRING_LIB}" "${pkgcfg_lib_PCAP_pcap}" "${pkgcfg_lib_NDPI_ndpi}" target_link_libraries(nDPId-test "${STATIC_LIBNDPI_LIB}" "${STATIC_PFRING_LIB}" "${pkgcfg_lib_PCAP_pcap}" "${pkgcfg_lib_NDPI_ndpi}"
@@ -580,7 +572,6 @@ endif()
message(STATUS "ENABLE_COVERAGE..........: ${ENABLE_COVERAGE}") message(STATUS "ENABLE_COVERAGE..........: ${ENABLE_COVERAGE}")
message(STATUS "ENABLE_SANITIZER.........: ${ENABLE_SANITIZER}") message(STATUS "ENABLE_SANITIZER.........: ${ENABLE_SANITIZER}")
message(STATUS "ENABLE_SANITIZER_THREAD..: ${ENABLE_SANITIZER_THREAD}") message(STATUS "ENABLE_SANITIZER_THREAD..: ${ENABLE_SANITIZER_THREAD}")
message(STATUS "ENABLE_MEMORY_STATUS.....: ${ENABLE_MEMORY_STATUS}")
message(STATUS "ENABLE_MEMORY_PROFILING..: ${ENABLE_MEMORY_PROFILING}") message(STATUS "ENABLE_MEMORY_PROFILING..: ${ENABLE_MEMORY_PROFILING}")
message(STATUS "ENABLE_ZLIB..............: ${ENABLE_ZLIB}") message(STATUS "ENABLE_ZLIB..............: ${ENABLE_ZLIB}")
message(STATUS "BUILD_NDPI...............: ${BUILD_NDPI}") message(STATUS "BUILD_NDPI...............: ${BUILD_NDPI}")

View File

@@ -1649,12 +1649,10 @@ int main(int argc, char ** argv)
return 1; return 1;
} }
#ifdef ENABLE_MEMORY_STATUS
set_ndpi_malloc(ndpi_malloc_wrapper); set_ndpi_malloc(ndpi_malloc_wrapper);
set_ndpi_free(ndpi_free_wrapper); set_ndpi_free(ndpi_free_wrapper);
set_ndpi_flow_malloc(NULL); set_ndpi_flow_malloc(NULL);
set_ndpi_flow_free(NULL); set_ndpi_flow_free(NULL);
#endif
init_logging("nDPId-test"); init_logging("nDPId-test");
log_app_info(); log_app_info();

16
nDPId.c
View File

@@ -75,10 +75,6 @@
#error "Invalid value for nDPId_PACKETS_PLEN_MAX" #error "Invalid value for nDPId_PACKETS_PLEN_MAX"
#endif #endif
#if defined(ENABLE_MEMORY_PROFILING) && !defined(ENABLE_MEMORY_STATUS)
#error "ENABLE_MEMORY_PROFILING requires ENABLE_MEMORY_STATUS to make it work!"
#endif
/* MIPS* does not support Compare and Swap. Use traditional locking as fallback. */ /* MIPS* does not support Compare and Swap. Use traditional locking as fallback. */
#if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) #if !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
#define MT_VALUE(name, type) \ #define MT_VALUE(name, type) \
@@ -462,7 +458,6 @@ static struct nDPId_reader_thread reader_threads[nDPId_MAX_READER_THREADS] = {};
static MT_VALUE(nDPId_main_thread_shutdown, int) = MT_INIT(0); static MT_VALUE(nDPId_main_thread_shutdown, int) = MT_INIT(0);
static MT_VALUE(global_flow_id, uint64_t) = MT_INIT(1); static MT_VALUE(global_flow_id, uint64_t) = MT_INIT(1);
#ifdef ENABLE_MEMORY_STATUS
static MT_VALUE(ndpi_memory_alloc_count, uint64_t) = MT_INIT(0); static MT_VALUE(ndpi_memory_alloc_count, uint64_t) = MT_INIT(0);
static MT_VALUE(ndpi_memory_alloc_bytes, uint64_t) = MT_INIT(0); static MT_VALUE(ndpi_memory_alloc_bytes, uint64_t) = MT_INIT(0);
static MT_VALUE(ndpi_memory_free_count, uint64_t) = MT_INIT(0); static MT_VALUE(ndpi_memory_free_count, uint64_t) = MT_INIT(0);
@@ -473,7 +468,6 @@ static MT_VALUE(zlib_decompressions, uint64_t) = MT_INIT(0);
static MT_VALUE(zlib_compression_diff, uint64_t) = MT_INIT(0); static MT_VALUE(zlib_compression_diff, uint64_t) = MT_INIT(0);
static MT_VALUE(zlib_compression_bytes, uint64_t) = MT_INIT(0); static MT_VALUE(zlib_compression_bytes, uint64_t) = MT_INIT(0);
#endif #endif
#endif
static struct static struct
{ {
@@ -747,11 +741,9 @@ static int zlib_deflate(const void * const src, int srcLen, void * dst, int dstL
if (err == Z_STREAM_END) if (err == Z_STREAM_END)
{ {
ret = strm.total_out; ret = strm.total_out;
#ifdef ENABLE_MEMORY_STATUS
MT_GET_AND_ADD(zlib_compressions, 1); MT_GET_AND_ADD(zlib_compressions, 1);
MT_GET_AND_ADD(zlib_compression_diff, srcLen - ret); MT_GET_AND_ADD(zlib_compression_diff, srcLen - ret);
MT_GET_AND_ADD(zlib_compression_bytes, ret); MT_GET_AND_ADD(zlib_compression_bytes, ret);
#endif
} }
else else
{ {
@@ -791,10 +783,8 @@ static int zlib_inflate(const void * src, int srcLen, void * dst, int dstLen)
if (err == Z_STREAM_END) if (err == Z_STREAM_END)
{ {
ret = strm.total_out; ret = strm.total_out;
#ifdef ENABLE_MEMORY_STATUS
MT_GET_AND_ADD(zlib_decompressions, 1); MT_GET_AND_ADD(zlib_decompressions, 1);
MT_GET_AND_SUB(zlib_compression_diff, ret - srcLen); MT_GET_AND_SUB(zlib_compression_diff, ret - srcLen);
#endif
} }
else else
{ {
@@ -1118,7 +1108,6 @@ static int get_ip_netmask_from_pcap_dev(char const * const pcap_dev)
return retval; return retval;
} }
#ifdef ENABLE_MEMORY_STATUS
static void * ndpi_malloc_wrapper(size_t const size) static void * ndpi_malloc_wrapper(size_t const size)
{ {
void * p = malloc(sizeof(uint64_t) + size); void * p = malloc(sizeof(uint64_t) + size);
@@ -1144,7 +1133,6 @@ static void ndpi_free_wrapper(void * const freeable)
free(p); free(p);
} }
#endif
#ifdef ENABLE_MEMORY_PROFILING #ifdef ENABLE_MEMORY_PROFILING
static void log_memory_usage(struct nDPId_reader_thread const * const reader_thread) static void log_memory_usage(struct nDPId_reader_thread const * const reader_thread)
@@ -2399,7 +2387,7 @@ static void jsonize_daemon(struct nDPId_reader_thread * const reader_thread, enu
ndpi_serialize_string_uint64(&workflow->ndpi_serializer, "total-compression-diff", 0); ndpi_serialize_string_uint64(&workflow->ndpi_serializer, "total-compression-diff", 0);
ndpi_serialize_string_uint64(&workflow->ndpi_serializer, "current-compression-diff", 0); ndpi_serialize_string_uint64(&workflow->ndpi_serializer, "current-compression-diff", 0);
#endif #endif
#if defined(ENABLE_MEMORY_STATUS) && !defined(NO_MAIN) #ifndef NO_MAIN
/* /*
* Global memory stats may very from run to run. * Global memory stats may very from run to run.
* Due to this, `nDPId-test' results would be inconsistent and is disabled if NO_MAIN defined. * Due to this, `nDPId-test' results would be inconsistent and is disabled if NO_MAIN defined.
@@ -5721,12 +5709,10 @@ int main(int argc, char ** argv)
return 1; return 1;
} }
#ifdef ENABLE_MEMORY_STATUS
set_ndpi_malloc(ndpi_malloc_wrapper); set_ndpi_malloc(ndpi_malloc_wrapper);
set_ndpi_free(ndpi_free_wrapper); set_ndpi_free(ndpi_free_wrapper);
set_ndpi_flow_malloc(NULL); set_ndpi_flow_malloc(NULL);
set_ndpi_flow_free(NULL); set_ndpi_flow_free(NULL);
#endif
init_logging("nDPId"); init_logging("nDPId");