1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/**
* hdr_decoder.c
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <hdr_histogram.h>
#include <hdr_histogram_log.h>
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;
struct timespec timestamp;
struct 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;
}
|