diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d86e9c..b8fc18a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project("hdr_histogram") ENABLE_TESTING() if(UNIX) - set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -Wextra -Wshadow -Winit-self") + set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -Wextra -Wshadow -Winit-self -Wmissing-prototypes") set(CMAKE_C_FLAGS_DEBUG "-O0 -g") set(CMAKE_C_FLAGS_RELEASE "-O3 -g") endif() diff --git a/examples/hiccup.c b/examples/hiccup.c index 4e4d247..c606c9c 100644 --- a/examples/hiccup.c +++ b/examples/hiccup.c @@ -23,7 +23,7 @@ #include #include -int64_t diff(struct timespec t0, struct timespec t1) +static int64_t diff(struct timespec t0, struct timespec t1) { int64_t delta_us = 0; delta_us = (t1.tv_sec - t0.tv_sec) * 1000000; @@ -32,7 +32,7 @@ int64_t diff(struct timespec t0, struct timespec t1) return delta_us; } -void update_histogram(void* data, void* arg) +static void update_histogram(void* data, void* arg) { struct hdr_histogram* h = data; int64_t* values = arg; @@ -40,7 +40,7 @@ void update_histogram(void* data, void* arg) hdr_record_value(h, values[0]); } -void* record_hiccups(void* thread_context) +static void* record_hiccups(void* thread_context) { struct pollfd fd; struct timespec t0; @@ -90,7 +90,7 @@ const char* USAGE = " interval: Time in seconds between samples (default 1).\n" " filename: Name of the file to log to (default stdout).\n"; -int handle_opts(int argc, char** argv, struct config_t* config) +static int handle_opts(int argc, char** argv, struct config_t* config) { int c; int interval = 1; @@ -205,4 +205,4 @@ int main(int argc, char** argv) #pragma clang diagnostic pop pthread_exit(NULL); -} \ No newline at end of file +} diff --git a/src/hdr_encoding.c b/src/hdr_encoding.c index 5d8e16d..7291290 100644 --- a/src/hdr_encoding.c +++ b/src/hdr_encoding.c @@ -7,6 +7,7 @@ #include #include "hdr_encoding.h" +#include "hdr_tests.h" int zig_zag_encode_i64(uint8_t* buffer, int64_t signed_value) { @@ -207,7 +208,7 @@ size_t hdr_base64_decoded_len(size_t encoded_size) return (encoded_size / 4) * 3; } -void hdr_base64_encode_block_pad(const uint8_t* input, char* output, size_t pad) +static void hdr_base64_encode_block_pad(const uint8_t* input, char* output, size_t pad) { uint32_t _24_bit_value = 0; diff --git a/src/hdr_histogram.c b/src/hdr_histogram.c index d1e8bb5..6b67634 100644 --- a/src/hdr_histogram.c +++ b/src/hdr_histogram.c @@ -15,6 +15,7 @@ #include #include "hdr_histogram.h" +#include "hdr_tests.h" // ###### ####### ## ## ## ## ######## ###### // ## ## ## ## ## ## ### ## ## ## ## @@ -220,7 +221,7 @@ void hdr_reset_internal_counters(struct hdr_histogram* h) h->total_count = observed_total_count; } -int32_t buckets_needed_to_cover_value(int64_t value, int32_t sub_bucket_count, int32_t unit_magnitude) +static int32_t buckets_needed_to_cover_value(int64_t value, int32_t sub_bucket_count, int32_t unit_magnitude) { int64_t smallest_untrackable_value = ((int64_t) sub_bucket_count) << unit_magnitude; int32_t buckets_needed = 1; @@ -686,7 +687,7 @@ bool hdr_iter_next(struct hdr_iter* iter) // ## ## ## ## ## ## ## ## ### ## ## ## ## ## ## // ## ######## ## ## ###### ######## ## ## ## #### ######## ######## ###### -bool _percentile_iter_next(struct hdr_iter* iter) +static bool _percentile_iter_next(struct hdr_iter* iter) { struct hdr_iter_percentiles* percentiles = &iter->specifics.percentiles; @@ -772,7 +773,7 @@ static void format_line_string(char* str, size_t len, int significant_figures, f // ## ## ######## ###### ####### ## ## ######## ######## ######## -bool _recorded_iter_next(struct hdr_iter* iter) +static bool _recorded_iter_next(struct hdr_iter* iter) { while (_basic_iter_next(iter)) { @@ -806,7 +807,7 @@ void hdr_iter_recorded_init(struct hdr_iter* iter, const struct hdr_histogram* h // ######## #### ## ## ######## ## ## ## ## -bool _iter_linear_next(struct hdr_iter* iter) +static bool _iter_linear_next(struct hdr_iter* iter) { struct hdr_iter_linear* linear = &iter->specifics.linear; @@ -862,7 +863,7 @@ void hdr_iter_linear_init(struct hdr_iter* iter, const struct hdr_histogram* h, // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## // ######## ####### ###### ## ## ## ## #### ## ## ## ## ## #### ###### -bool _log_iter_next(struct hdr_iter *iter) +static bool _log_iter_next(struct hdr_iter *iter) { struct hdr_iter_log* logarithmic = &iter->specifics.log; diff --git a/src/hdr_histogram_log.c b/src/hdr_histogram_log.c index e0d77a7..314fd22 100644 --- a/src/hdr_histogram_log.c +++ b/src/hdr_histogram_log.c @@ -20,6 +20,7 @@ #include "hdr_encoding.h" #include "hdr_histogram.h" #include "hdr_histogram_log.h" +#include "hdr_tests.h" #ifdef __APPLE__ @@ -54,7 +55,7 @@ int32_t counts_index_for(const struct hdr_histogram* h, int64_t value); } \ while (0) -int realloc_buffer( +static int realloc_buffer( void** buffer, size_t nmemb, ssize_t size) { size_t len = nmemb * size; @@ -86,7 +87,7 @@ int realloc_buffer( // ## ## ## ## ## ## ## ### ## ## ## ## // ###### ## ## ## #### ## ## ###### ###### -ssize_t null_trailing_whitespace(char* s, ssize_t len) +static ssize_t null_trailing_whitespace(char* s, ssize_t len) { ssize_t i = len; while (--i != -1) @@ -121,12 +122,12 @@ static const int32_t V1_COMPRESSION_COOKIE = 0x1c849302; static const int32_t V2_ENCODING_COOKIE = 0x1c849303; static const int32_t V2_COMPRESSION_COOKIE = 0x1c849304; -int32_t get_cookie_base(int32_t cookie) +static int32_t get_cookie_base(int32_t cookie) { return (cookie & ~0xf0); } -int32_t word_size_from_cookie(int32_t cookie) +static int32_t word_size_from_cookie(int32_t cookie) { return (cookie & 0xf0) >> 4; } diff --git a/src/hdr_writer_reader_phaser.c b/src/hdr_writer_reader_phaser.c index e926a1a..ea1b724 100644 --- a/src/hdr_writer_reader_phaser.c +++ b/src/hdr_writer_reader_phaser.c @@ -14,17 +14,17 @@ #include "hdr_writer_reader_phaser.h" -int64_t _hdr_phaser_get_epoch(int64_t* field) +static int64_t _hdr_phaser_get_epoch(int64_t* field) { return __atomic_load_n(field, __ATOMIC_SEQ_CST); } -void _hdr_phaser_set_epoch(int64_t* field, int64_t val) +static void _hdr_phaser_set_epoch(int64_t* field, int64_t val) { __atomic_store_n(field, val, __ATOMIC_SEQ_CST); } -int64_t _hdr_phaser_reset_epoch(int64_t* field, int64_t initial_value) +static int64_t _hdr_phaser_reset_epoch(int64_t* field, int64_t initial_value) { return __atomic_exchange_n(field, initial_value, __ATOMIC_SEQ_CST); } diff --git a/test/hdr_histogram_log_test.c b/test/hdr_histogram_log_test.c index 13b331f..79a4040 100644 --- a/test/hdr_histogram_log_test.c +++ b/test/hdr_histogram_log_test.c @@ -818,7 +818,7 @@ static struct mu_result all_tests() mu_ok; } -int hdr_histogram_log_run_tests() +static int hdr_histogram_log_run_tests() { struct mu_result result = all_tests(); diff --git a/test/hdr_histogram_perf.c b/test/hdr_histogram_perf.c index 9fb3ce3..61c5aea 100644 --- a/test/hdr_histogram_perf.c +++ b/test/hdr_histogram_perf.c @@ -13,7 +13,7 @@ #include "hdr_time.h" -struct timespec diff(struct timespec start, struct timespec end) +static struct timespec diff(struct timespec start, struct timespec end) { struct timespec temp; if ((end.tv_nsec-start.tv_nsec) < 0) @@ -29,12 +29,6 @@ struct timespec diff(struct timespec start, struct timespec end) return temp; } -void inc(struct hdr_histogram* h, int32_t index, int64_t value) -{ - h->counts[index] += value; - h->total_count += value; -} - int main() { struct hdr_histogram* histogram; diff --git a/test/hdr_histogram_test.c b/test/hdr_histogram_test.c index ef21349..c1ed2d6 100644 --- a/test/hdr_histogram_test.c +++ b/test/hdr_histogram_test.c @@ -14,12 +14,12 @@ #include "minunit.h" -bool compare_values(double a, double b, double variation) +static bool compare_values(double a, double b, double variation) { return compare_double(a, b, b * variation); } -bool compare_percentile(int64_t a, double b, double variation) +static bool compare_percentile(int64_t a, double b, double variation) { return compare_values((double) a, b, variation); // return fabs(a - b) <= b * variation; @@ -425,7 +425,7 @@ static char* test_scaling_equivalence() return 0; } -char* test_out_of_range_values() +static char* test_out_of_range_values() { struct hdr_histogram *h; hdr_init(1, 1000, 4, &h); @@ -455,7 +455,7 @@ static struct mu_result all_tests() mu_ok; } -int hdr_histogram_run_tests() +static int hdr_histogram_run_tests() { struct mu_result result = all_tests(); diff --git a/test/minunit.h b/test/minunit.h index 6c4c847..fe289dc 100644 --- a/test/minunit.h +++ b/test/minunit.h @@ -44,7 +44,7 @@ struct mu_result extern int tests_run; -bool compare_double(double a, double b, double delta) +static bool compare_double(double a, double b, double delta) { if (fabs(a - b) < delta) { @@ -66,4 +66,4 @@ static bool compare_int64(int64_t a, int64_t b) return false; } -#endif \ No newline at end of file +#endif