Write lgogs

This commit is contained in:
Quentin 2021-01-26 15:50:45 +01:00
parent 4b48b69d92
commit 5a6a44e484

View file

@ -165,9 +165,20 @@ void measure_param_print(struct measure_params* mp) {
} }
void measure_summary(struct measure_params* mp, struct measure_state* ms) { void measure_summary(struct measure_params* mp, struct measure_state* ms) {
char uuidstr[128]; char uuidstr[37] = {0};
uuid_unparse (ms->uuid, uuidstr); 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 = ms->log;
uint64_t real_log_size = mp->max_measure; 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--; real_log_size--;
} }
printf("[summary] cutted %lu values in total\n", mp->max_measure - 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; if (real_log_size == 0) return;
// AVERAGE // 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++) { for (int i = 0; i < real_log_size; i++) {
avg += ((double) real_log[i]) / ((double) real_log_size); avg += ((double) real_log[i]) / ((double) real_log_size);
} }
fprintf(stdout, "%s,%s,avg,%f\n", mp->tag, uuidstr, avg);
// DISTRIBUTION // DISTRIBUTION
qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t); qsort (real_log, real_log_size, sizeof(uint64_t), cmpuint64t);
uint64_t min = real_log[0]; 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]; 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)]; sprintf(txt, "%s.txt", uuidstr);
fprintf(stdout, "%s,%s,q25,%lu\n", mp->tag, uuidstr, q25); 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)]; printf("saved aggregated data as %s\n", txt);
fprintf(stdout, "%s,%s,q75,%lu\n", mp->tag, uuidstr, q75); return;
uint64_t q99 = real_log[(int)(0.99 * real_log_size)]; measurement_io_error:
fprintf(stdout, "%s,%s,q99,%lu\n", mp->tag, uuidstr, q99); perror("an io error occured while writing measurement results");
exit(EXIT_FAILURE);
} }