工作中经常会通过输出log对程序各模块耗时进行统计,写了个命令快速统计log文件中某个模块耗时。
原理是通过occur查找要统计的量,然后选中列,通过emacs内置命令对数值进行统计。
(require 'calc-stat)
(defun statistics-in-region (start end)
(interactive "r")
(setq LIST (split-string (buffer-substring start end)))
(setq LIST (mapcar* #'(lambda (X) (math-read-number X)) LIST))
(message "length:%s, mean:%s, variance:%s, standard deviation:%s, meidan:%s, max:%s, min:%s"
(length LIST)
(math-format-number (calcFunc-vmean (cons 'vec LIST)))
(math-format-number (calcFunc-vvar (cons 'vec LIST)))
(math-format-number (calcFunc-vsdev (cons 'vec LIST)))
(math-format-number (calcFunc-vmedian (cons 'vec LIST)))
(math-format-number (calcFunc-vmax (cons 'vec LIST)))
(math-format-number (calcFunc-vmin (cons 'vec LIST)))))
(defun statistics-in-rectangle (start end)
"statistics-in-rectangle."
(interactive "r")
(setq LIST nil)
(dolist (element (extract-rectangle start end)) ;; extract-rectangle to lists
(setq LIST (append LIST (split-string element)))) ;; apend to list
;; (setq LIST (seq-map 'string-to-number LIST)) ;; convert to num
(setq LIST (mapcar* #'(lambda (X) (math-read-number X)) LIST))
(message "length:%s, mean:%s, variance:%s, standard deviation:%s, meidan:%s, max:%s, min:%s"
(length LIST)
(math-format-number (calcFunc-vmean (cons 'vec LIST)))
(math-format-number (calcFunc-vvar (cons 'vec LIST)))
(math-format-number (calcFunc-vsdev (cons 'vec LIST)))
(math-format-number (calcFunc-vmedian (cons 'vec LIST)))
(math-format-number (calcFunc-vmax (cons 'vec LIST)))
(math-format-number (calcFunc-vmin (cons 'vec LIST)))))