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

added Matlab struct output

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@271 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2015-01-20 13:52:32 +00:00
parent d530ba9b2b
commit 76d887e7b4
4 changed files with 54 additions and 21 deletions
server

View file

@ -7,6 +7,8 @@
#ifndef _HIST_H_
#define _HIST_H_
#include <stdio.h>
#define HIST_HEIGHT 50
#define HIST_SEQ 17
@ -68,7 +70,10 @@ void hist_print(struct hist *h);
/** Print ASCII style plot of histogram */
void hist_plot(struct hist *h);
/** Dump histogram data in Matlab format to stdout */
void hist_dump(struct hist *h);
/** Dump histogram data in Matlab format to buf */
void hist_dump(struct hist *h, char *buf, int len);
/** Prints Matlab struct containing all infos to file. */
void hist_matlab(struct hist *h, FILE *f);
#endif /* _HIST_H_ */

View file

@ -9,6 +9,7 @@
#include <limits.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include "utils.h"
#include "hist.h"
@ -102,7 +103,11 @@ void hist_print(struct hist *h)
info("Standard derivation: %f", hist_stddev(h));
hist_plot(h);
hist_dump(h);
char buf[h->length * 8];
hist_dump(h, buf, sizeof(buf));
info("hist = %s", buf);
}
void hist_plot(struct hist *h)
@ -122,27 +127,43 @@ void hist_plot(struct hist *h)
memset(buf, '#', HIST_HEIGHT);
/* Print plot */
info("%5s | %5s | %s", "Value", "Occur", "Histogram Plot:");
info("%9s | %5s | %s", "Value", "Occur", "Histogram Plot:");
for (int i = 0; i < h->length; i++) {
int bar = HIST_HEIGHT * ((double) h->data[i] / max);
if (h->data[i] == min) info("%5.2e | " GRN("%5u") " | %.*s", VAL(h, i), h->data[i], bar, buf);
else if (h->data[i] == max) info("%5.2e | " RED("%5u") " | %.*s", VAL(h, i), h->data[i], bar, buf);
else info("%5.2e | " "%5u" " | %.*s", VAL(h, i), h->data[i], bar, buf);
if (h->data[i] == min) info("%+5.2e | " GRN("%5u") " | %.*s", VAL(h, i), h->data[i], bar, buf);
else if (h->data[i] == max) info("%+5.2e | " RED("%5u") " | %.*s", VAL(h, i), h->data[i], bar, buf);
else info("%+5.2e | " "%5u" " | %.*s", VAL(h, i), h->data[i], bar, buf);
}
}
void hist_dump(struct hist *h)
void hist_dump(struct hist *h, char *buf, int len)
{
char tok[8];
char buf[h->length * sizeof(tok)];
memset(buf, 0, sizeof(buf));
memset(buf, 0, len);
strncat(buf, "[ ", len);
/* Print in Matlab vector format */
for (int i = 0; i < h->length; i++) {
snprintf(tok, sizeof(tok), "%u ", h->data[i]);
strncat(buf, tok, sizeof(buf) - strlen(buf));
strncat(buf, tok, len - strlen(buf));
}
info("hist = [ %s]", buf);
strncat(buf, "]", len - strlen(buf));
}
void hist_matlab(struct hist *h, FILE *f)
{
char buf[h->length * 8];
hist_dump(h, buf, sizeof(buf));
fprintf(f, "%lu = struct( ", time(NULL));
fprintf(f, "'min', %f, 'max', %f, ", h->low, h->high);
fprintf(f, "'ok', %u, too_high', %u, 'too_low', %u, ", h->total, h->higher, h->lower);
fprintf(f, "'highest', %f, 'lowest', %f, ", h->highest, h->lowest);
fprintf(f, "'mean', %f, ", hist_mean(h));
fprintf(f, "'var', %f, ", hist_var(h));
fprintf(f, "'stddev', %f, ", hist_stddev(h));
fprintf(f, "'hist', %s ", buf);
fprintf(f, "),\n");
}

View file

@ -58,7 +58,8 @@ struct node_vtable const * node_lookup_vtable(const char *str)
int node_start(struct node *n)
{
int ret;
if (!n->refcnt)
return -1;
char str[256];
node_print(n, str, sizeof(str));
@ -66,13 +67,8 @@ int node_start(struct node *n)
debug(1, "Starting node '%s' of type '%s' (%s)", n->name, n->vt->name, str);
{ INDENT
if (!n->refcnt)
warn("Node '%s' is not used by an active path", n->name);
ret = n->vt->open(n);
return n->vt->open(n);
}
return ret;
}
int node_start_defer(struct node *n)

View file

@ -13,6 +13,9 @@
#include <limits.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#include "cfg.h"
@ -189,5 +192,13 @@ void test_rtt() {
hist_print(&histogram);
struct stat st;
if (!fstat(fd, &st)) {
FILE *f = fdopen(fd, "w");
hist_matlab(&histogram, f);
}
else
error("Invalid file descriptor: %u", fd);
hist_free(&histogram);
}