(require 'elp) (defun g (n) (f (abs n))) (defun f (n) (when (not (= n 0)) (f (1- n)))) (defun get-timer-info (funsym caller) (let ((info-plist (get funsym elp-timer-info-property))) (or info-plist (error "%s is not instrumented for profiling" funsym)) (plist-get info-plist caller))) (defun call-count (funsym caller) (let ((info (get-timer-info funsym caller))) (or info (error "%s is not instrumented for profiling" caller)) (aref info 0))) (ert-deftest root-function-is-profiled () (elp-instrument-function 'g) (g 3) ;; f(3) -> f(2) -> f(1) -> f(0) (should (= (call-count #'g t) 1)) (should (= (call-count #'g #'g) 0)) (elp-restore-all)) (ert-deftest recursive-calls-not-profiled () (elp-instrument-function 'f) (elp-instrument-function 'g) (g 3) ;; f(3) -> f(2) -> f(1) -> f(0) (should (= (call-count #'f #'g) 1)) (should (= (call-count #'f #'f) 3)) (should (= (call-count #'f t) 0)) (elp-restore-all)) (ert-deftest print-elp-result () (setq elp--instrumented-functions `(g f)) (let ((res-plist `(g (,(vector 1 2 3 "g") ,(vector 4 5 6 "f") ,(vector 0 0 0 "g")) f (,(vector 3 2 1 "f") ,(vector 9 9 9 "f")) )) (elp-field-len 2) (elp-cc-len 2) (elp-et-len 2) (elp-at-len 2)) (with-temp-buffer (message (format "elp-field-len: %s" elp-field-len)) (elp-output-function res-plist) (let ((first-line (buffer-substring-no-properties (point-min) (point)))) (should (equal first-line ""))))) (elp-restore-all)) (ert-deftest elp-reset-test () (elp-instrument-list `(g f)) (g 3) (elp-reset-function 'g))