logging - Emacs: log the time required for typing commands -
i'm emacs novice. i'm in middle of learning basic commands navigation, editing etc.
some key-combinations take me longer complete...they require either more keys pressed or higher degree of finger-position acrobatics :). i'm wondering if knows if there existing emacs plugin that:
- recognises when user has begun typing command (e.g. 'c-' or 'm-' something) , records time @ instant, then
- waits until user has finished typing command (i.e. point @ command recognised, before command executed) , records time too, then
- appends simple logging info configurable file (e.g. writes 'command description', 'keys', 'entry duration') particular occurrence.
why? perhaps it's overkill, save me time in future if able analyse such log file , determine commands have high usage frequency long completion time. such commands bound keys simpler humble fingers reach, example :).
it nice learning exercise me write myself, i'd prefer save time if solution exists.
here, take lisp code:
(global-set-key (kbd "c-t") 'timed-key-seq) (defvar timed-keys-hash (make-hash-table :test 'equal)) (defun timed-key-seq () (interactive) (let* ((t-beg (current-time)) (key (read-key-sequence "command:")) (t-end (current-time)) (t-diff (time-subtract t-end t-beg)) (data (gethash key timed-keys-hash))) (if data (destructuring-bind (times . time) data (puthash key (cons (1+ times) (time-add time t-diff)) timed-keys-hash)) (puthash key (cons 1 t-diff) timed-keys-hash)) (call-interactively (key-binding key)))) (defun anb-report () (interactive) (let (entries) (maphash (lambda (key data) (push (format "%s:\t%sx = %s ms\n" key (car data) (format-time-string "%3n" (cdr data))) entries)) timed-keys-hash) (message (apply #'concat entries))))
the disadvantage need bind timed-key-seq
something, i'd suggest c-t. , prefix commands c-t. maybe can suggest defadvice
make sure function called each time without having prefix it.
use anb-report
generate report. show how many times called each combination , how many milliseconds took together.
Comments
Post a Comment