elp.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. ;;; elp.el --- Emacs Lisp Profiler -*- lexical-binding: t -*-
  2. ;; Copyright (C) 1994-1995, 1997-1998, 2001-2015 Free Software
  3. ;; Foundation, Inc.
  4. ;; Author: Barry A. Warsaw
  5. ;; Maintainer: emacs-devel@gnu.org
  6. ;; Created: 26-Feb-1994
  7. ;; Keywords: debugging lisp tools
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;;
  21. ;; If you want to profile a bunch of functions, set elp-function-list
  22. ;; to the list of symbols, then do a M-x elp-instrument-list. This
  23. ;; hacks those functions so that profiling information is recorded
  24. ;; whenever they are called. To print out the current results, use
  25. ;; M-x elp-results. If you want output to go to standard-output
  26. ;; instead of a separate buffer, setq elp-use-standard-output to
  27. ;; non-nil. With elp-reset-after-results set to non-nil, profiling
  28. ;; information will be reset whenever the results are displayed. You
  29. ;; can also reset all profiling info at any time with M-x
  30. ;; elp-reset-all.
  31. ;;
  32. ;; You can also instrument all functions in a package, provided that
  33. ;; the package follows the GNU coding standard of a common textual
  34. ;; prefix. Use M-x elp-instrument-package for this.
  35. ;;
  36. ;; If you want to sort the results, set elp-sort-by-function to some
  37. ;; predicate function. The three most obvious choices are predefined:
  38. ;; elp-sort-by-call-count, elp-sort-by-average-time, and
  39. ;; elp-sort-by-total-time. Also, you can prune from the output, all
  40. ;; functions that have been called fewer than a given number of times
  41. ;; by setting elp-report-limit.
  42. ;;
  43. ;; Elp can instrument byte-compiled functions just as easily as
  44. ;; interpreted functions, but it cannot instrument macros. However,
  45. ;; when you redefine a function (e.g. with eval-defun), you'll need to
  46. ;; re-instrument it with M-x elp-instrument-function. This will also
  47. ;; reset profiling information for that function. Elp can handle
  48. ;; interactive functions (i.e. commands), but of course any time spent
  49. ;; idling for user prompts will show up in the timing results.
  50. ;;
  51. ;; You can also designate a `master' function. Profiling times will
  52. ;; be gathered for instrumented functions only during execution of
  53. ;; this master function. Thus, if you have some defuns like:
  54. ;;
  55. ;; (defun foo () (do-something-time-intensive))
  56. ;; (defun bar () (foo))
  57. ;; (defun baz () (bar) (foo))
  58. ;;
  59. ;; and you want to find out the amount of time spent in bar and foo,
  60. ;; but only during execution of bar, make bar the master. The call of
  61. ;; foo from baz will not add to foo's total timing sums. Use M-x
  62. ;; elp-set-master and M-x elp-unset-master to utilize this feature.
  63. ;; Only one master function can be set at a time.
  64. ;; You can restore any function's original function definition with
  65. ;; elp-restore-function. The other instrument, restore, and reset
  66. ;; functions are provided for symmetry.
  67. ;; Here is a list of variable you can use to customize elp:
  68. ;; elp-function-list
  69. ;; elp-reset-after-results
  70. ;; elp-sort-by-function
  71. ;; elp-report-limit
  72. ;;
  73. ;; Here is a list of the interactive commands you can use:
  74. ;; elp-instrument-function
  75. ;; elp-restore-function
  76. ;; elp-instrument-list
  77. ;; elp-restore-list
  78. ;; elp-instrument-package
  79. ;; elp-restore-all
  80. ;; elp-reset-function
  81. ;; elp-reset-list
  82. ;; elp-reset-all
  83. ;; elp-set-master
  84. ;; elp-unset-master
  85. ;; elp-results
  86. ;; Note that there are plenty of factors that could make the times
  87. ;; reported unreliable, including the accuracy and granularity of your
  88. ;; system clock, and the overhead spent in lisp calculating and
  89. ;; recording the intervals. I figure the latter is pretty constant,
  90. ;; so while the times may not be entirely accurate, I think they'll
  91. ;; give you a good feel for the relative amount of work spent in the
  92. ;; various lisp routines you are profiling. Note further that times
  93. ;; are calculated using wall-clock time, so other system load will
  94. ;; affect accuracy too.
  95. ;;; Background:
  96. ;; This program was inspired by the only two existing Emacs Lisp
  97. ;; profilers that I'm aware of, Boaz Ben-Zvi's profile.el, and Root
  98. ;; Boy Jim's profiler.el. Both were written for Emacs 18 and both were
  99. ;; pretty good first shots at profiling, but I found that they didn't
  100. ;; provide the functionality or interface that I wanted, so I wrote
  101. ;; this. I've tested elp in XEmacs 19 and Emacs 19. There's no point
  102. ;; in even trying to make this work with Emacs 18.
  103. ;; Unlike previous profilers, elp uses Emacs 19's built-in function
  104. ;; current-time to return interval times. This obviates the need for
  105. ;; both an external C program and Emacs processes to communicate with
  106. ;; such a program, and thus simplifies the package as a whole.
  107. ;; TBD:
  108. ;; Make this act like a real profiler, so that it records time spent
  109. ;; in all branches of execution.
  110. ;;; Code:
  111. (eval-when-compile (require 'cl-lib))
  112. ;; start of user configuration variables
  113. ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  114. (defgroup elp nil
  115. "Emacs Lisp Profiler."
  116. :group 'lisp)
  117. (defcustom elp-function-list nil
  118. "List of functions to profile.
  119. Used by the command `elp-instrument-list'."
  120. :type '(repeat function)
  121. :group 'elp)
  122. (defcustom elp-reset-after-results t
  123. "Non-nil means reset all profiling info after results are displayed.
  124. Results are displayed with the `elp-results' command."
  125. :type 'boolean
  126. :group 'elp)
  127. (defcustom elp-sort-by-function 'elp-sort-by-total-time
  128. "Non-nil specifies ELP results sorting function.
  129. These functions are currently available:
  130. `elp-sort-by-call-count' -- sort by the highest call count
  131. `elp-sort-by-total-time' -- sort by the highest total time
  132. `elp-sort-by-average-time' -- sort by the highest average times
  133. You can write your own sort function. It should adhere to the
  134. interface specified by the PREDICATE argument for `sort'.
  135. Each \"element of LIST\" is really a 4 element vector where element 0 is
  136. the call count, element 1 is the total time spent in the function,
  137. element 2 is the average time spent in the function, and element 3 is
  138. the symbol's name string."
  139. :type 'function
  140. :group 'elp)
  141. (defcustom elp-report-limit 1
  142. "Prevent some functions from being displayed in the results buffer.
  143. If a number, no function that has been called fewer than that number
  144. of times will be displayed in the output buffer. If nil, all
  145. functions will be displayed."
  146. :type '(choice integer
  147. (const :tag "Show All" nil))
  148. :group 'elp)
  149. (defcustom elp-use-standard-output nil
  150. "If non-nil, output to `standard-output' instead of a buffer."
  151. :type 'boolean
  152. :group 'elp)
  153. (defcustom elp-recycle-buffers-p t
  154. "If nil, don't recycle the `elp-results-buffer'.
  155. In other words, a new unique buffer is create every time you run
  156. \\[elp-results]."
  157. :type 'boolean
  158. :group 'elp)
  159. ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  160. ;; end of user configuration variables
  161. (defvar elp-results-buffer "*ELP Profiling Results*"
  162. "Buffer name for outputting profiling results.")
  163. (defconst elp-timer-info-property 'elp-info
  164. "ELP information property name.")
  165. (defvar elp-record-p t
  166. "Controls whether functions should record times or not.
  167. This variable is set by the master function.")
  168. (defvar elp-master nil
  169. "Master function symbol.")
  170. (defvar elp-not-profilable
  171. ;; First, the functions used inside each instrumented function:
  172. '(called-interactively-p
  173. ;; Then the functions used by the above functions. I used
  174. ;; (delq nil (mapcar (lambda (x) (and (symbolp x) (fboundp x) x))
  175. ;; (aref (symbol-function 'elp-wrapper) 2)))
  176. ;; to help me find this list.
  177. error call-interactively apply current-time
  178. ;; Andreas Politz reports problems profiling these (Bug#4233):
  179. + byte-code-function-p functionp byte-code subrp
  180. indirect-function fboundp)
  181. "List of functions that cannot be profiled.
  182. Those functions are used internally by the profiling code and profiling
  183. them would thus lead to infinite recursion.")
  184. (defun elp-profilable-p (fun)
  185. (and (symbolp fun)
  186. (fboundp fun)
  187. (not (or (memq fun elp-not-profilable)
  188. (keymapp fun)
  189. (autoloadp (symbol-function fun)) ;FIXME: Why not just load it?
  190. (special-form-p fun)))))
  191. (defconst elp--advice-name 'ELP-instrumentation\ )
  192. ;;;###autoload
  193. (defun elp-instrument-function (funsym)
  194. "Instrument FUNSYM for profiling.
  195. FUNSYM must be a symbol of a defined function."
  196. (interactive "aFunction to instrument: ")
  197. (let* ((infovec (vector 0 0)))
  198. ;; We cannot profile functions used internally during profiling.
  199. (unless (elp-profilable-p funsym)
  200. (error "ELP cannot profile the function: %s" funsym))
  201. ;; The info vector data structure is a 2 element vector. The 0th
  202. ;; element is the call-count, i.e. the total number of times this
  203. ;; function has been entered. This value is bumped up on entry to
  204. ;; the function so that non-local exists are still recorded. TBD:
  205. ;; I haven't tested non-local exits at all, so no guarantees.
  206. ;;
  207. ;; The 1st element is the total amount of time in seconds that has
  208. ;; been spent inside this function. This number is added to on
  209. ;; function exit.
  210. ;; Put the info vector on the property list.
  211. (put funsym elp-timer-info-property infovec)
  212. ;; Set the symbol's new profiling function definition to run
  213. ;; ELP wrapper.
  214. (advice-add funsym :around (elp--make-wrapper funsym)
  215. `((name . ,elp--advice-name) (depth . -99)))))
  216. (defun elp--instrumented-p (sym)
  217. (advice-member-p elp--advice-name sym))
  218. (defun elp-restore-function (funsym)
  219. "Restore an instrumented function to its original definition.
  220. Argument FUNSYM is the symbol of a defined function."
  221. (interactive
  222. (list
  223. (intern
  224. (completing-read "Function to restore: " obarray
  225. #'elp--instrumented-p t))))
  226. ;; If the function was the master, reset the master.
  227. (if (eq funsym elp-master)
  228. (setq elp-master nil
  229. elp-record-p t))
  230. ;; Zap the properties.
  231. (put funsym elp-timer-info-property nil)
  232. (advice-remove funsym elp--advice-name))
  233. ;;;###autoload
  234. (defun elp-instrument-list (&optional list)
  235. "Instrument, for profiling, all functions in `elp-function-list'.
  236. Use optional LIST if provided instead.
  237. If called interactively, read LIST using the minibuffer."
  238. (interactive "PList of functions to instrument: ") ;FIXME: Doesn't work?!
  239. (unless (listp list)
  240. (signal 'wrong-type-argument (list 'listp list)))
  241. (mapcar #'elp-instrument-function (or list elp-function-list)))
  242. ;;;###autoload
  243. (defun elp-instrument-package (prefix)
  244. "Instrument for profiling, all functions which start with PREFIX.
  245. For example, to instrument all ELP functions, do the following:
  246. \\[elp-instrument-package] RET elp- RET"
  247. (interactive
  248. (list (completing-read "Prefix of package to instrument: "
  249. obarray 'elp-profilable-p)))
  250. (if (zerop (length prefix))
  251. (error "Instrumenting all Emacs functions would render Emacs unusable"))
  252. (elp-instrument-list
  253. (mapcar
  254. 'intern
  255. (all-completions prefix obarray 'elp-profilable-p))))
  256. (defun elp-restore-list (&optional list)
  257. "Restore the original definitions for all functions in `elp-function-list'.
  258. Use optional LIST if provided instead."
  259. (interactive "PList of functions to restore: ") ;FIXME: Doesn't work!?
  260. (mapcar #'elp-restore-function (or list elp-function-list)))
  261. (defun elp-restore-all ()
  262. "Restore the original definitions of all functions being profiled."
  263. (interactive)
  264. (mapatoms #'elp-restore-function))
  265. (defun elp-reset-function (funsym)
  266. "Reset the profiling information for FUNSYM."
  267. (interactive "aFunction to reset: ")
  268. (let ((info (get funsym elp-timer-info-property)))
  269. (or info
  270. (error "%s is not instrumented for profiling" funsym))
  271. (aset info 0 0) ;reset call counter
  272. (aset info 1 0.0) ;reset total time
  273. ;; don't muck with aref 2 as that is the old symbol definition
  274. ))
  275. (defun elp-reset-list (&optional list)
  276. "Reset the profiling information for all functions in `elp-function-list'.
  277. Use optional LIST if provided instead."
  278. (interactive "PList of functions to reset: ") ;FIXME: Doesn't work!?
  279. (let ((list (or list elp-function-list)))
  280. (mapcar 'elp-reset-function list)))
  281. (defun elp-reset-all ()
  282. "Reset the profiling information for all functions being profiled."
  283. (interactive)
  284. (mapatoms (lambda (sym)
  285. (if (get sym elp-timer-info-property)
  286. (elp-reset-function sym)))))
  287. (defun elp-set-master (funsym)
  288. "Set the master function for profiling."
  289. (interactive
  290. (list
  291. (intern
  292. (completing-read "Master function: " obarray
  293. #'elp--instrumented-p
  294. t nil nil (if elp-master (symbol-name elp-master))))))
  295. ;; When there's a master function, recording is turned off by default.
  296. (setq elp-master funsym
  297. elp-record-p nil)
  298. ;; Make sure master function is instrumented.
  299. (or (elp--instrumented-p funsym)
  300. (elp-instrument-function funsym)))
  301. (defun elp-unset-master ()
  302. "Unset the master function."
  303. (interactive)
  304. ;; When there's no master function, recording is turned on by default.
  305. (setq elp-master nil
  306. elp-record-p t))
  307. (defsubst elp-elapsed-time (start end)
  308. (float-time (time-subtract end start)))
  309. (defun elp--make-wrapper (funsym)
  310. "Make the piece of advice that instruments FUNSYM."
  311. (lambda (func &rest args)
  312. "This function has been instrumented for profiling by the ELP.
  313. ELP is the Emacs Lisp Profiler. To restore the function to its
  314. original definition, use \\[elp-restore-function] or \\[elp-restore-all]."
  315. ;; turn on recording if this is the master function
  316. (if (and elp-master
  317. (eq funsym elp-master))
  318. (setq elp-record-p t))
  319. ;; get info vector and original function symbol
  320. (let* ((info (get funsym elp-timer-info-property))
  321. result)
  322. (or func
  323. (error "%s is not instrumented for profiling" funsym))
  324. (if (not elp-record-p)
  325. ;; when not recording, just call the original function symbol
  326. ;; and return the results.
  327. (setq result (apply func args))
  328. ;; we are recording times
  329. (let (enter-time exit-time)
  330. ;; increment the call-counter
  331. (cl-incf (aref info 0))
  332. (setq enter-time (current-time)
  333. result (apply func args)
  334. exit-time (current-time))
  335. ;; calculate total time in function
  336. (cl-incf (aref info 1) (elp-elapsed-time enter-time exit-time))
  337. ))
  338. ;; turn off recording if this is the master function
  339. (if (and elp-master
  340. (eq funsym elp-master))
  341. (setq elp-record-p nil))
  342. result)))
  343. ;; shut the byte-compiler up
  344. (defvar elp-field-len nil)
  345. (defvar elp-cc-len nil)
  346. (defvar elp-at-len nil)
  347. (defvar elp-et-len nil)
  348. (defun elp-sort-by-call-count (vec1 vec2)
  349. ;; sort by highest call count. See `sort'.
  350. (>= (aref vec1 0) (aref vec2 0)))
  351. (defun elp-sort-by-total-time (vec1 vec2)
  352. ;; sort by highest total time spent in function. See `sort'.
  353. (>= (aref vec1 1) (aref vec2 1)))
  354. (defun elp-sort-by-average-time (vec1 vec2)
  355. ;; sort by highest average time spent in function. See `sort'.
  356. (>= (aref vec1 2) (aref vec2 2)))
  357. (defsubst elp-pack-number (number width)
  358. ;; pack the NUMBER string into WIDTH characters, watching out for
  359. ;; very small or large numbers
  360. (if (<= (length number) width)
  361. number
  362. ;; check for very large or small numbers
  363. (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
  364. (concat (substring
  365. (match-string 1 number)
  366. 0
  367. (- width (match-end 2) (- (match-beginning 2)) 3))
  368. "..."
  369. (match-string 2 number))
  370. (substring number 0 width))))
  371. (defun elp-output-result (resultvec)
  372. ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or
  373. ;; more element vector where aref 0 is the call count, aref 1 is the
  374. ;; total time spent in the function, aref 2 is the average time
  375. ;; spent in the function, and aref 3 is the symbol's string
  376. ;; name. All other elements in the vector are ignored.
  377. (let* ((cc (aref resultvec 0))
  378. (tt (aref resultvec 1))
  379. (at (aref resultvec 2))
  380. (symname (aref resultvec 3))
  381. callcnt totaltime avetime)
  382. (setq callcnt (number-to-string cc)
  383. totaltime (number-to-string tt)
  384. avetime (number-to-string at))
  385. ;; possibly prune the results
  386. (if (and elp-report-limit
  387. (numberp elp-report-limit)
  388. (< cc elp-report-limit))
  389. nil
  390. (elp-output-insert-symname symname)
  391. (insert-char 32 (+ elp-field-len (- (length symname)) 2))
  392. ;; print stuff out, formatting it nicely
  393. (insert callcnt)
  394. (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2))
  395. (let ((ttstr (elp-pack-number totaltime elp-et-len))
  396. (atstr (elp-pack-number avetime elp-at-len)))
  397. (insert ttstr)
  398. (insert-char 32 (+ elp-et-len (- (length ttstr)) 2))
  399. (insert atstr))
  400. (insert "\n"))))
  401. (defvar elp-results-symname-map
  402. (let ((map (make-sparse-keymap)))
  403. (define-key map [mouse-2] 'elp-results-jump-to-definition)
  404. (define-key map [follow-link] 'mouse-face)
  405. (define-key map "\C-m" 'elp-results-jump-to-definition)
  406. map)
  407. "Keymap used on the function name column." )
  408. (defun elp-results-jump-to-definition (&optional event)
  409. "Jump to the definition of the function under the point."
  410. (interactive (list last-nonmenu-event))
  411. (if event (posn-set-point (event-end event)))
  412. (find-function (get-text-property (point) 'elp-symname)))
  413. (defun elp-output-insert-symname (symname)
  414. ;; Insert SYMNAME with text properties.
  415. (insert (propertize symname
  416. 'elp-symname (intern symname)
  417. 'keymap elp-results-symname-map
  418. 'mouse-face 'highlight
  419. 'face 'link
  420. 'help-echo "mouse-2 or RET jumps to definition")))
  421. ;;;###autoload
  422. (defun elp-results ()
  423. "Display current profiling results.
  424. If `elp-reset-after-results' is non-nil, then current profiling
  425. information for all instrumented functions is reset after results are
  426. displayed."
  427. (interactive)
  428. (let ((curbuf (current-buffer))
  429. (resultsbuf (if elp-recycle-buffers-p
  430. (get-buffer-create elp-results-buffer)
  431. (generate-new-buffer elp-results-buffer))))
  432. (set-buffer resultsbuf)
  433. (erase-buffer)
  434. ;; get the length of the longest function name being profiled
  435. (let* ((longest 0)
  436. (title "Function Name")
  437. (titlelen (length title))
  438. (elp-field-len titlelen)
  439. (cc-header "Call Count")
  440. (elp-cc-len (length cc-header))
  441. (et-header "Elapsed Time")
  442. (elp-et-len (length et-header))
  443. (at-header "Average Time")
  444. (elp-at-len (length at-header))
  445. (resvec '())
  446. ) ; end let*
  447. (mapatoms
  448. (lambda (funsym)
  449. (when (elp--instrumented-p funsym)
  450. (let* ((info (get funsym elp-timer-info-property))
  451. (symname (format "%s" funsym))
  452. (cc (aref info 0))
  453. (tt (aref info 1)))
  454. (if (not info)
  455. (insert "No profiling information found for: "
  456. symname)
  457. (setq longest (max longest (length symname)))
  458. (push
  459. (vector cc tt (if (zerop cc)
  460. 0.0 ;avoid arithmetic div-by-zero errors
  461. (/ (float tt) (float cc)))
  462. symname)
  463. resvec))))))
  464. ;; If printing to stdout, insert the header so it will print.
  465. ;; Otherwise use header-line-format.
  466. (setq elp-field-len (max titlelen longest))
  467. (if (or elp-use-standard-output noninteractive)
  468. (progn
  469. (insert title)
  470. (if (> longest titlelen)
  471. (progn
  472. (insert-char 32 (- longest titlelen))))
  473. (insert " " cc-header " " et-header " " at-header "\n")
  474. (insert-char ?= elp-field-len)
  475. (insert " ")
  476. (insert-char ?= elp-cc-len)
  477. (insert " ")
  478. (insert-char ?= elp-et-len)
  479. (insert " ")
  480. (insert-char ?= elp-at-len)
  481. (insert "\n"))
  482. (let ((column 0))
  483. (setq header-line-format
  484. (mapconcat
  485. (lambda (title)
  486. (prog1
  487. (concat
  488. (propertize " "
  489. 'display (list 'space :align-to column)
  490. 'face 'fixed-pitch)
  491. title)
  492. (setq column (+ column 2
  493. (if (= column 0)
  494. elp-field-len
  495. (length title))))))
  496. (list title cc-header et-header at-header) ""))))
  497. ;; if sorting is enabled, then sort the results list. in either
  498. ;; case, call elp-output-result to output the result in the
  499. ;; buffer
  500. (if elp-sort-by-function
  501. (setq resvec (sort resvec elp-sort-by-function)))
  502. (mapc 'elp-output-result resvec))
  503. ;; now pop up results buffer
  504. (set-buffer curbuf)
  505. (pop-to-buffer resultsbuf)
  506. ;; copy results to standard-output?
  507. (if (or elp-use-standard-output noninteractive)
  508. (princ (buffer-substring (point-min) (point-max)))
  509. (goto-char (point-min)))
  510. ;; reset profiling info if desired
  511. (and elp-reset-after-results
  512. (elp-reset-all))))
  513. (defun elp-unload-function ()
  514. "Unload the Emacs Lisp Profiler."
  515. (elp-restore-all)
  516. ;; continue standard unloading
  517. nil)
  518. (provide 'elp)
  519. ;;; elp.el ends here