0
|
1 ;;; profile.el --- basic profiling commands for XEmacs
|
|
2
|
|
3 ;; Copyright (C) 1996 Ben Wing.
|
|
4
|
155
|
5 ;; Maintainer: XEmacs Development Team
|
|
6 ;; Keywords: internal
|
|
7
|
0
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
16
|
21 ;; along with XEmacs; see the file COPYING. If not, write to the
|
70
|
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
16
|
23 ;; Boston, MA 02111-1307, USA.
|
0
|
24
|
|
25 ;;; Synched up with: Not in FSF.
|
|
26
|
155
|
27 ;;; Commentary:
|
|
28
|
167
|
29 ;; `profile' macro and `profile-key-sequence' added in June 1997 by
|
|
30 ;; hniksic.
|
|
31
|
|
32
|
155
|
33 ;;; Code:
|
|
34
|
|
35 ;;;###autoload
|
167
|
36 (defun pretty-print-profiling-info (&optional info stream)
|
|
37 "Print profiling info INFO to STREAM in a pretty format.
|
0
|
38 If INFO is omitted, the current profiling info is retrieved using
|
167
|
39 `get-profiling-info'.
|
|
40 If STREAM is omitted, either current buffer or standard output are used,
|
|
41 depending on whether the function was called interactively or not."
|
|
42 (interactive)
|
|
43 (if info
|
|
44 (setq info (copy-alist info))
|
0
|
45 (setq info (get-profiling-info)))
|
167
|
46 (let ((standard-output (or stream (if (interactive-p)
|
|
47 (current-buffer)
|
|
48 standard-output))))
|
|
49 (setq info (nreverse (sort info #'cdr-less-than-cdr)))
|
|
50 (princ "Function Count %\n")
|
|
51 (princ "---------------------------------------------------------------------\n")
|
|
52 (let ((sum 0.0))
|
|
53 (dolist (info2 info)
|
|
54 (incf sum (cdr info2)))
|
|
55 (while info
|
|
56 (let ((f (caar info)))
|
|
57 (princ (format "%-50s%10d %6.3f\n" f (cdar info)
|
|
58 (* 100 (/ (cdar info) sum)))))
|
|
59 (pop info)))))
|
155
|
60
|
165
|
61 ;;;###autoload
|
|
62 (defmacro profile (&rest forms)
|
173
|
63 "Turn on profiling, execute FORMS and restore profiling state.
|
|
64 Profiling state here means that if profiling was not in effect when
|
|
65 PROFILE was called, it will be turned off after FORMS are evaluated.
|
|
66 Otherwise, profiling will be left running.
|
|
67
|
165
|
68 Returns the profiling info, printable by `pretty-print-profiling-info'."
|
|
69 `(progn
|
173
|
70 (if (profiling-active-p)
|
165
|
71 (progn
|
|
72 ,@forms)
|
173
|
73 (unwind-protect
|
|
74 (progn
|
|
75 (start-profiling)
|
|
76 ,@forms)
|
|
77 (stop-profiling)))
|
165
|
78 (get-profiling-info)))
|
|
79
|
|
80 (put 'profile 'lisp-indent-function 0)
|
|
81
|
167
|
82 ;;;###autoload
|
|
83 (defun profile-key-sequence (keys)
|
|
84 "Dispatch the key sequence KEYS and profile the execution.
|
|
85 KEYS can be a vector of keypress events, a keypress event, or a character.
|
|
86 The function returns the profiling info."
|
|
87 (interactive "kProfile keystroke: ")
|
|
88 (and (characterp keys)
|
|
89 (setq keys (character-to-event keys)))
|
|
90 (or (vectorp keys)
|
|
91 (setq keys (vector keys)))
|
|
92 (profile
|
|
93 (mapc 'dispatch-event keys)))
|
|
94
|
155
|
95 ;;; profile.el ends here
|