Allow for retrieving profiler logs after stopping
* lisp/profiler.el (profiler-cpu-log, profiler-memory-log): New variables. (profiler-cpu-profile): Work even if the profiler is no longer running (bug#22114). (profiler-memory-profile): Ditto. (profiler-stop): Save the data. (profiler-reset): Clear the saved data. (profiler-report-cpu, profiler-report-memory): Report on the saved data. (profiler-report): Save the data here, too.
This commit is contained in:
parent
b93e546388
commit
9997429cb7
1 changed files with 35 additions and 24 deletions
|
@ -213,21 +213,22 @@ Optional argument MODE means only check for the specified mode (cpu or mem)."
|
|||
(t (or (profiler-running-p 'cpu)
|
||||
(profiler-running-p 'mem)))))
|
||||
|
||||
(defvar profiler-cpu-log nil)
|
||||
(defvar profiler-memory-log nil)
|
||||
|
||||
(defun profiler-cpu-profile ()
|
||||
"Return CPU profile."
|
||||
(when (profiler-running-p 'cpu)
|
||||
(profiler-make-profile
|
||||
:type 'cpu
|
||||
:timestamp (current-time)
|
||||
:log (profiler-cpu-log))))
|
||||
(profiler-make-profile
|
||||
:type 'cpu
|
||||
:timestamp (current-time)
|
||||
:log profiler-cpu-log))
|
||||
|
||||
(defun profiler-memory-profile ()
|
||||
"Return memory profile."
|
||||
(when (profiler-memory-running-p)
|
||||
(profiler-make-profile
|
||||
:type 'memory
|
||||
:timestamp (current-time)
|
||||
:log (profiler-memory-log))))
|
||||
(profiler-make-profile
|
||||
:type 'memory
|
||||
:timestamp (current-time)
|
||||
:log profiler-memory-log))
|
||||
|
||||
|
||||
;;; Calltrees
|
||||
|
@ -829,7 +830,12 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
|
|||
(defun profiler-stop ()
|
||||
"Stop started profilers. Profiler logs will be kept."
|
||||
(interactive)
|
||||
(let ((cpu (if (fboundp 'profiler-cpu-stop) (profiler-cpu-stop)))
|
||||
(when (and (fboundp 'profiler-cpu-running-p)
|
||||
(profiler-cpu-running-p))
|
||||
(setq profiler-cpu-log (profiler-cpu-log)))
|
||||
(when (profiler-memory-running-p)
|
||||
(setq profiler-memory-log (profiler-memory-log)))
|
||||
(let ((cpu (when (fboundp 'profiler-cpu-stop) (profiler-cpu-stop)))
|
||||
(mem (profiler-memory-stop)))
|
||||
(message "%s profiler stopped"
|
||||
(cond ((and mem cpu) "CPU and memory")
|
||||
|
@ -840,26 +846,31 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
|
|||
(defun profiler-reset ()
|
||||
"Reset profiler logs."
|
||||
(interactive)
|
||||
(when (fboundp 'profiler-cpu-log)
|
||||
(ignore (profiler-cpu-log)))
|
||||
(ignore (profiler-memory-log))
|
||||
t)
|
||||
(when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p))
|
||||
(profiler-cpu-stop))
|
||||
(when (profiler-memory-running-p)
|
||||
(profiler-memory-stop))
|
||||
(setq profiler-cpu-log nil
|
||||
profiler-memory-log nil))
|
||||
|
||||
(defun profiler-report-cpu ()
|
||||
(let ((profile (profiler-cpu-profile)))
|
||||
(when profile
|
||||
(profiler-report-profile-other-window profile))))
|
||||
(when profiler-cpu-log
|
||||
(profiler-report-profile-other-window (profiler-cpu-profile))))
|
||||
|
||||
(defun profiler-report-memory ()
|
||||
(let ((profile (profiler-memory-profile)))
|
||||
(when profile
|
||||
(profiler-report-profile-other-window profile))))
|
||||
(when profiler-memory-log
|
||||
(profiler-report-profile-other-window (profiler-memory-profile))))
|
||||
|
||||
(defun profiler-report ()
|
||||
"Report profiling results."
|
||||
(interactive)
|
||||
(profiler-report-cpu)
|
||||
(profiler-report-memory))
|
||||
(when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p))
|
||||
(setq profiler-cpu-log (profiler-cpu-log)))
|
||||
(when (profiler-memory-running-p)
|
||||
(setq profiler-memory-log (profiler-memory-log)))
|
||||
(if (and (not profiler-cpu-log) (not profiler-memory-log))
|
||||
(user-error "No profiler run recorded")
|
||||
(profiler-report-cpu)
|
||||
(profiler-report-memory)))
|
||||
|
||||
;;;###autoload
|
||||
(defun profiler-find-profile (filename)
|
||||
|
|
Loading…
Add table
Reference in a new issue