| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
(defgroup elp nil |
|---|
| 134 |
"Emacs Lisp Profiler." |
|---|
| 135 |
:group 'lisp) |
|---|
| 136 |
|
|---|
| 137 |
(defcustom elp-function-list nil |
|---|
| 138 |
"*List of functions to profile. |
|---|
| 139 |
Used by the command `elp-instrument-list'." |
|---|
| 140 |
:type '(repeat function) |
|---|
| 141 |
:group 'elp) |
|---|
| 142 |
|
|---|
| 143 |
(defcustom elp-reset-after-results t |
|---|
| 144 |
"*Non-nil means reset all profiling info after results are displayed. |
|---|
| 145 |
Results are displayed with the `elp-results' command." |
|---|
| 146 |
:type 'boolean |
|---|
| 147 |
:group 'elp) |
|---|
| 148 |
|
|---|
| 149 |
(defcustom elp-sort-by-function 'elp-sort-by-total-time |
|---|
| 150 |
"*Non-nil specifies ELP results sorting function. |
|---|
| 151 |
These functions are currently available: |
|---|
| 152 |
|
|---|
| 153 |
elp-sort-by-call-count -- sort by the highest call count |
|---|
| 154 |
elp-sort-by-total-time -- sort by the highest total time |
|---|
| 155 |
elp-sort-by-average-time -- sort by the highest average times |
|---|
| 156 |
|
|---|
| 157 |
You can write your own sort function. It should adhere to the |
|---|
| 158 |
interface specified by the PREDICATE argument for `sort'. |
|---|
| 159 |
Each \"element of LIST\" is really a 4 element vector where element 0 is |
|---|
| 160 |
the call count, element 1 is the total time spent in the function, |
|---|
| 161 |
element 2 is the average time spent in the function, and element 3 is |
|---|
| 162 |
the symbol's name string." |
|---|
| 163 |
:type 'function |
|---|
| 164 |
:group 'elp) |
|---|
| 165 |
|
|---|
| 166 |
(defcustom elp-report-limit 1 |
|---|
| 167 |
"*Prevent some functions from being displayed in the results buffer. |
|---|
| 168 |
If a number, no function that has been called fewer than that number |
|---|
| 169 |
of times will be displayed in the output buffer. If nil, all |
|---|
| 170 |
functions will be displayed." |
|---|
| 171 |
:type '(choice integer |
|---|
| 172 |
(const :tag "Show All" nil)) |
|---|
| 173 |
:group 'elp) |
|---|
| 174 |
|
|---|
| 175 |
(defcustom elp-use-standard-output nil |
|---|
| 176 |
"*If non-nil, output to `standard-output' instead of a buffer." |
|---|
| 177 |
:type 'boolean |
|---|
| 178 |
:group 'elp) |
|---|
| 179 |
|
|---|
| 180 |
(defcustom elp-recycle-buffers-p t |
|---|
| 181 |
"*If nil, don't recycle the `elp-results-buffer'. |
|---|
| 182 |
In other words, a new unique buffer is create every time you run |
|---|
| 183 |
\\[elp-results]." |
|---|
| 184 |
:type 'boolean |
|---|
| 185 |
:group 'elp) |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
(defvar elp-results-buffer "*ELP Profiling Results*" |
|---|
| 193 |
"Buffer name for outputting profiling results.") |
|---|
| 194 |
|
|---|
| 195 |
(defconst elp-timer-info-property 'elp-info |
|---|
| 196 |
"ELP information property name.") |
|---|
| 197 |
|
|---|
| 198 |
(defvar elp-all-instrumented-list nil |
|---|
| 199 |
"List of all functions currently being instrumented.") |
|---|
| 200 |
|
|---|
| 201 |
(defvar elp-record-p t |
|---|
| 202 |
"Controls whether functions should record times or not. |
|---|
| 203 |
This variable is set by the master function.") |
|---|
| 204 |
|
|---|
| 205 |
(defvar elp-master nil |
|---|
| 206 |
"Master function symbol.") |
|---|
| 207 |
|
|---|
| 208 |
(defvar elp-not-profilable |
|---|
| 209 |
|
|---|
| 210 |
'(elp-wrapper called-interactively-p |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
error call-interactively apply current-time) |
|---|
| 216 |
"List of functions that cannot be profiled. |
|---|
| 217 |
Those functions are used internally by the profiling code and profiling |
|---|
| 218 |
them would thus lead to infinite recursion.") |
|---|
| 219 |
|
|---|
| 220 |
(defun elp-profilable-p (fun) |
|---|
| 221 |
(and (symbolp fun) |
|---|
| 222 |
(fboundp fun) |
|---|
| 223 |
(not (or (memq fun elp-not-profilable) |
|---|
| 224 |
(keymapp fun) |
|---|
| 225 |
(memq (car-safe (symbol-function fun)) '(autoload macro)) |
|---|
| 226 |
(condition-case nil |
|---|
| 227 |
(when (subrp (indirect-function fun)) |
|---|
| 228 |
(eq 'unevalled |
|---|
| 229 |
(cdr (subr-arity (indirect-function fun))))) |
|---|
| 230 |
(error nil)))))) |
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
(defun elp-instrument-function (funsym) |
|---|
| 235 |
"Instrument FUNSYM for profiling. |
|---|
| 236 |
FUNSYM must be a symbol of a defined function." |
|---|
| 237 |
(interactive "aFunction to instrument: ") |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
(elp-restore-function funsym) |
|---|
| 247 |
(let* ((funguts (symbol-function funsym)) |
|---|
| 248 |
(infovec (vector 0 0 funguts)) |
|---|
| 249 |
(newguts '(lambda (&rest args)))) |
|---|
| 250 |
|
|---|
| 251 |
(and (eq (car-safe funguts) 'macro) |
|---|
| 252 |
(error "ELP cannot profile macro: %s" funsym)) |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
(and (eq (car-safe funguts) 'autoload) |
|---|
| 261 |
(error "ELP cannot profile autoloaded function: %s" funsym)) |
|---|
| 262 |
|
|---|
| 263 |
(unless (elp-profilable-p funsym) |
|---|
| 264 |
(error "ELP cannot profile the function: %s" funsym)) |
|---|
| 265 |
|
|---|
| 266 |
(if (commandp funsym) |
|---|
| 267 |
(setq newguts (append newguts '((interactive))))) |
|---|
| 268 |
(setq newguts (append newguts `((elp-wrapper |
|---|
| 269 |
(quote ,funsym) |
|---|
| 270 |
,(when (commandp funsym) |
|---|
| 271 |
'(called-interactively-p)) |
|---|
| 272 |
args)))) |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
(put funsym elp-timer-info-property infovec) |
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
(let ((advice-info (get funsym 'ad-advice-info))) |
|---|
| 298 |
(if advice-info |
|---|
| 299 |
(progn |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
(put funsym 'ad-advice-info nil) |
|---|
| 303 |
(fset funsym newguts) |
|---|
| 304 |
(put funsym 'ad-advice-info advice-info)) |
|---|
| 305 |
(fset funsym newguts))) |
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
(unless (memq funsym elp-all-instrumented-list) |
|---|
| 309 |
(push funsym elp-all-instrumented-list)))) |
|---|
| 310 |
|
|---|
| 311 |
(defun elp-restore-function (funsym) |
|---|
| 312 |
"Restore an instrumented function to its original definition. |
|---|
| 313 |
Argument FUNSYM is the symbol of a defined function." |
|---|
| 314 |
(interactive "aFunction to restore: ") |
|---|
| 315 |
(let ((info (get funsym elp-timer-info-property))) |
|---|
| 316 |
|
|---|
| 317 |
(setq elp-all-instrumented-list |
|---|
| 318 |
(delq funsym elp-all-instrumented-list)) |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
(if (eq funsym elp-master) |
|---|
| 322 |
(setq elp-master nil |
|---|
| 323 |
elp-record-p t)) |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
(put funsym elp-timer-info-property nil) |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
|
|---|
| 335 |
|
|---|
| 336 |
|
|---|
| 337 |
(and info |
|---|
| 338 |
(functionp funsym) |
|---|
| 339 |
(not (byte-code-function-p (symbol-function funsym))) |
|---|
| 340 |
(assq 'elp-wrapper (symbol-function funsym)) |
|---|
| 341 |
(fset funsym (aref info 2))))) |
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
(defun elp-instrument-list (&optional list) |
|---|
| 345 |
"Instrument for profiling, all functions in `elp-function-list'. |
|---|
| 346 |
Use optional LIST if provided instead." |
|---|
| 347 |
(interactive "PList of functions to instrument: ") |
|---|
| 348 |
(let ((list (or list elp-function-list))) |
|---|
| 349 |
(mapcar 'elp-instrument-function list))) |
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
(defun elp-instrument-package (prefix) |
|---|
| 353 |
"Instrument for profiling, all functions which start with PREFIX. |
|---|
| 354 |
For example, to instrument all ELP functions, do the following: |
|---|
| 355 |
|
|---|
| 356 |
\\[elp-instrument-package] RET elp- RET" |
|---|
| 357 |
(interactive |
|---|
| 358 |
(list (completing-read "Prefix of package to instrument: " |
|---|
| 359 |
obarray 'elp-profilable-p))) |
|---|
| 360 |
(if (zerop (length prefix)) |
|---|
| 361 |
(error "Instrumenting all Emacs functions would render Emacs unusable")) |
|---|
| 362 |
(elp-instrument-list |
|---|
| 363 |
(mapcar |
|---|
| 364 |
'intern |
|---|
| 365 |
(all-completions prefix obarray 'elp-profilable-p)))) |
|---|
| 366 |
|
|---|
| 367 |
(defun elp-restore-list (&optional list) |
|---|
| 368 |
"Restore the original definitions for all functions in `elp-function-list'. |
|---|
| 369 |
Use optional LIST if provided instead." |
|---|
| 370 |
(interactive "PList of functions to restore: ") |
|---|
| 371 |
(let ((list (or list elp-function-list))) |
|---|
| 372 |
(mapcar 'elp-restore-function list))) |
|---|
| 373 |
|
|---|
| 374 |
(defun elp-restore-all () |
|---|
| 375 |
"Restore the original definitions of all functions being profiled." |
|---|
| 376 |
(interactive) |
|---|
| 377 |
(elp-restore-list elp-all-instrumented-list)) |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
(defun elp-reset-function (funsym) |
|---|
| 381 |
"Reset the profiling information for FUNSYM." |
|---|
| 382 |
(interactive "aFunction to reset: ") |
|---|
| 383 |
(let ((info (get funsym elp-timer-info-property))) |
|---|
| 384 |
(or info |
|---|
| 385 |
(error "%s is not instrumented for profiling" funsym)) |
|---|
| 386 |
(aset info 0 0) |
|---|
| 387 |
(aset info 1 0.0) |
|---|
| 388 |
|
|---|
| 389 |
)) |
|---|
| 390 |
|
|---|
| 391 |
(defun elp-reset-list (&optional list) |
|---|
| 392 |
"Reset the profiling information for all functions in `elp-function-list'. |
|---|
| 393 |
Use optional LIST if provided instead." |
|---|
| 394 |
(interactive "PList of functions to reset: ") |
|---|
| 395 |
(let ((list (or list elp-function-list))) |
|---|
| 396 |
(mapcar 'elp-reset-function list))) |
|---|
| 397 |
|
|---|
| 398 |
(defun elp-reset-all () |
|---|
| 399 |
"Reset the profiling information for all functions being profiled." |
|---|
| 400 |
(interactive) |
|---|
| 401 |
(elp-reset-list elp-all-instrumented-list)) |
|---|
| 402 |
|
|---|
| 403 |
(defun elp-set-master (funsym) |
|---|
| 404 |
"Set the master function for profiling." |
|---|
| 405 |
(interactive "aMaster function: ") |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
(setq elp-master funsym |
|---|
| 409 |
elp-record-p nil) |
|---|
| 410 |
|
|---|
| 411 |
(or (memq funsym elp-all-instrumented-list) |
|---|
| 412 |
(elp-instrument-function funsym))) |
|---|
| 413 |
|
|---|
| 414 |
(defun elp-unset-master () |
|---|
| 415 |
"Unset the master function." |
|---|
| 416 |
(interactive) |
|---|
| 417 |
|
|---|
| 418 |
(setq elp-master nil |
|---|
| 419 |
elp-record-p t)) |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
(defsubst elp-elapsed-time (start end) |
|---|
| 423 |
(+ (* (- (car end) (car start)) 65536.0) |
|---|
| 424 |
(- (car (cdr end)) (car (cdr start))) |
|---|
| 425 |
(/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0))) |
|---|
| 426 |
|
|---|
| 427 |
(defun elp-wrapper (funsym interactive-p args) |
|---|
| 428 |
"This function has been instrumented for profiling by the ELP. |
|---|
| 429 |
ELP is the Emacs Lisp Profiler. To restore the function to its |
|---|
| 430 |
original definition, use \\[elp-restore-function] or \\[elp-restore-all]." |
|---|
| 431 |
|
|---|
| 432 |
(if (and elp-master |
|---|
| 433 |
(eq funsym elp-master)) |
|---|
| 434 |
(setq elp-record-p t)) |
|---|
| 435 |
|
|---|
| 436 |
(let* ((info (get funsym elp-timer-info-property)) |
|---|
| 437 |
(func (aref info 2)) |
|---|
| 438 |
result) |
|---|
| 439 |
(or func |
|---|
| 440 |
(error "%s is not instrumented for profiling" funsym)) |
|---|
| 441 |
(if (not elp-record-p) |
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 |
(setq result |
|---|
| 445 |
(if interactive-p |
|---|
| 446 |
(call-interactively func) |
|---|
| 447 |
(apply func args))) |
|---|
| 448 |
|
|---|
| 449 |
(let (enter-time exit-time) |
|---|
| 450 |
|
|---|
| 451 |
(aset info 0 (1+ (aref info 0))) |
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
(if interactive-p |
|---|
| 456 |
(setq enter-time (current-time) |
|---|
| 457 |
result (call-interactively func) |
|---|
| 458 |
exit-time (current-time)) |
|---|
| 459 |
(setq enter-time (current-time) |
|---|
| 460 |
result (apply func args) |
|---|
| 461 |
exit-time (current-time))) |
|---|
| 462 |
|
|---|
| 463 |
(aset info 1 (+ (aref info 1) (elp-elapsed-time enter-time exit-time))) |
|---|
| 464 |
)) |
|---|
| 465 |
|
|---|
| 466 |
(if (and elp-master |
|---|
| 467 |
(eq funsym elp-master)) |
|---|
| 468 |
(setq elp-record-p nil)) |
|---|
| 469 |
result)) |
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
(defvar elp-field-len nil) |
|---|
| 474 |
(defvar elp-cc-len nil) |
|---|
| 475 |
(defvar elp-at-len nil) |
|---|
| 476 |
(defvar elp-et-len nil) |
|---|
| 477 |
|
|---|
| 478 |
(defun elp-sort-by-call-count (vec1 vec2) |
|---|
| 479 |
|
|---|
| 480 |
(>= (aref vec1 0) (aref vec2 0))) |
|---|
| 481 |
|
|---|
| 482 |
(defun elp-sort-by-total-time (vec1 vec2) |
|---|
| 483 |
|
|---|
| 484 |
(>= (aref vec1 1) (aref vec2 1))) |
|---|
| 485 |
|
|---|
| 486 |
(defun elp-sort-by-average-time (vec1 vec2) |
|---|
| 487 |
|
|---|
| 488 |
(>= (aref vec1 2) (aref vec2 2))) |
|---|
| 489 |
|
|---|
| 490 |
(defsubst elp-pack-number (number width) |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
(if (<= (length number) width) |
|---|
| 494 |
number |
|---|
| 495 |
|
|---|
| 496 |
(if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number) |
|---|
| 497 |
(concat (substring |
|---|
| 498 |
(match-string 1 number) |
|---|
| 499 |
0 |
|---|
| 500 |
(- width (match-end 2) (- (match-beginning 2)) 3)) |
|---|
| 501 |
"..." |
|---|
| 502 |
(match-string 2 number)) |
|---|
| 503 |
(substring number 0 width)))) |
|---|
| 504 |
|
|---|
| 505 |
(defun elp-output-result (resultvec) |
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
(let* ((cc (aref resultvec 0)) |
|---|
| 512 |
(tt (aref resultvec 1)) |
|---|
| 513 |
(at (aref resultvec 2)) |
|---|
| 514 |
(symname (aref resultvec 3)) |
|---|
| 515 |
callcnt totaltime avetime) |
|---|
| 516 |
(setq callcnt (number-to-string cc) |
|---|
| 517 |
totaltime (number-to-string tt) |
|---|
| 518 |
avetime (number-to-string at)) |
|---|
| 519 |
|
|---|
| 520 |
(if (and elp-report-limit |
|---|
| 521 |
(numberp elp-report-limit) |
|---|
| 522 |
(< cc elp-report-limit)) |
|---|
| 523 |
nil |
|---|
| 524 |
(elp-output-insert-symname symname) |
|---|
| 525 |
(insert-char 32 (+ elp-field-len (- (length symname)) 2)) |
|---|
| 526 |
|
|---|
| 527 |
(insert callcnt) |
|---|
| 528 |
(insert-char 32 (+ elp-cc-len (- (length callcnt)) 2)) |
|---|
| 529 |
(let ((ttstr (elp-pack-number totaltime elp-et-len)) |
|---|
| 530 |
(atstr (elp-pack-number avetime elp-at-len))) |
|---|
| 531 |
(insert ttstr) |
|---|
| 532 |
(insert-char 32 (+ elp-et-len (- (length ttstr)) 2)) |
|---|
| 533 |
(insert atstr)) |
|---|
| 534 |
(insert "\n")))) |
|---|
| 535 |
|
|---|
| 536 |
(defvar elp-results-symname-map |
|---|
| 537 |
(let ((map (make-sparse-keymap))) |
|---|
| 538 |
(define-key map [mouse-2] 'elp-results-jump-to-definition) |
|---|
| 539 |
(define-key map "\C-m" 'elp-results-jump-to-definition) |
|---|
| 540 |
map) |
|---|
| 541 |
"Keymap used on the function name column." ) |
|---|
| 542 |
|
|---|
| 543 |
(defun elp-results-jump-to-definition (&optional event) |
|---|
| 544 |
"Jump to the definition of the function under the point." |
|---|
| 545 |
(interactive (list last-nonmenu-event)) |
|---|
| 546 |
(if event (posn-set-point (event-end event))) |
|---|
| 547 |
(find-function (get-text-property (point) 'elp-symname))) |
|---|
| 548 |
|
|---|
| 549 |
(defun elp-output-insert-symname (symname) |
|---|
| 550 |
|
|---|
| 551 |
(insert (propertize symname |
|---|
| 552 |
'elp-symname (intern symname) |
|---|
| 553 |
'keymap elp-results-symname-map |
|---|
| 554 |
'mouse-face 'highlight |
|---|
| 555 |
'help-echo "mouse-2 or RET jumps to definition"))) |
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
(defun elp-results () |
|---|
| 559 |
"Display current profiling results. |
|---|
| 560 |
If `elp-reset-after-results' is non-nil, then current profiling |
|---|
| 561 |
information for all instrumented functions is reset after results are |
|---|
| 562 |
displayed." |
|---|
| 563 |
(interactive) |
|---|
| 564 |
(let ((curbuf (current-buffer)) |
|---|
| 565 |
(resultsbuf (if elp-recycle-buffers-p |
|---|
| 566 |
(get-buffer-create elp-results-buffer) |
|---|
| 567 |
(generate-new-buffer elp-results-buffer)))) |
|---|
| 568 |
(set-buffer resultsbuf) |
|---|
| 569 |
(erase-buffer) |
|---|
| 570 |
|
|---|
| 571 |
(let* ((longest 0) |
|---|
| 572 |
(title "Function Name") |
|---|
| 573 |
(titlelen (length title)) |
|---|
| 574 |
(elp-field-len titlelen) |
|---|
| 575 |
(cc-header "Call Count") |
|---|
| 576 |
(elp-cc-len (length cc-header)) |
|---|
| 577 |
(et-header "Elapsed Time") |
|---|
| 578 |
(elp-et-len (length et-header)) |
|---|
| 579 |
(at-header "Average Time") |
|---|
| 580 |
(elp-at-len (length at-header)) |
|---|
| 581 |
(resvec |
|---|
| 582 |
(mapcar |
|---|
| 583 |
(function |
|---|
| 584 |
(lambda (funsym) |
|---|
| 585 |
(let* ((info (get funsym elp-timer-info-property)) |
|---|
| 586 |
(symname (format "%s" funsym)) |
|---|
| 587 |
(cc (aref info 0)) |
|---|
| 588 |
(tt (aref info 1))) |
|---|
| 589 |
(if (not info) |
|---|
| 590 |
(insert "No profiling information found for: " |
|---|
| 591 |
symname) |
|---|
| 592 |
(setq longest (max longest (length symname))) |
|---|
| 593 |
(vector cc tt (if (zerop cc) |
|---|
| 594 |
0.0 |
|---|
| 595 |
(/ (float tt) (float cc))) |
|---|
| 596 |
symname))))) |
|---|
| 597 |
elp-all-instrumented-list)) |
|---|
| 598 |
) |
|---|
| 599 |
(insert title) |
|---|
| 600 |
(if (> longest titlelen) |
|---|
| 601 |
(progn |
|---|
| 602 |
(insert-char 32 (- longest titlelen)) |
|---|
| 603 |
(setq elp-field-len longest))) |
|---|
| 604 |
(insert " " cc-header " " et-header " " at-header "\n") |
|---|
| 605 |
(insert-char ?= elp-field-len) |
|---|
| 606 |
(insert " ") |
|---|
| 607 |
(insert-char ?= elp-cc-len) |
|---|
| 608 |
(insert " ") |
|---|
| 609 |
(insert-char ?= elp-et-len) |
|---|
| 610 |
(insert " ") |
|---|
| 611 |
(insert-char ?= elp-at-len) |
|---|
| 612 |
(insert "\n") |
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
(if elp-sort-by-function |
|---|
| 617 |
(setq resvec (sort resvec elp-sort-by-function))) |
|---|
| 618 |
(mapcar 'elp-output-result resvec)) |
|---|
| 619 |
|
|---|
| 620 |
(set-buffer curbuf) |
|---|
| 621 |
(pop-to-buffer resultsbuf) |
|---|
| 622 |
|
|---|
| 623 |
(if (or elp-use-standard-output noninteractive) |
|---|
| 624 |
(princ (buffer-substring (point-min) (point-max)))) |
|---|
| 625 |
|
|---|
| 626 |
(and elp-reset-after-results |
|---|
| 627 |
(elp-reset-all)))) |
|---|
| 628 |
|
|---|
| 629 |
(defun elp-unload-hook () |
|---|
| 630 |
(elp-restore-all)) |
|---|
| 631 |
(add-hook 'elp-unload-hook 'elp-unload-hook) |
|---|
| 632 |
|
|---|
| 633 |
(provide 'elp) |
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|