diff --git a/server/include/config.h b/server/include/config.h index e1f4f90a8..4814e8b74 100644 --- a/server/include/config.h +++ b/server/include/config.h @@ -20,4 +20,7 @@ /** Socket priority */ #define SOCKET_PRIO 7 +/* Some parameters for histogram statistics */ +#define HIST_SEQ 33 + #endif /* _CONFIG_H_ */ diff --git a/server/include/path.h b/server/include/path.h index d0cc7619e..9eb8216b7 100644 --- a/server/include/path.h +++ b/server/include/path.h @@ -49,6 +49,8 @@ struct path unsigned int skipped; /** Counter for dropped messages due to reordering */ unsigned int dropped; + /** Counter for received messages according to their sequence no displacement */ + unsigned int histogram[HIST_SEQ]; /** The thread id for this path */ pthread_t recv_tid; diff --git a/server/include/utils.h b/server/include/utils.h index 7d21c483a..8225363f4 100644 --- a/server/include/utils.h +++ b/server/include/utils.h @@ -70,6 +70,9 @@ double timespec_delta(struct timespec *start, struct timespec *end); /** Get period as timespec from rate */ struct timespec timespec_rate(double rate); +/** Dump histogram data in Matlab format */ +void hist_dump(unsigned *hist, int length); + /** Append an element to a single linked list */ #define list_add(list, elm) do { \ elm->next = list; \ diff --git a/server/src/path.c b/server/src/path.c index cc9808caf..7c0950d49 100644 --- a/server/src/path.c +++ b/server/src/path.c @@ -79,6 +79,13 @@ static void * path_run(void *arg) p->received++; + if (HIST_SEQ/2 + lag >= HIST_SEQ) + p->histogram[HIST_SEQ-1]++; + else if (HIST_SEQ/2 + lag < 0) + p->histogram[0]++; + else + p->histogram[HIST_SEQ/2 + lag]++; + /** Check header fields */ if (m->version != MSG_VERSION || m->type != MSG_TYPE_DATA) { @@ -144,6 +151,11 @@ int path_stop(struct path *p) pthread_join(p->sent_tid, NULL); } + if (p->received) { + path_stats(p); + hist_dump(p->histogram, HIST_SEQ); + } + return 0; } diff --git a/server/src/utils.c b/server/src/utils.c index 76246bf4d..8784977d0 100644 --- a/server/src/utils.c +++ b/server/src/utils.c @@ -121,3 +121,18 @@ struct timespec timespec_rate(double rate) return ts; } + +void hist_dump(unsigned *hist, int length) +{ + char tok[16]; + char buf[length * sizeof(tok)]; + memset(buf, 0, sizeof(buf)); + + /* Print in Matlab vector format */ + for (int i = 0; i < length; i++) { + snprintf(tok, sizeof(tok), "%u ", hist[i]); + strncat(buf, tok, sizeof(buf)-strlen(buf)); + } + + info("hist = [ %s]", buf); +}