Skip to content

Commit 16a9c93

Browse files
committed
Make the hdr histogram log optional if allowed and zlib not found.
1 parent b9c1b3e commit 16a9c93

File tree

5 files changed

+218
-26
lines changed

5 files changed

+218
-26
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set(HDR_SOVERSION_REVISION 0)
1919

2020
set(HDR_VERSION ${HDR_SOVERSION_CURRENT}.${HDR_SOVERSION_AGE}.${HDR_SOVERSION_REVISION})
2121
set(HDR_SOVERSION ${HDR_SOVERSION_CURRENT})
22+
option(HDR_LOG_REQUIRED "HDR Logging component required" ON)
2223

2324
set(CMAKE_C_STANDARD 99)
2425
set(CMAKE_C_STANDARD_REQUIRED ON)
@@ -41,6 +42,14 @@ if(UNIX)
4142
-D_GNU_SOURCE)
4243
endif()
4344

45+
find_package(ZLIB)
46+
find_package(Threads REQUIRED)
47+
48+
set(HDR_LOG_ENABLED ${ZLIB_FOUND})
49+
if (${HDR_LOG_REQUIRED} AND NOT HDR_LOG_ENABLED)
50+
message(SEND_ERROR "HDR_LOG_REQUIRED=ON and unable to find zlib library")
51+
endif()
52+
4453
add_subdirectory(src)
4554

4655
option(HDR_HISTOGRAM_BUILD_PROGRAMS "Build tests and examples" ON)

examples/CMakeLists.txt

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
add_executable(hdr_decoder
2-
hdr_decoder.c)
3-
target_link_libraries(hdr_decoder
4-
PRIVATE
5-
$<$<BOOL:${WIN32}>:hdr_histogram_static>
6-
$<$<NOT:$<BOOL:${WIN32}>>:hdr_histogram>)
7-
install(
8-
TARGETS hdr_decoder
9-
EXPORT ${PROJECT_NAME}-targets
10-
DESTINATION ${CMAKE_INSTALL_BINDIR})
11-
12-
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
13-
find_package(Threads)
14-
15-
add_executable(hiccup
16-
hiccup.c)
17-
target_link_libraries(hiccup
1+
if (HDR_LOG_ENABLED)
2+
add_executable(hdr_decoder
3+
hdr_decoder.c)
4+
target_link_libraries(hdr_decoder
185
PRIVATE
19-
hdr_histogram
20-
Threads::Threads)
6+
$<$<BOOL:${WIN32}>:hdr_histogram_static>
7+
$<$<NOT:$<BOOL:${WIN32}>>:hdr_histogram>)
218
install(
22-
TARGETS hiccup
9+
TARGETS hdr_decoder
2310
EXPORT ${PROJECT_NAME}-targets
2411
DESTINATION ${CMAKE_INSTALL_BINDIR})
25-
endif()
12+
13+
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
14+
find_package(Threads)
15+
16+
add_executable(hiccup
17+
hiccup.c)
18+
target_link_libraries(hiccup
19+
PRIVATE
20+
hdr_histogram
21+
Threads::Threads)
22+
install(
23+
TARGETS hiccup
24+
EXPORT ${PROJECT_NAME}-targets
25+
DESTINATION ${CMAKE_INSTALL_BINDIR})
26+
endif()
27+
endif()

src/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
find_package(ZLIB REQUIRED)
2-
find_package(Threads REQUIRED)
31

42
include(CheckLibraryExists)
53
check_library_exists(m ceil "" HAVE_LIBM)
64
check_library_exists(rt clock_gettime "" HAVE_LIBRT)
75

