;;; -*- lexical-binding: t -*- ;; for a buffer/file of tick-time integers ;; one at each line ;; this Elisp number cruncher ;; is used to process the tick times ;; in order to find out how much ;; the ticks deviated ;; from the desired, fixed-interrupt rate ;; for the particular trace ;; stats are presented ;; as well as every drift from the specified ideal ;; as an indicator of an inexact clock ;; or if this needs to be further analyzed (require 'cl-macs) (defun get-variance (mean) (save-excursion (goto-char 1) (let ((sum 0) (offsets 0)) (cl-loop (let ((offset (thing-at-point 'number))) (if offset (progn (cl-incf offsets) (setq sum (+ sum (expt (- offset mean) 2))) (forward-line 1) ) (cl-return) ))) (/ sum offsets) ))) (defun tick-stats (desired-tick) (interactive "n desired tick: ") (save-excursion (goto-char 1) (let ((sum 0) (offsets 0) (max nil) (min nil) ) (cl-loop (let((t0 (thing-at-point 'number))) (forward-line 1) (let((t1 (thing-at-point 'number))) (save-current-buffer (set-buffer (get-buffer-create "offsets.log")) (if t1 (let((offset (- t1 t0 desired-tick))) (cl-incf offsets) (setq sum (+ sum offset)) (if (or (not max) (> offset max)) (setq max offset)) (if (or (not min) (> min offset)) (setq min offset)) (insert (format "%d\n" offset)) ) (progn (goto-char 1) (insert (let*((mean (/ sum offsets)) (variance (get-variance mean)) ) (format "readings: %d\nmean: %f\nvariance: %f\nstandard deviation: %f\nmin: %d\nmax: %d\n\n" offsets mean variance (sqrt variance) min max))) (write-file "stats.log") (cl-return) )))))))))