Mercurial > emacs
annotate lisp/obsolete/profile.el @ 95200:fd38f2fd3d08
(font-show-log): Limit each listing
to 20 items.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 22 May 2008 12:49:36 +0000 |
parents | 43d30a1ea764 |
children |
rev | line source |
---|---|
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
1 ;;; profile.el --- Emacs profiler (OBSOLETE; use elp.el instead) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
2 |
74509 | 3 ;; Copyright (C) 1992, 1994, 1998, 2001, 2002, 2003, 2004, |
79715 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
5 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
6 ;; Author: Boaz Ben-Zvi <boaz@lcs.mit.edu> |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
7 ;; Created: 07 Feb 1992 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
8 ;; Version: 1.0 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
9 ;; Adapted-By: ESR |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
10 ;; Keywords: lisp, tools |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
11 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
12 ;; This file is part of GNU Emacs. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
13 |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
15 ;; it under the terms of the GNU General Public License as published by |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
17 ;; (at your option) any later version. |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
18 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
19 ;; GNU Emacs is distributed in the hope that it will be useful, |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
22 ;; GNU General Public License for more details. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
23 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
24 ;; You should have received a copy of the GNU General Public License |
94667
43d30a1ea764
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94000
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
26 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
27 ;;; Commentary: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
28 |
94000
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
29 ;; This file has been obsolete since Emacs 21.1. |
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
30 |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
31 ;; DESCRIPTION: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
32 ;; ------------ |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
33 ;; This program can be used to monitor running time performance of Emacs Lisp |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
34 ;; functions. It takes a list of functions and report the real time spent |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
35 ;; inside these functions. (Actually, for each function it reports the amount |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
36 ;; of time spent while at least one instance of that function is on the call |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
37 ;; stack. So if profiled function FOO calls profiled function BAR, the time |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
38 ;; spent inside BAR is credited to both functions.) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
39 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
40 ;; HOW TO USE: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
41 ;; ----------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
42 ;; Set the variable profile-functions-list to the list of functions |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
43 ;; (as symbols) You want to profile. Call M-x profile-functions to set |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
44 ;; this list on and start using your program. Note that profile-functions |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
45 ;; MUST be called AFTER all the functions in profile-functions-list have |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
46 ;; been loaded !! (This call modifies the code of the profiled functions. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
47 ;; Hence if you reload these functions, you need to call profile-functions |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
48 ;; again! ). |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
49 ;; To display the results do M-x profile-results . For example: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
50 ;;------------------------------------------------------------------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
51 ;; (setq profile-functions-list '(sokoban-set-mode-line sokoban-load-game |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
52 ;; sokoban-move-vertical sokoban-move)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
53 ;; (load "sokoban") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
54 ;; M-x profile-functions |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
55 ;; ... I play the sokoban game .......... |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
56 ;; M-x profile-results |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
57 ;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
58 ;; Function Time (Seconds.Useconds) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
59 ;; ======== ======================= |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
60 ;; sokoban-move 0.539088 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
61 ;; sokoban-move-vertical 0.410130 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
62 ;; sokoban-load-game 0.453235 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
63 ;; sokoban-set-mode-line 1.949203 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
64 ;;----------------------------------------------------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
65 ;; To clear all the settings to profile use profile-finish. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
66 ;; To set one function at a time (instead of or in addition to setting the |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
67 ;; above list and M-x profile-functions) use M-x profile-a-function. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
68 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
69 ;;; Code: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
70 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
71 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
72 ;;; User modifiable VARIABLES |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
73 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
74 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
75 (defvar profile-functions-list nil "*List of functions to profile.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
76 (defvar profile-buffer "*profile*" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
77 "Name of profile buffer.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
78 (defvar profile-distinct nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
79 "If non-nil, each time slice gets credited to at most one function. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
80 \(Namely, the most recent one in the call stack.) If nil, then the |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
81 time reported for a function includes the entire time from beginning |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
82 to end, even if it called some other function that was also profiled.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
83 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
84 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
85 ;;; V A R I A B L E S |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
86 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
87 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
88 (defvar profile-time-list nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
89 "List of cumulative calls and time for each profiled function. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
90 Each element looks like (FUN NCALLS SEC . USEC).") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
91 (defvar profile-init-list nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
92 "List of entry time for each function. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
93 Both how many times invoked and real time of start. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
94 Each element looks like (FUN DEPTH HISEC LOSEC USEC), where DEPTH is |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
95 the current recursion depth, and HISEC, LOSEC, and USEC represent the |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
96 starting time of the call (or of the outermost recursion).") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
97 (defvar profile-max-fun-name 0 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
98 "Max length of name of any function profiled.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
99 (defvar profile-call-stack nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
100 "A list of the profiled functions currently executing. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
101 Used only when profile-distinct is non-nil.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
102 (defvar profile-last-time nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
103 "The start time of the current time slice. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
104 Used only when profile-distinct is non-nil.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
105 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
106 (defconst profile-million 1000000) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
107 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
108 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
109 ;;; F U N C T I O N S |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
110 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
111 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
112 (defun profile-functions (&optional flist) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
113 "Profile all the functions listed in `profile-functions-list'. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
114 With argument FLIST, use the list FLIST instead." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
115 (interactive "P") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
116 (mapcar 'profile-a-function (or flist profile-functions-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
117 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
118 (defun profile-print (entry) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
119 "Print one ENTRY (from `profile-time-list')." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
120 (let* ((calls (car (cdr entry))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
121 (timec (cdr (cdr entry))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
122 (avgtime (and (not (zerop calls)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
123 (/ (+ (car timec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
124 (/ (cdr timec) (float profile-million))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
125 calls)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
126 (insert (format (concat "%-" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
127 (int-to-string profile-max-fun-name) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
128 "s %7d %10d.%06d") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
129 (car entry) calls (car timec) (cdr timec)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
130 (if (null avgtime) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
131 "\n" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
132 (format " %18.6f\n" avgtime))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
133 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
134 (defun profile-results () |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
135 "Display profiling results in the buffer `*profile*'. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
136 \(The buffer name comes from `profile-buffer'.)" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
137 (interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
138 (switch-to-buffer profile-buffer) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
139 (erase-buffer) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
140 (insert "Function" (make-string (- profile-max-fun-name 6) ? )) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
141 (insert " Calls Total time (sec) Avg time per call\n") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
142 (insert (make-string profile-max-fun-name ?=) " ") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
143 (insert "====== ================ =================\n") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
144 (mapcar 'profile-print profile-time-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
145 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
146 (defun profile-add-time (dest now prev) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
147 "Add to DEST the difference between timestamps NOW and PREV. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
148 DEST is a pair (SEC . USEC) which is modified in place. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
149 NOW and PREV are triples as returned by `current-time'." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
150 (let ((sec (+ (car dest) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
151 (* 65536 (- (car now) (car prev))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
152 (- (cadr now) (cadr prev)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
153 (usec (+ (cdr dest) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
154 (- (car (cddr now)) (car (cddr prev)))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
155 (if (< usec 0) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
156 (setq sec (1- sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
157 usec (+ usec profile-million)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
158 (if (>= usec profile-million) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
159 (setq sec (1+ sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
160 usec (- usec profile-million)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
161 (setcar dest sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
162 (setcdr dest usec))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
163 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
164 (defun profile-function-prolog (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
165 "Mark the beginning of a call to function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
166 (if profile-distinct |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
167 (let ((profile-time (current-time))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
168 (if profile-call-stack |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
169 (profile-add-time (cdr (cdr (assq (car profile-call-stack) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
170 profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
171 profile-time profile-last-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
172 (setq profile-call-stack (cons fun profile-call-stack) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
173 profile-last-time profile-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
174 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
175 (init-time (cdr (assq fun profile-init-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
176 (if (null init-time) (error "Function %s missing from list" fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
177 (if (not (zerop (car init-time)));; is it a recursive call ? |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
178 (setcar init-time (1+ (car init-time))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
179 (setcar init-time 1) ; mark first entry |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
180 (setcdr init-time profile-time))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
181 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
182 (defun profile-function-epilog (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
183 "Mark the end of a call to function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
184 (if profile-distinct |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
185 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
186 (accum (cdr (assq fun profile-time-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
187 (setcar accum (1+ (car accum))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
188 (profile-add-time (cdr accum) profile-time profile-last-time) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
189 (setq profile-call-stack (cdr profile-call-stack) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
190 profile-last-time profile-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
191 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
192 (init-time (cdr (assq fun profile-init-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
193 (accum (cdr (assq fun profile-time-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
194 (if (or (null init-time) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
195 (null accum)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
196 (error "Function %s missing from list" fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
197 (setcar init-time (1- (car init-time))) ; pop one level in recursion |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
198 ;; Update only if we've finished the outermost recursive call |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
199 (when (zerop (car init-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
200 (setcar accum (1+ (car accum))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
201 (profile-add-time (cdr accum) profile-time (cdr init-time)))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
202 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
203 (defun profile-convert-byte-code (function) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
204 (let ((defn (symbol-function function))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
205 (if (byte-code-function-p defn) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
206 ;; It is a compiled code object. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
207 (let* ((contents (append defn nil)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
208 (body |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
209 (list (list 'byte-code (nth 1 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
210 (nth 2 contents) (nth 3 contents))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
211 (if (nthcdr 5 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
212 (setq body (cons (list 'interactive (nth 5 contents)) body))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
213 (if (nth 4 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
214 ;; Use `documentation' here, to get the actual string, |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
215 ;; in case the compiled function has a reference |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
216 ;; to the .elc file. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
217 (setq body (cons (documentation function) body))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
218 (fset function (cons 'lambda (cons (car contents) body))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
219 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
220 (defun profile-a-function (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
221 "Profile the function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
222 (interactive "aFunction to profile: ") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
223 (let ((def (symbol-function fun))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
224 (when (eq (car-safe def) 'autoload) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
225 (load (car (cdr def))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
226 (setq def (symbol-function fun))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
227 (fetch-bytecode def)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
228 (profile-convert-byte-code fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
229 (let ((def (symbol-function fun)) (funlen (length (symbol-name fun)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
230 (or (eq (car def) 'lambda) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
231 (error "To profile: %s must be a user-defined function" fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
232 (setq profile-time-list ; add a new entry |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
233 (cons (cons fun (cons 0 (cons 0 0))) profile-time-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
234 (setq profile-init-list ; add a new entry |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
235 (cons (cons fun (cons 0 nil)) profile-init-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
236 (if (< profile-max-fun-name funlen) (setq profile-max-fun-name funlen)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
237 (fset fun (profile-fix-fun fun def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
238 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
239 (defun profile-fix-fun (fun def) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
240 "Take function FUN and return it fixed for profiling. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
241 DEF is (symbol-function FUN)." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
242 (if (< (length def) 3) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
243 def ; nothing to change |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
244 (let ((prefix (list (car def) (car (cdr def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
245 (suffix (cdr (cdr def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
246 ;; Skip the doc string, if there is a string |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
247 ;; which serves only as a doc string, |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
248 ;; and put it in PREFIX. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
249 (if (and (stringp (car suffix)) (cdr suffix)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
250 (setq prefix (nconc prefix (list (car suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
251 suffix (cdr suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
252 ;; Check for an interactive spec. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
253 ;; If found, put it into PREFIX and skip it. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
254 (if (and (listp (car suffix)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
255 (eq (car (car suffix)) 'interactive)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
256 (setq prefix (nconc prefix (list (car suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
257 suffix (cdr suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
258 (if (eq (car-safe (car suffix)) 'profile-function-prolog) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
259 def ; already profiled |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
260 ;; Prepare new function definition. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
261 ;; If you change this structure, also change profile-restore-fun. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
262 (nconc prefix |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
263 (list (list 'profile-function-prolog |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
264 (list 'quote fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
265 (list 'unwind-protect |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
266 (cons 'progn suffix) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
267 (list 'profile-function-epilog |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
268 (list 'quote fun))))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
269 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
270 (defun profile-restore-fun (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
271 "Restore profiled function FUN to its original state." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
272 (let ((def (symbol-function fun)) body index) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
273 ;; move index beyond header |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
274 (setq index (cdr-safe def)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
275 (if (stringp (car (cdr index))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
276 (setq index (cdr index))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
277 (if (eq (car-safe (car (cdr index))) 'interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
278 (setq index (cdr index))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
279 (if (eq (car-safe (car (cdr index))) 'profile-function-prolog) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
280 (setcdr index (cdr (car (cdr (car (cdr (cdr index)))))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
281 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
282 (defun profile-finish () |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
283 "Stop profiling functions. Clear all the settings." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
284 (interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
285 (while profile-time-list |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
286 (profile-restore-fun (car (car profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
287 (setq profile-time-list (cdr profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
288 (setq profile-max-fun-name 0) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
289 (setq profile-init-list nil)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
290 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
291 (provide 'profile) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
292 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79715
diff
changeset
|
293 ;; arch-tag: 816f97e8-efff-4da2-9a95-7bc392f58b19 |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
294 ;;; profile.el ends here |