int main(int argc, char** argv) { int rc = 0; FILE* f; if (argc == 1) { f = stdin; } else { f = fopen(argv[1], "r"); } if (!f) { fprintf(stderr, "Failed to open file(%s):%s\n", argv[1], strerror(errno)); return -1; } struct hdr_log_reader reader; if (hdr_log_reader_init(&reader)) { fprintf(stderr, "Failed to init reader\n"); return -1; } struct hdr_histogram* h = NULL; hdr_timespec timestamp; hdr_timespec interval; rc = hdr_log_read_header(&reader, f); if(rc) { fprintf(stderr, "Failed to read header: %s\n", hdr_strerror(rc)); return -1; } while (true) { rc = hdr_log_read(&reader, f, &h, ×tamp, &interval); if (0 == rc) { hdr_percentiles_print(h, stdout, 5, 1.0, CLASSIC); } else if (EOF == rc) { break; } else { fprintf(stderr, "Failed to print histogram: %s\n", hdr_strerror(rc)); return -1; } } return 0; }
static char* test_encode_and_decode_compressed() { load_histograms(); size_t raw_histogram_size = hdr_get_memory_size(raw_histogram); uint8_t* buffer = (uint8_t*) malloc(hdr_get_memory_size(raw_histogram)); size_t encode_result = hdr_encode_compressed(raw_histogram, buffer, raw_histogram_size); mu_assert("Did not encode", encode_result == 0); int32_t compressed_length = hdr_get_compressed_length(buffer); struct hdr_histogram* loaded_histogram = NULL; int decode_result = hdr_decode_compressed(buffer, compressed_length, &loaded_histogram); if (decode_result != 0) { printf("%s\n", hdr_strerror(decode_result)); } mu_assert("Did not decode", decode_result == 0); mu_assert("Loaded histogram is null", loaded_histogram != NULL); int compare_result = memcmp(raw_histogram, loaded_histogram, raw_histogram_size); mu_assert("Comparison did not match", compare_result == 0); return 0; }
static bool validate_return_code(int rc) { if (rc == 0) { return true; } printf("%s\n", hdr_strerror(rc)); return false; }