xref: /freebsd/contrib/ntp/scripts/stats/loop.awk (revision cfe30d02adda7c3b5c76156ac52d50d8cab325d9)
1c0b746e5SOllivier Robert# awk program to scan loopstats files and report errors/statistics
2c0b746e5SOllivier Robert#
3c0b746e5SOllivier Robert# usage: awk -f loop.awk loopstats
4c0b746e5SOllivier Robert#
5c0b746e5SOllivier Robert# format of loopstats record
6c0b746e5SOllivier Robert#  MJD    sec   time (s)  freq (ppm)  poll
7c0b746e5SOllivier Robert# 49235  3.943  0.000016   22.4716    6
8c0b746e5SOllivier Robert#
9c0b746e5SOllivier Robert# format of output dataset (time values in milliseconds, freq in ppm)
10c0b746e5SOllivier Robert# loopstats.19960706
11c0b746e5SOllivier Robert# loop 1180, 0+/-11.0, rms 2.3, freq -24.45+/-0.045, var 0.019
12c0b746e5SOllivier Robert#
13c0b746e5SOllivier RobertBEGIN {
14c0b746e5SOllivier Robert	loop_tmax = loop_fmax = -1e9
15c0b746e5SOllivier Robert	loop_tmin = loop_fmin = 1e9
16c0b746e5SOllivier Robert}
17c0b746e5SOllivier Robert#
18c0b746e5SOllivier Robert# scan all records in file
19c0b746e5SOllivier Robert#
20c0b746e5SOllivier Robert{
21c0b746e5SOllivier Robert	if (NF >= 5) {
22c0b746e5SOllivier Robert		loop_count++
23c0b746e5SOllivier Robert		if ($3 > loop_tmax)
24c0b746e5SOllivier Robert			loop_tmax = $3
25c0b746e5SOllivier Robert		if ($3 < loop_tmin)
26c0b746e5SOllivier Robert			loop_tmin = $3
27c0b746e5SOllivier Robert		if ($4 > loop_fmax)
28c0b746e5SOllivier Robert			loop_fmax = $4
29c0b746e5SOllivier Robert		if ($4 < loop_fmin)
30c0b746e5SOllivier Robert			loop_fmin = $4
31c0b746e5SOllivier Robert		loop_time += $3
32c0b746e5SOllivier Robert		loop_time_rms += $3 * $3
33c0b746e5SOllivier Robert		loop_freq += $4
34c0b746e5SOllivier Robert		loop_freq_rms += $4 * $4
35c0b746e5SOllivier Robert	}
36c0b746e5SOllivier Robert} END {
37c0b746e5SOllivier Robert	if (loop_count > 0) {
38c0b746e5SOllivier Robert		loop_time /= loop_count
39c0b746e5SOllivier Robert                loop_time_rms = sqrt(loop_time_rms / loop_count - loop_time * loop_time)
40c0b746e5SOllivier Robert		loop_freq /= loop_count
41c0b746e5SOllivier Robert		loop_freq_rms = sqrt(loop_freq_rms / loop_count - loop_freq * loop_freq)
42c0b746e5SOllivier Robert		printf "loop %d, %.0f+/-%.1f, rms %.1f, freq %.2f+/-%0.3f, var %.3f\n", loop_count, (loop_tmax + loop_tmin) / 2 * 1e6, (loop_tmax - loop_tmin) / 2 * 1e6, loop_time_rms * 1e6, (loop_fmax + loop_fmin) / 2, (loop_fmax - loop_fmin) / 2, loop_freq_rms
43c0b746e5SOllivier Robert	}
44c0b746e5SOllivier Robert}
45c0b746e5SOllivier Robert
46