From 5a6a44e484e8c7a8becb4afe3402de07feeb8176 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 26 Jan 2021 15:50:45 +0100 Subject: [PATCH] Write lgogs --- src/measure.c | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/src/measure.c b/src/measure.c index 6b5d0a1..49b86f9 100644 --- a/src/measure.c +++ b/src/measure.c @@ -165,9 +165,20 @@ void measure_param_print(struct measure_params* mp) { } void measure_summary(struct measure_params* mp, struct measure_state* ms) { - char uuidstr[128]; + char uuidstr[37] = {0}; uuid_unparse (ms->uuid, uuidstr); - fprintf(stdout, "tag,uuid,metric,value\n"); + + char bin[41] = {0}, txt[41] = {0}; + FILE *fbin, *ftxt; + size_t res; + + sprintf(bin, "%s.bin", uuidstr); + if ((fbin = fopen(bin, "a+")) == NULL) goto measurement_io_error; + if (fwrite(ms->uuid, sizeof(uuid_t), 1, fbin) != 1) goto measurement_io_error; + if (fwrite(&mp->max_measure, sizeof(uint64_t), 1, fbin) != 1) goto measurement_io_error; + if (fwrite(&ms->log, sizeof(uint64_t), mp->max_measure, fbin) != mp->max_measure) goto measurement_io_error; + if (fclose(fbin) != 0) goto measurement_io_error; + printf("saved raw data as %s\n", bin); uint64_t* real_log = ms->log; uint64_t real_log_size = mp->max_measure; @@ -184,7 +195,6 @@ void measure_summary(struct measure_params* mp, struct measure_state* ms) { real_log_size--; } printf("[summary] cutted %lu values in total\n", mp->max_measure - real_log_size); - fprintf(stdout, "%s,%s,count,%lu\n", mp->tag, uuidstr, real_log_size); if (real_log_size == 0) return; // AVERAGE @@ -192,25 +202,33 @@ void measure_summary(struct measure_params* mp, struct measure_state* ms) { for (int i = 0; i < real_log_size; i++) { avg += ((double) real_log[i]) / ((double) real_log_size); } - fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg); // DISTRIBUTION qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t); uint64_t min = real_log[0]; - fprintf(stdout, "%s,%s,min,%lu\n", mp->tag, uuidstr, min); - uint64_t max = real_log[real_log_size-1]; - fprintf(stdout, "%s,%s,max,%lu\n", mp->tag, uuidstr, max); + uint64_t med = real_log[(int)(0.50 * real_log_size) - 1]; + uint64_t q25 = real_log[(int)(0.25 * real_log_size) - 1]; + uint64_t q75 = real_log[(int)(0.75 * real_log_size) - 1]; + uint64_t q99 = real_log[(int)(0.99 * real_log_size) - 1]; - uint64_t med = real_log[(int)(0.50 * real_log_size)]; - fprintf(stdout, "%s,%s,med,%lu\n", mp->tag, uuidstr, med); - uint64_t q25 = real_log[(int)(0.25 * real_log_size)]; - fprintf(stdout, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25); + sprintf(txt, "%s.txt", uuidstr); + if ((ftxt = fopen(txt, "a+")) == NULL) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,count,%lu\n", mp->tag, uuidstr, real_log_size) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,min,%lu\n", mp->tag, uuidstr, min) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,max,%lu\n", mp->tag, uuidstr, max) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,med,%lu\n", mp->tag, uuidstr, med) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75) < 0) goto measurement_io_error; + if (fprintf(ftxt, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99) < 0) goto measurement_io_error; + if (fclose(ftxt) != 0) goto measurement_io_error; - uint64_t q75 = real_log[(int)(0.75 * real_log_size)]; - fprintf(stdout, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75); + printf("saved aggregated data as %s\n", txt); + return; - uint64_t q99 = real_log[(int)(0.99 * real_log_size)]; - fprintf(stdout, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99); +measurement_io_error: + perror("an io error occured while writing measurement results"); + exit(EXIT_FAILURE); }