6+
if (HDR_LOG_ENABLED)
7+
set(HDR_LOG_IMPLEMENTATION hdr_histogram_log.c)
8+
set(HDR_ZLIB ZLIB::ZLIB)
9+
else()
10+
set(HDR_LOG_IMPLEMENTATION hdr_histogram_log_no_op.c)
11+
set(HDR_ZLIB "")
12+
endif()
13+
814
set(HDR_HISTOGRAM_SOURCES
915
hdr_encoding.c
1016
hdr_histogram.c
11-
hdr_histogram_log.c
17+
${HDR_LOG_IMPLEMENTATION}
1218
hdr_interval_recorder.c
1319
hdr_thread.c
1420
hdr_time.c
@@ -35,7 +41,9 @@ function(hdr_histogram_add_library NAME LIBRARY_TYPE DO_INSTALL)
3541
${HDR_HISTOGRAM_PUBLIC_HEADERS})
3642
target_link_libraries(${NAME}
3743
PRIVATE
38-
ZLIB::ZLIB
44+
# ZLIB::ZLIB
45+
${HDR_ZLIB}
46+
# $<$<BOOL:${ZLIB_FOUND}>ZLIB::ZLIB>
3947
Threads::Threads
4048
$<$<BOOL:${HAVE_LIBM}>:m>
4149
$<$<BOOL:${HAVE_LIBRT}>:rt>

src/hdr_histogram_log_no_op.c

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/**
2+
* hdr_histogram_log.c
3+
* Written by Michael Barker and released to the public domain,
4+
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
5+
*/
6+
7+
#include <stdint.h>
8+
#include <stdio.h>
9+
#include <string.h>
10+
11+
#include "hdr_histogram.h"
12+
#include "hdr_histogram_log.h"
13+
#include "hdr_tests.h"
14+
15+
#define UNUSED(x) (void)(x)
16+
17+
const char* hdr_strerror(int errnum)
18+
{
19+
switch (errnum)
20+
{
21+
case HDR_COMPRESSION_COOKIE_MISMATCH:
22+
return "Compression cookie mismatch";
23+
case HDR_ENCODING_COOKIE_MISMATCH:
24+
return "Encoding cookie mismatch";
25+
case HDR_DEFLATE_INIT_FAIL:
26+
return "Deflate initialisation failed";
27+
case HDR_DEFLATE_FAIL:
28+
return "Deflate failed";
29+
case HDR_INFLATE_INIT_FAIL:
30+
return "Inflate initialisation failed";
31+
case HDR_INFLATE_FAIL:
32+
return "Inflate failed";
33+
case HDR_LOG_INVALID_VERSION:
34+
return "Log - invalid version in log header";
35+
case HDR_TRAILING_ZEROS_INVALID:
36+
return "Invalid number of trailing zeros";
37+
case HDR_VALUE_TRUNCATED:
38+
return "Truncated value found when decoding";
39+
case HDR_ENCODED_INPUT_TOO_LONG:
40+
return "The encoded input exceeds the size of the histogram";
41+
default:
42+
return strerror(errnum);
43+
}
44+
}
45+
46+
int hdr_encode_compressed(
47+
struct hdr_histogram* h,
48+
uint8_t** compressed_histogram,
49+
size_t* compressed_len)
50+
{
51+
UNUSED(h);
52+
UNUSED(compressed_histogram);
53+
UNUSED(compressed_len);
54+
55+
return -1;
56+
}
57+
58+
int hdr_decode_compressed(
59+
uint8_t* buffer, size_t length, struct hdr_histogram** histogram)
60+
{
61+
UNUSED(buffer);
62+
UNUSED(length);
63+
UNUSED(histogram);
64+
65+
return -1;
66+
}
67+
68+
int hdr_log_writer_init(struct hdr_log_writer* writer)
69+
{
70+
UNUSED(writer);
71+
72+
return -1;
73+
}
74+
75+
int hdr_log_write_header(
76+
struct hdr_log_writer* writer, FILE* file,
77+
const char* user_prefix, hdr_timespec* timestamp)
78+
{
79+
UNUSED(writer);
80+
UNUSED(file);
81+
UNUSED(user_prefix);
82+
UNUSED(timestamp);
83+
84+
return -1;
85+
}
86+
87+
int hdr_log_write(
88+
struct hdr_log_writer* writer,
89+
FILE* file,
90+
const hdr_timespec* start_timestamp,
91+
const hdr_timespec* end_timestamp,
92+
struct hdr_histogram* histogram)
93+
{
94+
UNUSED(writer);
95+
UNUSED(file);
96+
UNUSED(start_timestamp);
97+
UNUSED(end_timestamp);
98+
UNUSED(histogram);
99+
100+
return -1;
101+
}
102+
103+
int hdr_log_write_entry(
104+
struct hdr_log_writer* writer,
105+
FILE* file,
106+
struct hdr_log_entry* entry,
107+
struct hdr_histogram* histogram)
108+
{
109+
UNUSED(writer);
110+
UNUSED(file);
111+
UNUSED(entry);
112+
UNUSED(histogram);
113+
114+
return -1;
115+
}
116+
117+
int hdr_log_reader_init(struct hdr_log_reader* reader)
118+
{
119+
UNUSED(reader);
120+
121+
return -1;
122+
}
123+
124+
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file)
125+
{
126+
UNUSED(reader);
127+
UNUSED(file);
128+
129+
return -1;
130+
}
131+
132+
int hdr_log_read(
133+
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
134+
hdr_timespec* timestamp, hdr_timespec* interval)
135+
{
136+
UNUSED(reader);
137+
UNUSED(file);
138+
UNUSED(histogram);
139+
UNUSED(timestamp);
140+
UNUSED(interval);
141+
142+
return -1;
143+
}
144+
145+
int hdr_log_read_entry(
146+
struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram)
147+
{
148+
UNUSED(reader);
149+
UNUSED(file);
150+
UNUSED(entry);
151+
UNUSED(histogram);
152+
153+
return -1;
154+
}
155+
156+
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram)
157+
{
158+
UNUSED(histogram);
159+
UNUSED(encoded_histogram);
160+
161+
return -1;
162+
}
163+
164+
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len)
165+
{
166+
UNUSED(histogram);
167+
UNUSED(base64_histogram);
168+
UNUSED(base64_len);
169+
170+
return -1;
171+
}

test/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ endfunction()
6161

6262
hdr_histogram_add_test(hdr_histogram_test)
6363
hdr_histogram_add_test(hdr_histogram_atomic_test)
64-
hdr_histogram_add_test(hdr_histogram_log_test)
64+
if (HDR_LOG_ENABLED)
65+
hdr_histogram_add_test(hdr_histogram_log_test)
66+
endif()
6567
hdr_histogram_add_test(hdr_atomic_test)
6668
if(UNIX)
6769
hdr_histogram_add_test(hdr_histogram_atomic_concurrency_test)

0 commit comments

Comments
 (0)