diff --git a/CMakeLists.txt b/CMakeLists.txt index 72261da2..4e919904 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(HDR_SOVERSION_REVISION 0) set(HDR_VERSION ${HDR_SOVERSION_CURRENT}.${HDR_SOVERSION_AGE}.${HDR_SOVERSION_REVISION}) set(HDR_SOVERSION ${HDR_SOVERSION_CURRENT}) +option(HDR_LOG_REQUIRED "HDR Logging component required" ON) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) @@ -41,6 +42,14 @@ if(UNIX) -D_GNU_SOURCE) endif() +find_package(ZLIB) +find_package(Threads REQUIRED) + +set(HDR_LOG_ENABLED ${ZLIB_FOUND}) +if (${HDR_LOG_REQUIRED} AND NOT HDR_LOG_ENABLED) + message(SEND_ERROR "HDR_LOG_REQUIRED=ON and unable to find zlib library") +endif() + add_subdirectory(src) option(HDR_HISTOGRAM_BUILD_PROGRAMS "Build tests and examples" ON) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 42b3351b..062af189 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,25 +1,27 @@ -add_executable(hdr_decoder - hdr_decoder.c) -target_link_libraries(hdr_decoder - PRIVATE - $<$:hdr_histogram_static> - $<$>:hdr_histogram>) -install( - TARGETS hdr_decoder - EXPORT ${PROJECT_NAME}-targets - DESTINATION ${CMAKE_INSTALL_BINDIR}) - -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - find_package(Threads) - - add_executable(hiccup - hiccup.c) - target_link_libraries(hiccup +if (HDR_LOG_ENABLED) + add_executable(hdr_decoder + hdr_decoder.c) + target_link_libraries(hdr_decoder PRIVATE - hdr_histogram - Threads::Threads) + $<$:hdr_histogram_static> + $<$>:hdr_histogram>) install( - TARGETS hiccup + TARGETS hdr_decoder EXPORT ${PROJECT_NAME}-targets DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() + + if(CMAKE_SYSTEM_NAME MATCHES "Linux") + find_package(Threads) + + add_executable(hiccup + hiccup.c) + target_link_libraries(hiccup + PRIVATE + hdr_histogram + Threads::Threads) + install( + TARGETS hiccup + EXPORT ${PROJECT_NAME}-targets + DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e56c9af..2ff2f317 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,20 @@ -find_package(ZLIB REQUIRED) -find_package(Threads REQUIRED) include(CheckLibraryExists) check_library_exists(m ceil "" HAVE_LIBM) check_library_exists(rt clock_gettime "" HAVE_LIBRT) +if (HDR_LOG_ENABLED) + set(HDR_LOG_IMPLEMENTATION hdr_histogram_log.c) + set(HDR_ZLIB ZLIB::ZLIB) +else() + set(HDR_LOG_IMPLEMENTATION hdr_histogram_log_no_op.c) + set(HDR_ZLIB "") +endif() + set(HDR_HISTOGRAM_SOURCES hdr_encoding.c hdr_histogram.c - hdr_histogram_log.c + ${HDR_LOG_IMPLEMENTATION} hdr_interval_recorder.c hdr_thread.c hdr_time.c @@ -35,7 +41,9 @@ function(hdr_histogram_add_library NAME LIBRARY_TYPE DO_INSTALL) ${HDR_HISTOGRAM_PUBLIC_HEADERS}) target_link_libraries(${NAME} PRIVATE - ZLIB::ZLIB +# ZLIB::ZLIB + ${HDR_ZLIB} +# $<$ZLIB::ZLIB> Threads::Threads $<$:m> $<$:rt> diff --git a/src/hdr_histogram_log_no_op.c b/src/hdr_histogram_log_no_op.c new file mode 100644 index 00000000..e46aff2d --- /dev/null +++ b/src/hdr_histogram_log_no_op.c @@ -0,0 +1,171 @@ +/** + * hdr_histogram_log.c + * Written by Michael Barker and released to the public domain, + * as explained at http://creativecommons.org/publicdomain/zero/1.0/ + */ + +#include +#include +#include + +#include "hdr_histogram.h" +#include "hdr_histogram_log.h" +#include "hdr_tests.h" + +#define UNUSED(x) (void)(x) + +const char* hdr_strerror(int errnum) +{ + switch (errnum) + { + case HDR_COMPRESSION_COOKIE_MISMATCH: + return "Compression cookie mismatch"; + case HDR_ENCODING_COOKIE_MISMATCH: + return "Encoding cookie mismatch"; + case HDR_DEFLATE_INIT_FAIL: + return "Deflate initialisation failed"; + case HDR_DEFLATE_FAIL: + return "Deflate failed"; + case HDR_INFLATE_INIT_FAIL: + return "Inflate initialisation failed"; + case HDR_INFLATE_FAIL: + return "Inflate failed"; + case HDR_LOG_INVALID_VERSION: + return "Log - invalid version in log header"; + case HDR_TRAILING_ZEROS_INVALID: + return "Invalid number of trailing zeros"; + case HDR_VALUE_TRUNCATED: + return "Truncated value found when decoding"; + case HDR_ENCODED_INPUT_TOO_LONG: + return "The encoded input exceeds the size of the histogram"; + default: + return strerror(errnum); + } +} + +int hdr_encode_compressed( + struct hdr_histogram* h, + uint8_t** compressed_histogram, + size_t* compressed_len) +{ + UNUSED(h); + UNUSED(compressed_histogram); + UNUSED(compressed_len); + + return -1; +} + +int hdr_decode_compressed( + uint8_t* buffer, size_t length, struct hdr_histogram** histogram) +{ + UNUSED(buffer); + UNUSED(length); + UNUSED(histogram); + + return -1; +} + +int hdr_log_writer_init(struct hdr_log_writer* writer) +{ + UNUSED(writer); + + return -1; +} + +int hdr_log_write_header( + struct hdr_log_writer* writer, FILE* file, + const char* user_prefix, hdr_timespec* timestamp) +{ + UNUSED(writer); + UNUSED(file); + UNUSED(user_prefix); + UNUSED(timestamp); + + return -1; +} + +int hdr_log_write( + struct hdr_log_writer* writer, + FILE* file, + const hdr_timespec* start_timestamp, + const hdr_timespec* end_timestamp, + struct hdr_histogram* histogram) +{ + UNUSED(writer); + UNUSED(file); + UNUSED(start_timestamp); + UNUSED(end_timestamp); + UNUSED(histogram); + + return -1; +} + +int hdr_log_write_entry( + struct hdr_log_writer* writer, + FILE* file, + struct hdr_log_entry* entry, + struct hdr_histogram* histogram) +{ + UNUSED(writer); + UNUSED(file); + UNUSED(entry); + UNUSED(histogram); + + return -1; +} + +int hdr_log_reader_init(struct hdr_log_reader* reader) +{ + UNUSED(reader); + + return -1; +} + +int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file) +{ + UNUSED(reader); + UNUSED(file); + + return -1; +} + +int hdr_log_read( + struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram, + hdr_timespec* timestamp, hdr_timespec* interval) +{ + UNUSED(reader); + UNUSED(file); + UNUSED(histogram); + UNUSED(timestamp); + UNUSED(interval); + + return -1; +} + +int hdr_log_read_entry( + struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram) +{ + UNUSED(reader); + UNUSED(file); + UNUSED(entry); + UNUSED(histogram); + + return -1; +} + +int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram) +{ + UNUSED(histogram); + UNUSED(encoded_histogram); + + return -1; +} + +int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len) +{ + UNUSED(histogram); + UNUSED(base64_histogram); + UNUSED(base64_len); + + return -1; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1a0d22e2..f795e335 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,7 +61,9 @@ endfunction() hdr_histogram_add_test(hdr_histogram_test) hdr_histogram_add_test(hdr_histogram_atomic_test) -hdr_histogram_add_test(hdr_histogram_log_test) +if (HDR_LOG_ENABLED) + hdr_histogram_add_test(hdr_histogram_log_test) +endif() hdr_histogram_add_test(hdr_atomic_test) if(UNIX) hdr_histogram_add_test(hdr_histogram_atomic_concurrency_test)