aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/profiler.el74
2 files changed, 41 insertions, 37 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a12390cd61f..6c8a4f9ec84 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12012-08-22 Tomohiro Matsuyama <tomo@cx4a.org>
2
3 * profiler.el: Switch to cl-lib.
4
12012-08-22 Daiki Ueno <ueno@unixuser.org> 52012-08-22 Daiki Ueno <ueno@unixuser.org>
2 6
3 * progmodes/js.el (js-indent-level, js-expr-indent-offset) 7 * progmodes/js.el (js-indent-level, js-expr-indent-offset)
diff --git a/lisp/profiler.el b/lisp/profiler.el
index c82aea1118d..8428b38c586 100644
--- a/lisp/profiler.el
+++ b/lisp/profiler.el
@@ -25,7 +25,7 @@
25;;; Code: 25;;; Code:
26 26
27(eval-when-compile 27(eval-when-compile
28 (require 'cl)) 28 (require 'cl-lib))
29 29
30(defgroup profiler nil 30(defgroup profiler nil
31 "Emacs profiler." 31 "Emacs profiler."
@@ -42,38 +42,38 @@
42 (format "%s" object))) 42 (format "%s" object)))
43 43
44(defun profiler-format (fmt &rest args) 44(defun profiler-format (fmt &rest args)
45 (loop for (width align subfmt) in fmt 45 (cl-loop for (width align subfmt) in fmt
46 for arg in args 46 for arg in args
47 for str = (typecase subfmt 47 for str = (cl-typecase subfmt
48 (cons (apply 'profiler-format subfmt arg)) 48 (cons (apply 'profiler-format subfmt arg))
49 (string (format subfmt arg)) 49 (string (format subfmt arg))
50 (t (profiler-ensure-string arg))) 50 (t (profiler-ensure-string arg)))
51 for len = (length str) 51 for len = (length str)
52 if (< width len) 52 if (< width len)
53 collect (substring str 0 width) into frags 53 collect (substring str 0 width) into frags
54 else 54 else
55 collect 55 collect
56 (let ((padding (make-string (- width len) ?\s))) 56 (let ((padding (make-string (- width len) ?\s)))
57 (ecase align 57 (cl-ecase align
58 (left (concat str padding)) 58 (left (concat str padding))
59 (right (concat padding str)))) 59 (right (concat padding str))))
60 into frags 60 into frags
61 finally return (apply #'concat frags))) 61 finally return (apply #'concat frags)))
62 62
63 63
64 64
65;;; Slot data structure 65;;; Slot data structure
66 66
67(defstruct (profiler-slot (:type list) 67(cl-defstruct (profiler-slot (:type list)
68 (:constructor profiler-make-slot)) 68 (:constructor profiler-make-slot))
69 backtrace count elapsed) 69 backtrace count elapsed)
70 70
71 71
72 72
73;;; Log data structure 73;;; Log data structure
74 74
75(defstruct (profiler-log (:type list) 75(cl-defstruct (profiler-log (:type list)
76 (:constructor profiler-make-log)) 76 (:constructor profiler-make-log))
77 type diff-p timestamp slots) 77 type diff-p timestamp slots)
78 78
79(defun profiler-log-diff (log1 log2) 79(defun profiler-log-diff (log1 log2)
@@ -117,7 +117,7 @@
117 117
118;;; Calltree data structure 118;;; Calltree data structure
119 119
120(defstruct (profiler-calltree (:constructor profiler-make-calltree)) 120(cl-defstruct (profiler-calltree (:constructor profiler-make-calltree))
121 entry 121 entry
122 (count 0) count-percent 122 (count 0) count-percent
123 (elapsed 0) elapsed-percent 123 (elapsed 0) elapsed-percent
@@ -151,9 +151,9 @@
151 (1+ (profiler-calltree-depth parent))))) 151 (1+ (profiler-calltree-depth parent)))))
152 152
153(defun profiler-calltree-find (tree entry) 153(defun profiler-calltree-find (tree entry)
154 (dolist (child (profiler-calltree-children tree)) 154 (cl-dolist (child (profiler-calltree-children tree))
155 (when (equal (profiler-calltree-entry child) entry) 155 (when (equal (profiler-calltree-entry child) entry)
156 (return child)))) 156 (cl-return child))))
157 157
158(defun profiler-calltree-walk (calltree function) 158(defun profiler-calltree-walk (calltree function)
159 (funcall function calltree) 159 (funcall function calltree)
@@ -171,16 +171,16 @@
171 (unless child 171 (unless child
172 (setq child (profiler-make-calltree :entry entry :parent node)) 172 (setq child (profiler-make-calltree :entry entry :parent node))
173 (push child (profiler-calltree-children node))) 173 (push child (profiler-calltree-children node)))
174 (incf (profiler-calltree-count child) count) 174 (cl-incf (profiler-calltree-count child) count)
175 (incf (profiler-calltree-elapsed child) elapsed) 175 (cl-incf (profiler-calltree-elapsed child) elapsed)
176 (setq node child)))))) 176 (setq node child))))))
177 177
178(defun profiler-calltree-compute-percentages (tree) 178(defun profiler-calltree-compute-percentages (tree)
179 (let ((total-count 0) 179 (let ((total-count 0)
180 (total-elapsed 0)) 180 (total-elapsed 0))
181 (dolist (child (profiler-calltree-children tree)) 181 (dolist (child (profiler-calltree-children tree))
182 (incf total-count (profiler-calltree-count child)) 182 (cl-incf total-count (profiler-calltree-count child))
183 (incf total-elapsed (profiler-calltree-elapsed child))) 183 (cl-incf total-elapsed (profiler-calltree-elapsed child)))
184 (profiler-calltree-walk 184 (profiler-calltree-walk
185 tree (lambda (node) 185 tree (lambda (node)
186 (unless (zerop total-count) 186 (unless (zerop total-count)
@@ -194,7 +194,7 @@
194 (/ (* (profiler-calltree-elapsed node) 100) 194 (/ (* (profiler-calltree-elapsed node) 100)
195 total-elapsed)))))))) 195 total-elapsed))))))))
196 196
197(defun* profiler-calltree-build (log &key reverse) 197(cl-defun profiler-calltree-build (log &key reverse)
198 (let ((tree (profiler-make-calltree))) 198 (let ((tree (profiler-make-calltree)))
199 (profiler-calltree-build-1 tree log reverse) 199 (profiler-calltree-build-1 tree log reverse)
200 (profiler-calltree-compute-percentages tree) 200 (profiler-calltree-compute-percentages tree)
@@ -276,7 +276,7 @@
276 (elapsed-percent (profiler-calltree-elapsed-percent tree)) 276 (elapsed-percent (profiler-calltree-elapsed-percent tree))
277 (count (profiler-calltree-count tree)) 277 (count (profiler-calltree-count tree))
278 (count-percent (profiler-calltree-count-percent tree))) 278 (count-percent (profiler-calltree-count-percent tree)))
279 (ecase (profiler-log-type profiler-report-log) 279 (cl-ecase (profiler-log-type profiler-report-log)
280 (sample 280 (sample
281 (if diff-p 281 (if diff-p
282 (profiler-format profiler-report-sample-line-format 282 (profiler-format profiler-report-sample-line-format
@@ -334,7 +334,7 @@
334 334
335(defun profiler-report-make-buffer-name (log) 335(defun profiler-report-make-buffer-name (log)
336 (let ((time (format-time-string "%Y-%m-%d %T" (profiler-log-timestamp log)))) 336 (let ((time (format-time-string "%Y-%m-%d %T" (profiler-log-timestamp log))))
337 (ecase (profiler-log-type log) 337 (cl-ecase (profiler-log-type log)
338 (sample (format "*CPU-Profiler-Report %s*" time)) 338 (sample (format "*CPU-Profiler-Report %s*" time))
339 (memory (format "*Memory-Profiler-Report %s*" time))))) 339 (memory (format "*Memory-Profiler-Report %s*" time)))))
340 340
@@ -445,16 +445,16 @@ otherwise collapse the entry."
445 (require 'help-fns) 445 (require 'help-fns)
446 (describe-function entry))))) 446 (describe-function entry)))))
447 447
448(defun* profiler-report-render-calltree-1 (log &key reverse (order 'descending)) 448(cl-defun profiler-report-render-calltree-1 (log &key reverse (order 'descending))
449 (let ((calltree (profiler-calltree-build profiler-report-log 449 (let ((calltree (profiler-calltree-build profiler-report-log
450 :reverse reverse))) 450 :reverse reverse)))
451 (ecase (profiler-log-type log) 451 (cl-ecase (profiler-log-type log)
452 (sample 452 (sample
453 (setq header-line-format 453 (setq header-line-format
454 (profiler-report-header-line-format 454 (profiler-report-header-line-format
455 profiler-report-sample-line-format 455 profiler-report-sample-line-format
456 "Function" (list "Time (ms)" "%"))) 456 "Function" (list "Time (ms)" "%")))
457 (let ((predicate (ecase order 457 (let ((predicate (cl-ecase order
458 (ascending 'profiler-calltree-elapsed<) 458 (ascending 'profiler-calltree-elapsed<)
459 (descending 'profiler-calltree-elapsed>)))) 459 (descending 'profiler-calltree-elapsed>))))
460 (profiler-calltree-sort calltree predicate))) 460 (profiler-calltree-sort calltree predicate)))
@@ -463,7 +463,7 @@ otherwise collapse the entry."
463 (profiler-report-header-line-format 463 (profiler-report-header-line-format
464 profiler-report-memory-line-format 464 profiler-report-memory-line-format
465 "Function" (list "Alloc" "%"))) 465 "Function" (list "Alloc" "%")))
466 (let ((predicate (ecase order 466 (let ((predicate (cl-ecase order
467 (ascending 'profiler-calltree-count<) 467 (ascending 'profiler-calltree-count<)
468 (descending 'profiler-calltree-count>)))) 468 (descending 'profiler-calltree-count>))))
469 (profiler-calltree-sort calltree predicate)))) 469 (profiler-calltree-sort calltree predicate))))
@@ -540,7 +540,7 @@ otherwise collapse the entry."
540 (interactive 540 (interactive
541 (list (intern (completing-read "Mode: " '("cpu" "memory" "cpu&memory") 541 (list (intern (completing-read "Mode: " '("cpu" "memory" "cpu&memory")
542 nil t nil nil "cpu")))) 542 nil t nil nil "cpu"))))
543 (ecase mode 543 (cl-ecase mode
544 (cpu 544 (cpu
545 (sample-profiler-start profiler-sample-interval) 545 (sample-profiler-start profiler-sample-interval)
546 (message "CPU profiler started")) 546 (message "CPU profiler started"))