Mercurial > emacs
annotate lisp/obsolete/profile.el @ 94446:24da79778167
(gud-display-line): Only consider visible
frames when looking for source buffer.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Tue, 29 Apr 2008 00:44:47 +0000 |
parents | ee22366f2a68 |
children | 43d30a1ea764 |
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 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify |
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 |
78228
1e016d63f292
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
16 ;; the Free Software Foundation; either version 3, or (at your option) |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
17 ;; any later version. |
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 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
28 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
29 ;;; Commentary: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
30 |
94000
ee22366f2a68
Add a comment giving version of obsolescence.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
31 ;; 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
|
32 |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
33 ;; DESCRIPTION: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
34 ;; ------------ |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
35 ;; 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
|
36 ;; 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
|
37 ;; 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
|
38 ;; 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
|
39 ;; 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
|
40 ;; spent inside BAR is credited to both functions.) |
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 ;; HOW TO USE: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
43 ;; ----------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
44 ;; 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
|
45 ;; (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
|
46 ;; 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
|
47 ;; 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
|
48 ;; 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
|
49 ;; 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
|
50 ;; again! ). |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
51 ;; 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
|
52 ;;------------------------------------------------------------------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
53 ;; (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
|
54 ;; sokoban-move-vertical sokoban-move)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
55 ;; (load "sokoban") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
56 ;; M-x profile-functions |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
57 ;; ... I play the sokoban game .......... |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
58 ;; M-x profile-results |
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 ;; Function Time (Seconds.Useconds) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
61 ;; ======== ======================= |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
62 ;; sokoban-move 0.539088 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
63 ;; sokoban-move-vertical 0.410130 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
64 ;; sokoban-load-game 0.453235 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
65 ;; sokoban-set-mode-line 1.949203 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
66 ;;----------------------------------------------------- |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
67 ;; 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
|
68 ;; 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
|
69 ;; 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
|
70 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
71 ;;; Code: |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
72 |
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 ;;; User modifiable VARIABLES |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
75 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
76 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
77 (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
|
78 (defvar profile-buffer "*profile*" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
79 "Name of profile buffer.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
80 (defvar profile-distinct nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
81 "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
|
82 \(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
|
83 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
|
84 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
|
85 |
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 ;;; V A R I A B L E S |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
88 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
89 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
90 (defvar profile-time-list nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
91 "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
|
92 Each element looks like (FUN NCALLS SEC . USEC).") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
93 (defvar profile-init-list nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
94 "List of entry time for each function. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 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
|
99 (defvar profile-max-fun-name 0 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
100 "Max length of name of any function profiled.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
101 (defvar profile-call-stack nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
102 "A list of the profiled functions currently executing. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
103 Used only when profile-distinct is non-nil.") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
104 (defvar profile-last-time nil |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
105 "The start time of the current time slice. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
106 Used only when profile-distinct is non-nil.") |
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 (defconst profile-million 1000000) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
109 |
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 ;;; F U N C T I O N S |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
112 ;;; |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
113 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
114 (defun profile-functions (&optional flist) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
115 "Profile all the functions listed in `profile-functions-list'. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
116 With argument FLIST, use the list FLIST instead." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
117 (interactive "P") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
118 (mapcar 'profile-a-function (or flist profile-functions-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
119 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
120 (defun profile-print (entry) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
121 "Print one ENTRY (from `profile-time-list')." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
122 (let* ((calls (car (cdr entry))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
123 (timec (cdr (cdr entry))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
124 (avgtime (and (not (zerop calls)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
125 (/ (+ (car timec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
126 (/ (cdr timec) (float profile-million))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
127 calls)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
128 (insert (format (concat "%-" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
129 (int-to-string profile-max-fun-name) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
130 "s %7d %10d.%06d") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
131 (car entry) calls (car timec) (cdr timec)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
132 (if (null avgtime) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
133 "\n" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
134 (format " %18.6f\n" avgtime))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
135 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
136 (defun profile-results () |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
137 "Display profiling results in the buffer `*profile*'. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
138 \(The buffer name comes from `profile-buffer'.)" |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
139 (interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
140 (switch-to-buffer profile-buffer) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
141 (erase-buffer) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
142 (insert "Function" (make-string (- profile-max-fun-name 6) ? )) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
143 (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
|
144 (insert (make-string profile-max-fun-name ?=) " ") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
145 (insert "====== ================ =================\n") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
146 (mapcar 'profile-print profile-time-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
147 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
148 (defun profile-add-time (dest now prev) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
149 "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
|
150 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
|
151 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
|
152 (let ((sec (+ (car dest) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
153 (* 65536 (- (car now) (car prev))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
154 (- (cadr now) (cadr prev)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
155 (usec (+ (cdr dest) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
156 (- (car (cddr now)) (car (cddr prev)))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
157 (if (< usec 0) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
158 (setq sec (1- sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
159 usec (+ usec profile-million)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
160 (if (>= usec profile-million) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
161 (setq sec (1+ sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
162 usec (- usec profile-million)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
163 (setcar dest sec) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
164 (setcdr dest usec))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
165 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
166 (defun profile-function-prolog (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
167 "Mark the beginning of a call to function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
168 (if profile-distinct |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
169 (let ((profile-time (current-time))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
170 (if profile-call-stack |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
171 (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
|
172 profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
173 profile-time profile-last-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
174 (setq profile-call-stack (cons fun profile-call-stack) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
175 profile-last-time profile-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
176 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
177 (init-time (cdr (assq fun profile-init-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
178 (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
|
179 (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
|
180 (setcar init-time (1+ (car init-time))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
181 (setcar init-time 1) ; mark first entry |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
182 (setcdr init-time profile-time))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
183 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
184 (defun profile-function-epilog (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
185 "Mark the end of a call to function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
186 (if profile-distinct |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
187 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
188 (accum (cdr (assq fun profile-time-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
189 (setcar accum (1+ (car accum))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
190 (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
|
191 (setq profile-call-stack (cdr profile-call-stack) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
192 profile-last-time profile-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
193 (let ((profile-time (current-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
194 (init-time (cdr (assq fun profile-init-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
195 (accum (cdr (assq fun profile-time-list)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
196 (if (or (null init-time) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
197 (null accum)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
198 (error "Function %s missing from list" fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
199 (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
|
200 ;; 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
|
201 (when (zerop (car init-time)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
202 (setcar accum (1+ (car accum))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
203 (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
|
204 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
205 (defun profile-convert-byte-code (function) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
206 (let ((defn (symbol-function function))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
207 (if (byte-code-function-p defn) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
208 ;; It is a compiled code object. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
209 (let* ((contents (append defn nil)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
210 (body |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
211 (list (list 'byte-code (nth 1 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
212 (nth 2 contents) (nth 3 contents))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
213 (if (nthcdr 5 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
214 (setq body (cons (list 'interactive (nth 5 contents)) body))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
215 (if (nth 4 contents) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
216 ;; Use `documentation' here, to get the actual string, |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
217 ;; in case the compiled function has a reference |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
218 ;; to the .elc file. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
219 (setq body (cons (documentation function) body))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
220 (fset function (cons 'lambda (cons (car contents) body))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
221 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
222 (defun profile-a-function (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
223 "Profile the function FUN." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
224 (interactive "aFunction to profile: ") |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
225 (let ((def (symbol-function fun))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
226 (when (eq (car-safe def) 'autoload) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
227 (load (car (cdr def))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
228 (setq def (symbol-function fun))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
229 (fetch-bytecode def)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
230 (profile-convert-byte-code fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
231 (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
|
232 (or (eq (car def) 'lambda) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
233 (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
|
234 (setq profile-time-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 (cons 0 0))) profile-time-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
236 (setq profile-init-list ; add a new entry |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
237 (cons (cons fun (cons 0 nil)) profile-init-list)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
238 (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
|
239 (fset fun (profile-fix-fun fun def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
240 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
241 (defun profile-fix-fun (fun def) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
242 "Take function FUN and return it fixed for profiling. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
243 DEF is (symbol-function FUN)." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
244 (if (< (length def) 3) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
245 def ; nothing to change |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
246 (let ((prefix (list (car def) (car (cdr def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
247 (suffix (cdr (cdr def)))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
248 ;; Skip the doc string, if there is a string |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
249 ;; which serves only as a doc string, |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
250 ;; and put it in PREFIX. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
251 (if (and (stringp (car suffix)) (cdr suffix)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
252 (setq prefix (nconc prefix (list (car suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
253 suffix (cdr suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
254 ;; Check for an interactive spec. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
255 ;; If found, put it into PREFIX and skip it. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
256 (if (and (listp (car suffix)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
257 (eq (car (car suffix)) 'interactive)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
258 (setq prefix (nconc prefix (list (car suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
259 suffix (cdr suffix))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
260 (if (eq (car-safe (car suffix)) 'profile-function-prolog) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
261 def ; already profiled |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
262 ;; Prepare new function definition. |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
263 ;; 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
|
264 (nconc prefix |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
265 (list (list 'profile-function-prolog |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
266 (list 'quote fun)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
267 (list 'unwind-protect |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
268 (cons 'progn suffix) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
269 (list 'profile-function-epilog |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
270 (list 'quote fun))))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
271 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
272 (defun profile-restore-fun (fun) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
273 "Restore profiled function FUN to its original state." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
274 (let ((def (symbol-function fun)) body index) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
275 ;; move index beyond header |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
276 (setq index (cdr-safe def)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
277 (if (stringp (car (cdr index))) |
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))) 'interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
280 (setq index (cdr index))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
281 (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
|
282 (setcdr index (cdr (car (cdr (car (cdr (cdr index)))))))))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
283 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
284 (defun profile-finish () |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
285 "Stop profiling functions. Clear all the settings." |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
286 (interactive) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
287 (while profile-time-list |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
288 (profile-restore-fun (car (car profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
289 (setq profile-time-list (cdr profile-time-list))) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
290 (setq profile-max-fun-name 0) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
291 (setq profile-init-list nil)) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
292 |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
293 (provide 'profile) |
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
294 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79715
diff
changeset
|
295 ;; arch-tag: 816f97e8-efff-4da2-9a95-7bc392f58b19 |
37278
430eb00d1e9a
Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff
changeset
|
296 ;;; profile.el ends here |