Browse Source

ppswatch: Add useful stats output.

Calculate mean value and standard deviation of captured offsets. Display them
at the exit.

Signed-off-by: Andrey Drobyshev <immortalguardian1@gmail.com>
tags/v1.0.0
Andrey Drobyshev Alexander GQ Gerasiov 3 years ago
parent
commit
7449bce937
2 changed files with 11 additions and 0 deletions
  1. +1
    -0
      Makefile
  2. +10
    -0
      ppswatch.c

+ 1
- 0
Makefile View File

@@ -4,6 +4,7 @@ CFLAGS += -Wall -O2 -D_GNU_SOURCE
CFLAGS += -I .
CFLAGS += -ggdb
CFLAGS += -D__N_PPS=18
LDFLAGS += -lm

# -- Actions section --



+ 10
- 0
ppswatch.c View File

@@ -22,6 +22,7 @@
#include <sys/stat.h>
#include <getopt.h>
#include <signal.h>
#include <math.h>

#include "timepps.h"

@@ -35,6 +36,8 @@ static int total = 0;
static int overflows = 0;
static int max_unsync = 0;
static int max_divergence = 0;
static double mean = 0.0;
static double M2 = 0.0;

int find_source(char *path, pps_handle_t *handle, int *avail_mode)
{
@@ -99,6 +102,7 @@ int fetch_source(pps_handle_t handle, int avail_mode)
pps_info_t infobuf;
int ret;
long div;
double delta, delta2;

if (avail_mode & PPS_CANWAIT) /* waits for the next event */
ret = time_pps_fetch(handle, PPS_TSFMT_TSPEC, &infobuf,
@@ -132,6 +136,10 @@ int fetch_source(pps_handle_t handle, int avail_mode)

total++;
div = ts.tv_nsec;
delta = div - mean;
mean += delta / total;
delta2 = div - mean;
M2 += delta * delta2;
if (div < 0)
div = -div;
if (max_divergence < div)
@@ -230,6 +238,8 @@ void print_stats()
printf("Maximum unsynchronized time: %d\n", max_unsync);
}
printf("Maximum divergence: %d\n", max_divergence);
printf("Mean value: %g\n", mean);
printf("Standard deviation: %g\n", sqrt(M2 / total));
}

static void sighandler_exit(int signum) {


Loading…
Cancel
Save