Skip to content

Commit

Permalink
Merge branch 'tristan957-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Feb 28, 2022
2 parents 706a9e0 + 3b43ad8 commit 1bc7ab0
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 75 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ 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(include)
add_subdirectory(src)

option(HDR_HISTOGRAM_BUILD_PROGRAMS "Build tests and examples" ON)
Expand All @@ -70,10 +71,12 @@ configure_file(
config.cmake.in
${PROJECT_NAME}-config.cmake
@ONLY)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::)
if(HDR_HISTOGRAM_INSTALL_SHARED OR HDR_HISTOGRAM_INSTALL_STATIC)
install(
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
NAMESPACE ${PROJECT_NAME}::)
endif()
install(
FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
Expand Down
8 changes: 4 additions & 4 deletions examples/hdr_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <time.h>
#include <errno.h>
#include <string.h>
#include <hdr_histogram.h>
#include <hdr_histogram_log.h>

#include <hdr/hdr_histogram.h>
#include <hdr/hdr_histogram_log.h>

#if defined(_MSC_VER)
#pragma warning(push)
Expand Down Expand Up @@ -71,7 +71,7 @@ int main(int argc, char** argv)
{
fprintf(stderr, "Failed to print histogram: %s\n", hdr_strerror(rc));
return -1;
}
}
}

return 0;
Expand Down
14 changes: 7 additions & 7 deletions examples/hiccup.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include <stdlib.h>
#include <unistd.h>

#include <hdr_histogram.h>
#include <hdr_histogram_log.h>
#include <hdr_interval_recorder.h>
#include <hdr_time.h>
#include <hdr/hdr_histogram.h>
#include <hdr/hdr_histogram_log.h>
#include <hdr/hdr_interval_recorder.h>
#include <hdr/hdr_time.h>

