diff options
Diffstat (limited to 'ckt0.awk')
| -rw-r--r-- | ckt0.awk | 121 |
1 files changed, 81 insertions, 40 deletions
@@ -17,8 +17,9 @@ function merge_meas(est_val, est_unc, meas_val, meas_unc) { est_val = est_val + K*(meas_val - est_val) est_unc = (est_unc*meas_unc)/(est_unc + meas_unc) - # convert est_unc back to original units + # convert uncertainties back to original units est_unc = 2.0*sqrt(est_unc) + meas_unc = 2.0*sqrt(meas_unc) return sprintf(OFMT OFS OFMT ORS, est_val, est_unc) @@ -30,24 +31,24 @@ function sigfig(val, unc) { ordmag_val = log10(val) ordmag_unc = log10(unc) - #sigfig_unc = sprintf("%.f", 6) - sigfig_unc = sprintf("%.f", sqrt((ordmag_val - ordmag_unc)^2.0) + 1.0) - sigfig_val = sprintf("%.f", (ordmag_val - ordmag_unc + sigfig_unc)) + ordmag_high = sqrt((ordmag_val)^2.0 + (ordmag_unc)^2.0) + ordmag_low = ((ordmag_val)^-1.0 + (ordmag_unc)^-1.0)^-1.0 + ordmag_range = ordmag_high - ordmag_low + + sigfig_unc = sprintf("%.f", ordmag_range) + sigfig_val = sprintf("%.f", sigfig_unc + 6.0) ofmt_val = "%." sigfig_val "g" ofmt_unc = "%." sigfig_unc "g" - return sprintf(ofmt_val OFS ofmt_unc ORS, val, unc) + return sprintf(ofmt_val OFS ofmt_unc, val, unc) } -function ck_boottime() { +function ck_boottime(unm) { - "uname" | getline uname - close("uname") - - if (uname ~/OpenBSD/) { + if (unm ~/OpenBSD/) { "sysctl kern.boottime" | getline t0_k close("sysctl kern.boottime") sub("^.*=", "", t0_k) @@ -58,7 +59,7 @@ function ck_boottime() { t0_k = mktime(t0_k) } - if (uname ~/FreeBSD/) { + if (unm ~/FreeBSD/) { "sysctl kern.boottime" | getline t0_k close("sysctl kern.boottime") sub("^.*{", "", t0_k) @@ -78,19 +79,27 @@ function ck_boottime() { } -function ck_uptime(t0_est, t0_unc) { +function ck_time(unm) { - t_sys_meas[1] = systime() - t_sys_meas[2] = 1.0 + if (unm ~/FreeBSD/) { + #t = systime() + "date +%s.%N" | getline t + close("date +%s.%N") + } + else { + t = systime() + } - "uptime" | getline t_up_cmd - close("uptime") + return t - split(merge_meas(t_sys_meas[1], t_sys_meas[2], systime(), 1.0), t_sys_meas) +} - # estimate (predict) uptime - t_up_est[1] = t_sys_meas[1] - t0_est - t_up_est[2] = t_sys_meas[2] + t0_unc + +function ck_uptime() { + + # check uptime cmd + "uptime" | getline t_up_cmd + close("uptime") # evaluate measured uptime t_up_meas[1] = 0.0 @@ -131,40 +140,72 @@ function ck_uptime(t0_est, t0_unc) { } - # merge predicted and measured uptimes - split(merge_meas(t_up_est[1], t_up_est[2], t_up_meas[1], t_up_meas[2]), t_up_est) - - # evaluate measured boot time, t0 - t_boot_meas[1] = t_sys_meas[1] - t_up_meas[1] - t_boot_meas[2] = t_sys_meas[2] + t_up_meas[2] - - # merge previous and updated boot time, t0 - split(merge_meas(t0_est, t0_unc, t_boot_meas[1], t_boot_meas[2]), t_boot_est) - - return sigfig(t_boot_est[1], t_boot_est[2]) + return sigfig(t_up_meas[1], t_up_meas[2]) } BEGIN { - OFMT="%.21g" + OFMT="%f" pi = 4.0*atan2(1.0, 1.0) c0 = 299792458 # m/sec + "uname" | getline uname + close("uname") + #print("_systime_", systime()) #print("_boottime_", ck_boottime()) - # check ARGV for previous estimate - if (ARGC > 0) { - ARGV[1] ? t0_est[1] = ARGV[1] : split(ck_boottime(), t0_est) - ARGV[2] ? t0_est[2] = ARGV[2] : split(ck_boottime(), t0_est) + # check ARGV for previous estimates + #print("ARGC:", ARGC) + if (ARGC) { + ARGV[1] ? t_prev[1] = ARGV[1] : t_prev[1] = 0.0 + ARGV[2] ? t_prev[2] = ARGV[2] : t_prev[2] = systime() + ARGV[3] ? t_up_prev[1] = ARGV[3] : t_up_prev[1] = 0.0 + ARGV[4] ? t_up_prev[2] = ARGV[4] : t_up_prev[2] = systime() + ARGV[5] ? t0_prev[1] = ARGV[5] : split(ck_boottime(uname), t0_prev) + ARGV[6] ? t0_prev[2] = ARGV[6] : split(ck_boottime(uname), t0_prev) } - #print("t0_est = ", t0_est[1]) - #print("t_boot_unc = ", t0_est[2]) + #print( t_prev[1], t_prev[2], t_up_prev[1], t_up_prev[2], t0_prev[1], t0_prev[2] ) + + # check systime, check uptime, check systime again + t_meas[1] = ck_time(uname) + split(ck_uptime(), t_up_meas) + t_meas[2] = ck_time(uname) + + # convert to [val, unc] vector + if ( t_meas[1] != t_meas[2] ) { + t_meas[2] -= t_meas[1] + t_meas[1] += 0.5*t_meas[2] + } else { + t_meas[2] = 1.0 + } + t_meas_str = sigfig(t_meas[1], t_meas[2]) + + # estimate dt + dt[1] = t_meas[1] - t_prev[1] + dt[2] = t_meas[2] + t_prev[2] + + # predict uptime based on dt, t_up(new) = t_up(old) + dt + t_up_est[1] = t_up_prev[1] + dt[1] + t_up_est[2] = t_up_prev[2] + dt[2] + + # merge predicted and measured uptimes + split(merge_meas(t_up_est[1], t_up_est[2], t_up_meas[1], t_up_meas[2]), t_up_est) + t_up_est[2] = sqrt( t_up_est[2]^2.0 + (t_up_est[1] - t_up_prev[1] - dt[1])^2.0 ) + t_up_est_str = sigfig(t_up_est[1], t_up_est[2]) + + # evaluate measured boot time, t0 + t0_est[1] = t_meas[1] - t_up_est[1] + t0_est[2] = t_meas[2] + t_up_est[2] + + # merge previous and updated boot time, t0 + split(merge_meas(t0_est[1], t0_est[2], t0_prev[1], t0_prev[2]), t0_est) + t0_est[2] = sqrt( t0_est[2]^2.0 + (t0_est[1] - t0_prev[1])^2.0 ) + t0_est_str = sigfig(t0_est[1], t0_est[2]) - # check uptime, update estimate - print(ck_uptime(t0_est[1], t0_est[2])) + print(t_meas_str, t_up_est_str, t0_est_str) } |
