From 9203c1c23c7e3abf7c3c82f82402561b12a82986 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 10 May 2024 13:15:37 +0200 Subject: [PATCH] zstd debug --- readsb.c | 7 +++++++ readsb.h | 1 + util.c | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/readsb.c b/readsb.c index 8bd8fbde..de2197b3 100644 --- a/readsb.c +++ b/readsb.c @@ -541,8 +541,12 @@ static void *jsonEntryPoint(void *arg) { threadpool_buffer_t pass_buffer = { 0 }; threadpool_buffer_t zstd_buffer = { 0 }; + if (Modes.debug_zstd) { fprintf(stderr, "calling ZSTD_createCCtx()\n"); } + ZSTD_CCtx* cctx = ZSTD_createCCtx(); + if (Modes.debug_zstd) { fprintf(stderr, "ZSTD_createCCtx() returned %p\n", cctx); } + while (!Modes.exit) { struct timespec start_time; @@ -1926,6 +1930,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { if (strcasecmp(token[0], "debugGPS") == 0) { Modes.debug_gps = 1; } + if (strcasecmp(token[0], "debugZstd") == 0) { + Modes.debug_zstd = 1; + } sfree(argdup); } diff --git a/readsb.h b/readsb.h index fc13e113..1cd1a6db 100644 --- a/readsb.h +++ b/readsb.h @@ -670,6 +670,7 @@ struct _Modes int8_t debug_lastStatus; int8_t debug_gps; int8_t debug_planefinder; + int8_t debug_zstd; int8_t incrementId; int8_t omitGlobeFiles; int8_t enableAcasCsv; diff --git a/util.c b/util.c index 2a20ba4e..df834d86 100644 --- a/util.c +++ b/util.c @@ -864,7 +864,13 @@ struct char_buffer generateZstd(ZSTD_CCtx* cctx, threadpool_buffer_t *pbuffer, s check_grow_threadpool_buffer_t(pbuffer, ZSTD_compressBound(src.len)); - //fprintf(stderr, "pbuffer->size: %ld src.len %ld\n", (long) pbuffer->size, (long) src.len); + if (Modes.debug_zstd) { + fprintf(stderr, "calling ZSTD_compressCCtx() with cctx %p pbuffer->size %6ld" + " src.buffer %p src.len %6ld level %d src.buffer[0] 0x%02x cctx_first_byte 0x%02x\n" + , cctx, (long) pbuffer->size, + src.buffer, (long) src.len, level, (uint8_t) src.buffer[0], (uint8_t) ((uint8_t *) cctx)[0] + ); + } /* * size_t ZSTD_compressCCtx(ZSTD_CCtx* cctx, @@ -878,6 +884,10 @@ struct char_buffer generateZstd(ZSTD_CCtx* cctx, threadpool_buffer_t *pbuffer, s src.buffer, src.len, level); + if (Modes.debug_zstd) { + fprintf(stderr, "calling ZSTD_isError() with compressedSize: %zd\n", compressedSize); + } + if (ZSTD_isError(compressedSize)) { fprintf(stderr, "generateZstd() zstd error: %s\n", ZSTD_getErrorName(compressedSize)); cb.buffer = NULL;