annotate lisp/obsolete/profile.el @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 375f2633d815
children f9a65d7ebd29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1992, 1994, 1998 Free Software Foundation, Inc.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Boaz Ben-Zvi <boaz@lcs.mit.edu>
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Created: 07 Feb 1992
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Version: 1.0
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Adapted-By: ESR
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; Keywords: lisp, tools
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; 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
14 ;; it under the terms of the GNU General Public License as published by
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; any later version.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; 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
19 ;; 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
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; 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
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; DESCRIPTION:
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; ------------
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; 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
33 ;; 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
34 ;; 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
35 ;; 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
36 ;; 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
37 ;; spent inside BAR is credited to both functions.)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; HOW TO USE:
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; -----------
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; 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
42 ;; (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
43 ;; 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
44 ;; 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
45 ;; 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
46 ;; 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
47 ;; again! ).
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; 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
49 ;;-------------------------------------------------------------------
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; (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
51 ;; sokoban-move-vertical sokoban-move))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; (load "sokoban")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; M-x profile-functions
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; ... I play the sokoban game ..........
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; M-x profile-results
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;;
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; Function Time (Seconds.Useconds)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; ======== =======================
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; sokoban-move 0.539088
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; sokoban-move-vertical 0.410130
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; sokoban-load-game 0.453235
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; sokoban-set-mode-line 1.949203
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;;-----------------------------------------------------
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; 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
65 ;; 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
66 ;; 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
67
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;;; Code:
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
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 ;;; User modifiable VARIABLES
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 (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
75 (defvar profile-buffer "*profile*"
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 "Name of profile buffer.")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (defvar profile-distinct nil
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 "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
79 \(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
80 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
81 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
82
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 ;;; V A R I A B L E S
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 (defvar profile-time-list nil
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 "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
89 Each element looks like (FUN NCALLS SEC . USEC).")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (defvar profile-init-list nil
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 "List of entry time for each function.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 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
93 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
94 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
95 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
96 (defvar profile-max-fun-name 0
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 "Max length of name of any function profiled.")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (defvar profile-call-stack nil
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 "A list of the profiled functions currently executing.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 Used only when profile-distinct is non-nil.")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (defvar profile-last-time nil
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 "The start time of the current time slice.
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
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (defconst profile-million 1000000)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
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 ;;; F U N C T I O N S
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 (defun profile-functions (&optional flist)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 "Profile all the functions listed in `profile-functions-list'.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 With argument FLIST, use the list FLIST instead."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (interactive "P")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (mapcar 'profile-a-function (or flist profile-functions-list)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (defun profile-print (entry)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 "Print one ENTRY (from `profile-time-list')."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (let* ((calls (car (cdr entry)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (timec (cdr (cdr entry)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (avgtime (and (not (zerop calls))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (/ (+ (car timec)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (/ (cdr timec) (float profile-million)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 calls))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (insert (format (concat "%-"
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 (int-to-string profile-max-fun-name)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 "s %7d %10d.%06d")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (car entry) calls (car timec) (cdr timec))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (if (null avgtime)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 "\n"
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (format " %18.6f\n" avgtime)))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (defun profile-results ()
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 "Display profiling results in the buffer `*profile*'.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 \(The buffer name comes from `profile-buffer'.)"
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (interactive)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (switch-to-buffer profile-buffer)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (erase-buffer)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (insert "Function" (make-string (- profile-max-fun-name 6) ? ))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (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
141 (insert (make-string profile-max-fun-name ?=) " ")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (insert "====== ================ =================\n")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (mapcar 'profile-print profile-time-list))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (defun profile-add-time (dest now prev)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 "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
147 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
148 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
149 (let ((sec (+ (car dest)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (* 65536 (- (car now) (car prev)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (- (cadr now) (cadr prev))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (usec (+ (cdr dest)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (- (car (cddr now)) (car (cddr prev))))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (if (< usec 0)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (setq sec (1- sec)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 usec (+ usec profile-million))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (if (>= usec profile-million)
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 (setcar dest sec)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (setcdr dest usec)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (defun profile-function-prolog (fun)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 "Mark the beginning of a call to function FUN."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (if profile-distinct
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (let ((profile-time (current-time)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (if profile-call-stack
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (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
169 profile-time-list)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 profile-time profile-last-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (setq profile-call-stack (cons fun profile-call-stack)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 profile-last-time profile-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (let ((profile-time (current-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (init-time (cdr (assq fun profile-init-list))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (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
176 (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
177 (setcar init-time (1+ (car init-time)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (setcar init-time 1) ; mark first entry
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (setcdr init-time profile-time)))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (defun profile-function-epilog (fun)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 "Mark the end of a call to function FUN."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (if profile-distinct
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (let ((profile-time (current-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (accum (cdr (assq fun profile-time-list))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (setcar accum (1+ (car accum)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (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
188 (setq profile-call-stack (cdr profile-call-stack)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 profile-last-time profile-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (let ((profile-time (current-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (init-time (cdr (assq fun profile-init-list)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (accum (cdr (assq fun profile-time-list))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (if (or (null init-time)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (null accum))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (error "Function %s missing from list" fun))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (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
197 ;; 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
198 (when (zerop (car init-time))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (setcar accum (1+ (car accum)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (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
201
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (defun profile-convert-byte-code (function)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (let ((defn (symbol-function function)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (if (byte-code-function-p defn)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 ;; It is a compiled code object.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (let* ((contents (append defn nil))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (body
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (list (list 'byte-code (nth 1 contents)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (nth 2 contents) (nth 3 contents)))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (if (nthcdr 5 contents)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (setq body (cons (list 'interactive (nth 5 contents)) body)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (if (nth 4 contents)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 ;; Use `documentation' here, to get the actual string,
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 ;; in case the compiled function has a reference
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 ;; to the .elc file.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 (setq body (cons (documentation function) body)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (fset function (cons 'lambda (cons (car contents) body)))))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (defun profile-a-function (fun)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 "Profile the function FUN."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (interactive "aFunction to profile: ")
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (let ((def (symbol-function fun)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (when (eq (car-safe def) 'autoload)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (load (car (cdr def)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (setq def (symbol-function fun)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (fetch-bytecode def))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (profile-convert-byte-code fun)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (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
229 (or (eq (car def) 'lambda)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (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
231 (setq profile-time-list ; add a new entry
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (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
233 (setq profile-init-list ; add a new entry
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (cons (cons fun (cons 0 nil)) profile-init-list))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (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
236 (fset fun (profile-fix-fun fun def))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (defun profile-fix-fun (fun def)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 "Take function FUN and return it fixed for profiling.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 DEF is (symbol-function FUN)."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (if (< (length def) 3)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 def ; nothing to change
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (let ((prefix (list (car def) (car (cdr def))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (suffix (cdr (cdr def))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 ;; Skip the doc string, if there is a string
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 ;; which serves only as a doc string,
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 ;; and put it in PREFIX.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (if (and (stringp (car suffix)) (cdr suffix))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (setq prefix (nconc prefix (list (car suffix)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 suffix (cdr suffix)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 ;; Check for an interactive spec.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 ;; If found, put it into PREFIX and skip it.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (if (and (listp (car suffix))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (eq (car (car suffix)) 'interactive))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (setq prefix (nconc prefix (list (car suffix)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 suffix (cdr suffix)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (if (eq (car-safe (car suffix)) 'profile-function-prolog)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 def ; already profiled
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 ;; Prepare new function definition.
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 ;; 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
261 (nconc prefix
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (list (list 'profile-function-prolog
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (list 'quote fun))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (list 'unwind-protect
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (cons 'progn suffix)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (list 'profile-function-epilog
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (list 'quote fun)))))))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (defun profile-restore-fun (fun)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 "Restore profiled function FUN to its original state."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (let ((def (symbol-function fun)) body index)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 ;; move index beyond header
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (setq index (cdr-safe def))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (if (stringp (car (cdr index)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (setq index (cdr index)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (if (eq (car-safe (car (cdr index))) 'interactive)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (setq index (cdr index)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (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
279 (setcdr index (cdr (car (cdr (car (cdr (cdr index))))))))))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (defun profile-finish ()
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 "Stop profiling functions. Clear all the settings."
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (interactive)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (while profile-time-list
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (profile-restore-fun (car (car profile-time-list)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (setq profile-time-list (cdr profile-time-list)))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (setq profile-max-fun-name 0)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (setq profile-init-list nil))
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (provide 'profile)
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
292 ;;; arch-tag: 816f97e8-efff-4da2-9a95-7bc392f58b19
37278
430eb00d1e9a Moved here from lisp/emacs-lisp/.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 ;;; profile.el ends here