static int64_t diff(struct timespec t0, struct timespec t1)
{
Expand All @@ -36,7 +36,7 @@ static void* record_hiccups(void* thread_context)
struct pollfd fd;
struct timespec t0;
struct timespec t1;
struct itimerspec timeout;
struct itimerspec timeout;
struct hdr_interval_recorder* r = thread_context;

memset(&fd, 0, sizeof(struct pollfd));
Expand Down Expand Up @@ -140,7 +140,7 @@ int main(int argc, char** argv)
if (!output)
{
fprintf(
stderr, "Failed to open/create file: %s, %s",
stderr, "Failed to open/create file: %s, %s",
config.filename, strerror(errno));

return -1;
Expand All @@ -167,7 +167,7 @@ int main(int argc, char** argv)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true)
{
{
sleep(config.interval);

inactive = hdr_interval_recorder_sample_and_recycle(&recorder, inactive);
Expand Down
11 changes: 11 additions & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(HDR_HISTOGRAM_PUBLIC_HEADERS
hdr/hdr_histogram.h
hdr/hdr_histogram_log.h
hdr/hdr_interval_recorder.h
hdr/hdr_thread.h
hdr/hdr_time.h
hdr/hdr_writer_reader_phaser.h)

install(
FILES ${HDR_HISTOGRAM_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hdr)
14 changes: 7 additions & 7 deletions src/hdr_histogram.h → include/hdr/hdr_histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,27 @@ bool hdr_record_values_atomic(struct hdr_histogram* h, int64_t value, int64_t co
* Record a value in the histogram and backfill based on an expected interval.
*
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at contruction time. This is specifically used
* than the significant_figure specified at construction time. This is specifically used
* for recording latency. If the value is larger than the expected_interval then the
* latency recording system has experienced co-ordinated omission. This method fills in the
* values that would have occured had the client providing the load not been blocked.
* values that would have occurred had the client providing the load not been blocked.
* @param h "This" pointer
* @param value Value to add to the histogram
* @param expected_interval The delay between recording values.
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_value(struct hdr_histogram* h, int64_t value, int64_t expexcted_interval);
bool hdr_record_corrected_value(struct hdr_histogram* h, int64_t value, int64_t expected_interval);

/**
* Record a value in the histogram and backfill based on an expected interval.
*
* Records a value in the histogram, will round this value of to a precision at or better
* than the significant_figure specified at contruction time. This is specifically used
* than the significant_figure specified at construction time. This is specifically used
* for recording latency. If the value is larger than the expected_interval then the
* latency recording system has experienced co-ordinated omission. This method fills in the
* values that would have occured had the client providing the load not been blocked.
* values that would have occurred had the client providing the load not been blocked.
*
* Will record this value atomically, however the whole structure may appear inconsistent
* when read concurrently with this update. Do NOT mix calls to this method with calls
Expand All @@ -191,7 +191,7 @@ bool hdr_record_corrected_value(struct hdr_histogram* h, int64_t value, int64_t
* @return false if the value is larger than the highest_trackable_value and can't be recorded,
* true otherwise.
*/
bool hdr_record_corrected_value_atomic(struct hdr_histogram* h, int64_t value, int64_t expexcted_interval);
bool hdr_record_corrected_value_atomic(struct hdr_histogram* h, int64_t value, int64_t expected_interval);

/**
* Record a value in the histogram 'count' times. Applies the same correcting logic
Expand Down Expand Up @@ -504,7 +504,7 @@ int64_t hdr_next_non_equivalent_value(const struct hdr_histogram* h, int64_t val
int64_t hdr_median_equivalent_value(const struct hdr_histogram* h, int64_t value);

/**
* Used to reset counters after importing data manuallying into the histogram, used by the logging code
* Used to reset counters after importing data manually into the histogram, used by the logging code
* and other custom serialisation tools.
*/
void hdr_reset_internal_counters(struct hdr_histogram* h);
Expand Down
4 changes: 2 additions & 2 deletions src/hdr_histogram_log.h → include/hdr/hdr_histogram_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <stdbool.h>
#include <stdio.h>

#include "hdr_time.h"
#include "hdr_histogram.h"
#include <hdr/hdr_time.h>
#include <hdr/hdr_histogram.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
#ifndef HDR_INTERVAL_RECORDER_H
#define HDR_INTERVAL_RECORDER_H 1

#include "hdr_writer_reader_phaser.h"
#include "hdr_histogram.h"
#include <hdr/hdr_writer_reader_phaser.h>
#include <hdr/hdr_histogram.h>

HDR_ALIGN_PREFIX(8)
struct hdr_interval_recorder
{
struct hdr_histogram* active;
struct hdr_histogram* inactive;
struct hdr_writer_reader_phaser phaser;
}
}
HDR_ALIGN_SUFFIX(8);

#ifdef __cplusplus
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 5 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ set(HDR_HISTOGRAM_PRIVATE_HEADERS
hdr_tests.h
hdr_malloc.h)

set(HDR_HISTOGRAM_PUBLIC_HEADERS
hdr_histogram.h
hdr_histogram_log.h
hdr_interval_recorder.h
hdr_thread.h
hdr_time.h
hdr_writer_reader_phaser.h)

function(hdr_histogram_add_library NAME LIBRARY_TYPE DO_INSTALL)
add_library(${NAME} ${LIBRARY_TYPE}
${HDR_HISTOGRAM_SOURCES}
${HDR_HISTOGRAM_PRIVATE_HEADERS}
${HDR_HISTOGRAM_PUBLIC_HEADERS})

target_link_libraries(${NAME}
PRIVATE
# ZLIB::ZLIB
Expand All @@ -49,10 +42,11 @@ function(hdr_histogram_add_library NAME LIBRARY_TYPE DO_INSTALL)
$<$<BOOL:${HAVE_LIBM}>:m>
$<$<BOOL:${HAVE_LIBRT}>:rt>
$<$<BOOL:${WIN32}>:ws2_32>)
target_include_directories(${NAME}
target_include_directories(
${NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hdr>)
if(DO_INSTALL)
install(
TARGETS ${NAME}
Expand All @@ -77,7 +71,3 @@ option(HDR_HISTOGRAM_INSTALL_STATIC "Install static library" ON)
if(HDR_HISTOGRAM_BUILD_STATIC)
hdr_histogram_add_library(hdr_histogram_static STATIC ${HDR_HISTOGRAM_INSTALL_STATIC})
endif()

install(
FILES ${HDR_HISTOGRAM_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hdr)
29 changes: 22 additions & 7 deletions src/hdr_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <errno.h>
#include <inttypes.h>

#include "hdr_histogram.h"
#include <hdr/hdr_histogram.h>
#include "hdr_tests.h"
#include "hdr_atomic.h"

Expand Down Expand Up @@ -222,13 +222,24 @@ int64_t hdr_size_of_equivalent_value_range(const struct hdr_histogram* h, int64_
return INT64_C(1) << (h->unit_magnitude + adjusted_bucket);
}

static int64_t hdr_size_of_equivalent_value_range_given_bucket_indices(const struct hdr_histogram* h, int64_t value, int32_t bucket_index, int32_t sub_bucket_index)
{
const int32_t adjusted_bucket = (sub_bucket_index >= h->sub_bucket_count) ? (bucket_index + 1) : bucket_index;
return INT64_C(1) << (h->unit_magnitude + adjusted_bucket);
}

static int64_t lowest_equivalent_value(const struct hdr_histogram* h, int64_t value)
{
int32_t bucket_index = get_bucket_index(h, value);
int32_t sub_bucket_index = get_sub_bucket_index(value, bucket_index, h->unit_magnitude);
return value_from_index(bucket_index, sub_bucket_index, h->unit_magnitude);
}

static int64_t lowest_equivalent_value_given_bucket_indices(const struct hdr_histogram* h, int64_t value, int32_t bucket_index, int32_t sub_bucket_index)
{
return value_from_index(bucket_index, sub_bucket_index, h->unit_magnitude);
}

int64_t hdr_next_non_equivalent_value(const struct hdr_histogram *h, int64_t value)
{
return lowest_equivalent_value(h, value) + hdr_size_of_equivalent_value_range(h, value);
Expand Down Expand Up @@ -699,7 +710,7 @@ int hdr_value_at_percentiles(const struct hdr_histogram *h, const double *percen
while (hdr_iter_next(&iter) && at_pos < length)
{
total += iter.count;
while (total >= values[at_pos] && at_pos < length)
while (at_pos < length && total >= values[at_pos])
{
values[at_pos] = highest_equivalent_value(h, iter.value);
at_pos++;
Expand Down Expand Up @@ -797,11 +808,15 @@ static bool move_next(struct hdr_iter* iter)

iter->count = counts_get_normalised(iter->h, iter->counts_index);
iter->cumulative_count += iter->count;

iter->value = hdr_value_at_index(iter->h, iter->counts_index);
iter->highest_equivalent_value = highest_equivalent_value(iter->h, iter->value);
iter->lowest_equivalent_value = lowest_equivalent_value(iter->h, iter->value);
iter->median_equivalent_value = hdr_median_equivalent_value(iter->h, iter->value);
const int64_t value = hdr_value_at_index(iter->h, iter->counts_index);
const int32_t bucket_index = get_bucket_index(iter->h, value);
const int32_t sub_bucket_index = get_sub_bucket_index(value, bucket_index, iter->h->unit_magnitude);
const int64_t leq = lowest_equivalent_value_given_bucket_indices(iter->h, value, bucket_index, sub_bucket_index);
const int64_t size_of_equivalent_value_range = hdr_size_of_equivalent_value_range_given_bucket_indices(iter->h, value, bucket_index, sub_bucket_index);
iter->lowest_equivalent_value = leq;
iter->value = value;
iter->highest_equivalent_value = leq + size_of_equivalent_value_range - 1;
iter->median_equivalent_value = leq + (size_of_equivalent_value_range >> 1);

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hdr_histogram_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include <errno.h>
#include <time.h>

#include <hdr/hdr_histogram.h>
#include <hdr/hdr_histogram_log.h>
#include "hdr_encoding.h"
#include "hdr_histogram.h"
#include "hdr_histogram_log.h"
#include "hdr_tests.h"

#if defined(_MSC_VER)
Expand Down Expand Up @@ -120,7 +120,7 @@ union uint64_dbl_cvt
static double int64_bits_to_double(int64_t i)
{
union uint64_dbl_cvt x;

x.l = (uint64_t) i;
return x.d;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hdr_interval_recorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/

#include <hdr/hdr_interval_recorder.h>
#include "hdr_atomic.h"
#include "hdr_interval_recorder.h"

#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr_malloc.h"
Expand Down
2 changes: 1 addition & 1 deletion src/hdr_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/* These are functions used in tests and are not intended for normal usage. */

#include "hdr_histogram.h"
#include <hdr/hdr_histogram.h>

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/hdr_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include <stdlib.h>
#include "hdr_thread.h"
#include <hdr/hdr_thread.h>

#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr_malloc.h"
Expand Down
5 changes: 1 addition & 4 deletions src/hdr_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/

#include "hdr_time.h"
#include <hdr/hdr_time.h>

#if defined(_WIN32) || defined(_WIN64)

Expand Down Expand Up @@ -93,6 +93,3 @@ void hdr_timespec_from_double(hdr_timespec* t, double value)
t->tv_sec = seconds;
t->tv_nsec = milliseconds * 1000000;
}



7 changes: 3 additions & 4 deletions src/hdr_writer_reader_phaser.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
#include <stdbool.h>
#include <errno.h>

#include <hdr/hdr_thread.h>
#include <hdr/hdr_writer_reader_phaser.h>
#include "hdr_atomic.h"
#include "hdr_thread.h"

#include "hdr_writer_reader_phaser.h"

#ifndef HDR_MALLOC_INCLUDE
#define HDR_MALLOC_INCLUDE "hdr_malloc.h"
Expand Down Expand Up @@ -77,7 +76,7 @@ int64_t hdr_phaser_writer_enter(struct hdr_writer_reader_phaser* p)
void hdr_phaser_writer_exit(
struct hdr_writer_reader_phaser* p, int64_t critical_value_at_enter)
{
int64_t* end_epoch =
int64_t* end_epoch =
(critical_value_at_enter < 0) ? &p->odd_end_epoch : &p->even_end_epoch;
hdr_atomic_add_fetch_64(end_epoch, 1);
}
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function(hdr_histogram_add_test_executable NAME)
target_link_libraries(${NAME}
PRIVATE
hdr_histogram_static)
target_include_directories(${NAME}
PRIVATE
${PROJECT_SOURCE_DIR}/src)
install(
TARGETS ${NAME}
DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down
Loading

0 comments on commit 1bc7ab0

Please sign in to comment.