1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| | (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))
|