aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVasilij Schneidermann2019-06-27 20:18:20 +0200
committerLars Ingebrigtsen2019-06-27 21:00:36 +0200
commit9997429cb7f960a1a08c7dfb4848a0cb60107f57 (patch)
treeee6271e1be08cbd1532105e69f8d12ae2e0dd5d8
parentb93e5463885f9c99e74b52d2f569ad06ec2d0ff8 (diff)
downloademacs-9997429cb7f960a1a08c7dfb4848a0cb60107f57.tar.gz
emacs-9997429cb7f960a1a08c7dfb4848a0cb60107f57.zip
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.
-rw-r--r--lisp/profiler.el59
1 files changed, 35 insertions, 24 deletions
diff --git a/lisp/profiler.el b/lisp/profiler.el
index 45dc1d1edc0..74b847c8d74 100644
--- a/lisp/profiler.el
+++ b/lisp/profiler.el
@@ -213,21 +213,22 @@ Optional argument MODE means only check for the specified mode (cpu or mem)."
213 (t (or (profiler-running-p 'cpu) 213 (t (or (profiler-running-p 'cpu)
214 (profiler-running-p 'mem))))) 214 (profiler-running-p 'mem)))))
215 215
216(defvar profiler-cpu-log nil)
217(defvar profiler-memory-log nil)
218
216(defun profiler-cpu-profile () 219(defun profiler-cpu-profile ()
217 "Return CPU profile." 220 "Return CPU profile."
218 (when (profiler-running-p 'cpu) 221 (profiler-make-profile
219 (profiler-make-profile 222 :type 'cpu
220 :type 'cpu 223 :timestamp (current-time)
221 :timestamp (current-time) 224 :log profiler-cpu-log))
222 :log (profiler-cpu-log))))
223 225
224(defun profiler-memory-profile () 226(defun profiler-memory-profile ()
225 "Return memory profile." 227 "Return memory profile."
226 (when (profiler-memory-running-p) 228 (profiler-make-profile
227 (profiler-make-profile 229 :type 'memory
228 :type 'memory 230 :timestamp (current-time)
229 :timestamp (current-time) 231 :log profiler-memory-log))
230 :log (profiler-memory-log))))
231 232
232 233
233;;; Calltrees 234;;; Calltrees
@@ -829,7 +830,12 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
829(defun profiler-stop () 830(defun profiler-stop ()
830 "Stop started profilers. Profiler logs will be kept." 831 "Stop started profilers. Profiler logs will be kept."
831 (interactive) 832 (interactive)
832 (let ((cpu (if (fboundp 'profiler-cpu-stop) (profiler-cpu-stop))) 833 (when (and (fboundp 'profiler-cpu-running-p)
834 (profiler-cpu-running-p))
835 (setq profiler-cpu-log (profiler-cpu-log)))
836 (when (profiler-memory-running-p)
837 (setq profiler-memory-log (profiler-memory-log)))
838 (let ((cpu (when (fboundp 'profiler-cpu-stop) (profiler-cpu-stop)))
833 (mem (profiler-memory-stop))) 839 (mem (profiler-memory-stop)))
834 (message "%s profiler stopped" 840 (message "%s profiler stopped"
835 (cond ((and mem cpu) "CPU and memory") 841 (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."
840(defun profiler-reset () 846(defun profiler-reset ()
841 "Reset profiler logs." 847 "Reset profiler logs."
842 (interactive) 848 (interactive)
843 (when (fboundp 'profiler-cpu-log) 849 (when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p))
844 (ignore (profiler-cpu-log))) 850 (profiler-cpu-stop))
845 (ignore (profiler-memory-log)) 851 (when (profiler-memory-running-p)
846 t) 852 (profiler-memory-stop))
853 (setq profiler-cpu-log nil
854 profiler-memory-log nil))
847 855
848(defun profiler-report-cpu () 856(defun profiler-report-cpu ()
849 (let ((profile (profiler-cpu-profile))) 857 (when profiler-cpu-log
850 (when profile 858 (profiler-report-profile-other-window (profiler-cpu-profile))))
851 (profiler-report-profile-other-window profile))))
852 859
853(defun profiler-report-memory () 860(defun profiler-report-memory ()
854 (let ((profile (profiler-memory-profile))) 861 (when profiler-memory-log
855 (when profile 862 (profiler-report-profile-other-window (profiler-memory-profile))))
856 (profiler-report-profile-other-window profile))))
857 863
858(defun profiler-report () 864(defun profiler-report ()
859 "Report profiling results." 865 "Report profiling results."
860 (interactive) 866 (when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p))
861 (profiler-report-cpu) 867 (setq profiler-cpu-log (profiler-cpu-log)))
862 (profiler-report-memory)) 868 (when (profiler-memory-running-p)
869 (setq profiler-memory-log (profiler-memory-log)))
870 (if (and (not profiler-cpu-log) (not profiler-memory-log))
871 (user-error "No profiler run recorded")
872 (profiler-report-cpu)
873 (profiler-report-memory)))
863 874
864;;;###autoload 875;;;###autoload
865(defun profiler-find-profile (filename) 876(defun profiler-find-profile (filename)