1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

optimisations in hist_dump_* functions to reduce output to screen

This commit is contained in:
Steffen Vogel 2017-03-12 17:11:23 -03:00
parent 9a9e9c17d4
commit 4ca0785095

View file

@ -173,12 +173,9 @@ char * hist_dump(struct hist *h)
#ifdef WITH_JANSSON
json_t * hist_json(struct hist *h)
{
json_t *b = json_array();
for (int i = 0; i < h->length; i++)
json_array_append(b, json_integer(h->data[i]));
return json_pack("{ s: f, s: f, s: i, s: i, s: i, s: f, s: f, s: f, s: f, s: f, s: o }",
json_t *json_buckets, *json_hist;
json_hist = json_pack("{ s: f, s: f, s: i, s: i, s: i, s: f, s: f, s: f, s: f, s: f }",
"low", h->low,
"high", h->high,
"total", h->total,
@ -188,9 +185,19 @@ json_t * hist_json(struct hist *h)
"lowest", h->lowest,
"mean", hist_mean(h),
"variance", hist_var(h),
"stddev", hist_stddev(h),
"buckets", b
"stddev", hist_stddev(h)
);
if (h->total - h->lower - h->higher > 0) {
json_buckets = json_array();
for (int i = 0; i < h->length; i++)
json_array_append(json_buckets, json_integer(h->data[i]));
json_object_set(json_hist, "buckets", json_buckets);
}
return json_hist;
}
int hist_dump_json(struct hist *h, FILE *f)
@ -207,9 +214,7 @@ int hist_dump_json(struct hist *h, FILE *f)
int hist_dump_matlab(struct hist *h, FILE *f)
{
char *buf = hist_dump(h);
fprintf(f, "%lu = struct( ", time(NULL));
fprintf(f, "struct(");
fprintf(f, "'low', %f, ", h->low);
fprintf(f, "'high', %f, ", h->high);
fprintf(f, "'total', %ju, ", h->total);
@ -220,10 +225,16 @@ int hist_dump_matlab(struct hist *h, FILE *f)
fprintf(f, "'mean', %f, ", hist_mean(h));
fprintf(f, "'variance', %f, ", hist_var(h));
fprintf(f, "'stddev', %f, ", hist_stddev(h));
fprintf(f, "'buckets', %s ", buf);
fprintf(f, "),\n");
free(buf);
if (h->total - h->lower - h->higher > 0) {
char *buf = hist_dump(h);
fprintf(f, "'buckets', %s", buf);
free(buf);
}
else
fprintf(f, "'buckets', zeros(1, %d)", h->length);
fprintf(f, ")");
return 0;
}