[Git][NTPsec/ntpsec][master] 3 commits: ntpfrob array fix

Eric S. Raymond gitlab at mg.gitlab.com
Tue Jul 31 16:37:12 UTC 2018


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
6044ef91 by James Browning at 2018-07-31T16:28:36Z
ntpfrob array fix

- - - - -
80913de7 by James Browning at 2018-07-31T16:28:36Z
fix ntpfrob -c sorting

- - - - -
25bd9aab by James Browning at 2018-07-31T16:28:36Z
add variance as jitter

- - - - -


1 changed file:

- ntpfrob/jitter.c


Changes:

=====================================
ntpfrob/jitter.c
=====================================
@@ -62,9 +62,12 @@ get_clocktime(
 	setlfpfrac(*now, (uint32_t)dtemp);
 }
 
-static int doublecmp(const void *a, const void *b)
+// modified from https://stackoverflow.com/questions/11931547/qsort-does-not-work-for-double-array
+static int doublecmp(const void * a, const void * b)
 {
-    return (int)(*((const double *)a) - *((const double *)b));
+  if (*(const double*)a > *(const double*)b) return -1;
+  else if (*(const double*)a < *(const double*)b) return 1;
+  else return 0;
 }
 
 void jitter(const iomode mode)
@@ -72,6 +75,7 @@ void jitter(const iomode mode)
 	l_fp tr;
 	int i;
 	double gtod[NBUF];
+	doubletime_t jitter;
 
 	/*
 	 * Force pages into memory
@@ -91,7 +95,7 @@ void jitter(const iomode mode)
 	 * Write out gtod array for later processing with Matlab
 	 */
 	average = 0;
-	for (i = 0; i < NBUF - 2; i++) {
+	for (i = 0; i < (NBUF - 1); i++) {
 		gtod[i] = gtod[i + 1] - gtod[i];
 		if (mode == raw)
 			printf("%13.9f\n", gtod[i]);
@@ -101,33 +105,45 @@ void jitter(const iomode mode)
 	if (mode == raw)
 	    exit(0);
 
+	average = average / (NBUF - 1);
+
+	// calculate 'variance' and call it jitter
+	// and scale everything up a million time for clarity
+	jitter = 0;
+	for (i = 0; i < (NBUF - 1); i ++) {
+		gtod[i] = (gtod[i] - average) * 1000000;
+		jitter += gtod[i] * gtod[i];
+	}
+	jitter = jitter / (NBUF - 1);
+
 	/*
 	 * Sort the gtod array and display deciles
 	 */
-	qsort(gtod, NBUF, sizeof(gtod[0]), doublecmp);
-	average = average / (NBUF - 2);
+	qsort(gtod, (NBUF - 1), sizeof(gtod[0]), doublecmp);
+
 	if (mode == json) {
-		fprintf(stdout, "{\"Average\": %.9Lf, \"First rank\": [", average);
+		fprintf(stdout, "{\"Mean\": %.9Lf, \"High\": [", average);
 		for (i = 0; i < NSAMPLES; i++) {
 		    fprintf(stdout, "%.9f", gtod[i]);
 		    if (i < NSAMPLES - 1)
 			fputs(", ", stdout);
 		}
-		fputs("], \"Last rank\": [", stdout);
+		fputs("], \"Low\": [", stdout);
 		for (i = NBUF - NSAMPLES - 2; i < NBUF - 2; i++) {
 		    fprintf(stdout, "%.9f", gtod[i]);
 		    if (i < NBUF - 3)
 			fputs(", ", stdout);
 		}
-		fputs("]}\n", stdout);
+		fprintf(stdout, "], \"Jitter\": %.9Lf}\n", jitter);
 	}
 	else if (mode != raw)
 	{
-		fprintf(stdout, "Average %13.9Lf\n", average);
-		fprintf(stdout, "First rank\n");
+		fprintf(stdout, "Mean %13.9Lf\n", average);
+		fprintf(stdout, "Jitter %13.9Lf\n", jitter);
+		fprintf(stdout, "High\n");
 		for (i = 0; i < NSAMPLES; i++)
 		    fprintf(stdout, "%2d %13.9f\n", i, gtod[i]);
-		fprintf(stdout, "Last rank\n");
+		fprintf(stdout, "Low\n");
 		for (i = NBUF - NSAMPLES - 2; i < NBUF - 2; i++)
 		    fprintf(stdout, "%2d %13.9f\n", i, gtod[i]);
 	}



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/34302c37cd6bd00a4e47c1a3ab930dd5db7a8acf...25bd9aabeec02580186c7164ce3c91c9d1675961

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/34302c37cd6bd00a4e47c1a3ab930dd5db7a8acf...25bd9aabeec02580186c7164ce3c91c9d1675961
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20180731/31c84c72/attachment-0001.html>


More information about the vc mailing list