diff options
| author | Vegard Øye <vegard_oye@hotmail.com> | 2011-08-17 14:18:33 +0200 |
|---|---|---|
| committer | Vegard Øye <vegard_oye@hotmail.com> | 2011-08-17 14:18:33 +0200 |
| commit | bf3c9ebf9e0e1144d81586c838bc47a5756fff64 (patch) | |
| tree | 481cc3a2e05300058065a0445fa08c36bfe6afb8 | |
| parent | 3154834c8188c6b20b04d70a05247b8fb2174108 (diff) | |
Add PROFILER variable and "make profiler" rule
Let evil-tests.el instrument Evil for profiling. This is enabled with
"make profiler", which runs all tests in the terminal and then displays
profiling results, or with the PROFILER variable, which can be used
with any rule and specifies how the results are sorted (by call count,
average time or total time):
make test PROFILER=call
make test PROFILER=average
make test PROFILER=total
Using the PROFILER variable with the "make emacs" rule creates a
results buffer with links to each function's source.
| -rw-r--r-- | Makefile | 22 | ||||
| -rw-r--r-- | evil-integration.el | 6 | ||||
| -rw-r--r-- | evil-tests.el | 62 |
3 files changed, 68 insertions, 22 deletions
@@ -2,11 +2,12 @@ SHELL = /bin/bash EMACS = emacs FILES = $(filter-out evil-tests.el,$(filter-out evil-pkg.el,$(wildcard evil*.el))) ELPAPKG = evil-`sed -n '3s/.*"\(.*\)".*/\1/p' evil-pkg.el` +PROFILER = TAG = ELCFILES = $(FILES:.el=.elc) -.PHONY: all compile compile-batch clean tests test emacs term terminal indent elpa version +.PHONY: all compile compile-batch clean tests test emacs term terminal profiler indent elpa version # Byte-compile Evil. all: compile @@ -41,30 +42,31 @@ clean: # The TAG variable may specify a test tag or a test name: # make test TAG=repeat # This will only run tests pertaining to the repeat system. -test: clean +test: $(EMACS) --batch -Q -L . -L lib -l evil-tests.el \ ---eval "(evil-tests-run '(${TAG}))" +--eval "(evil-tests-initialize '(${TAG}) '(${PROFILER}))" # Byte-compile Evil and run all tests. tests: compile-batch $(EMACS) --batch -Q -L . -L lib -l evil-tests.el \ ---eval "(evil-tests-run '(${TAG}))" +--eval "(evil-tests-initialize '(${TAG}) '(${PROFILER}))" rm -f *.elc # Load Evil in a fresh instance of Emacs and run all tests. emacs: $(EMACS) -Q -L . -L lib -l evil-tests.el --eval "(evil-mode 1)" \ ---eval "(if (y-or-n-p-with-timeout \"Run tests? \" 2 t) \ -(evil-tests-run '(${TAG}) t) \ -(message \"You can run the tests at any time with \`M-x evil-tests-run\'\"))" & +--eval "(evil-tests-initialize '(${TAG}) '(${PROFILER}) t)" & # Load Evil in a terminal Emacs and run all tests. term: terminal terminal: $(EMACS) -nw -Q -L . -L lib -l evil-tests.el --eval "(evil-mode 1)" \ ---eval "(if (y-or-n-p-with-timeout \"Run tests? \" 2 t) \ -(evil-tests-run '(${TAG}) t) \ -(message \"You can run the tests at any time with \`M-x evil-tests-run\'\"))" +--eval "(evil-tests-initialize '(${TAG}) '(${PROFILER}) t)" + +# Run all tests with profiler. +profiler: + $(EMACS) --batch -Q -L . -L lib -l evil-tests.el \ +--eval "(evil-tests-initialize '(${TAG}) (or '(${PROFILER}) t))" # Re-indent all Evil code. # Loads Evil into memory in order to indent macros properly. diff --git a/evil-integration.el b/evil-integration.el index b58dc3d..b634fbb 100644 --- a/evil-integration.el +++ b/evil-integration.el @@ -33,6 +33,12 @@ (defadvice wdired-change-to-dired-mode (after evil activate) (evil-change-to-initial-state nil t)))) +;;; ELP + +(eval-after-load 'elp + '(defadvice elp-results (after evil activate) + (evil-motion-state))) + ;;; Folding (eval-after-load 'hideshow diff --git a/evil-tests.el b/evil-tests.el index 7485025..fbc83b9 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -9,26 +9,64 @@ ;; ;; This file is NOT part of Evil itself. +(require 'elp) (require 'ert) (require 'evil) (defvar evil-tests-run nil "*Run Evil tests.") +(defvar evil-tests-profiler nil + "*Profile Evil tests.") + +(defun evil-tests-initialize (&optional tests profiler interactive) + (setq profiler (or profiler evil-tests-profiler)) + (when (listp profiler) + (setq profiler (car profiler))) + (when profiler + (setq evil-tests-profiler t) + (setq profiler + (or (cdr (assq profiler + '((call . elp-sort-by-call-count) + (average . elp-sort-by-average-time) + (total . elp-sort-by-total-time)))))) + (setq elp-sort-by-function (or profiler 'elp-sort-by-call-count)) + (elp-instrument-package "evil")) + (if interactive + (if (y-or-n-p-with-timeout "Run tests? " 2 t) + (evil-tests-run tests interactive) + (message "You can run the tests at any time \ +with `M-x evil-tests-run'")) + (evil-tests-run tests))) + (defun evil-tests-run (&optional tests interactive) "Run Evil tests." (interactive '(nil t)) - (setq tests - (or (null tests) - `(or ,@(mapcar (lambda (test) - (or (null test) - (and (memq test '(evil t)) t) - `(or (tag ,test) - ,(format "^%s$" test)))) - tests)))) - (if interactive + (let ((elp-use-standard-output (not interactive))) + (setq tests + (or (null tests) + `(or ,@(mapcar (lambda (test) + (or (null test) + (and (memq test '(evil t)) t) + `(or (tag ,test) + ,(format "^%s$" test)))) + tests)))) + (cond + (interactive (ert-run-tests-interactively tests) - (ert-run-tests-batch-and-exit tests))) + (when evil-tests-profiler + (elp-results))) + (evil-tests-profiler + (ert-run-tests-batch tests) + (elp-results)) + (t + (ert-run-tests-batch-and-exit tests))))) + +(defun evil-tests-profiler (&optional force) + "Profile Evil tests." + (when (or evil-tests-profiler force) + (setq evil-tests-profiler t) + (elp-instrument-package "evil"))) (defvar evil-test-point nil "Marker for point.") @@ -3816,8 +3854,8 @@ if no previous selection") (should (equal (evil-ex-parse-range ".+42cmd arg" 0) (cons 4 '((current-line . 42) nil nil))))) -(when evil-tests-run - (evil-tests-run)) +(when (or evil-tests-profiler evil-tests-run) + (evil-tests-initialize)) (provide 'evil-tests) |
