unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#22114: 24.5; [PATCH] Allow profiler.el to display reports after stopping
@ 2015-12-08  8:13 Vasilij Schneidermann
  2015-12-08 16:22 ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Vasilij Schneidermann @ 2015-12-08  8:13 UTC (permalink / raw)
  To: 22114


[-- Attachment #1.1: Type: text/plain, Size: 719 bytes --]

I've worked with a few other profilers than profiler.el so far and one
striking difference is that they allowed you to start a profiling run,
stop it and then retrieve the profiling log between these two points in
time.  profiler.el on the other hand flatout refuses to display a report
after stopping which is especially puzzling given the `profiler-stop`
docstring: "Stop started profilers.  Profiler logs will be kept."  If
the logs are kept after all, why can't I take a look at them?

I've attached a patch that solves this by caching the last accessable
profiler log.  This allows both workflows to work, be it displaying a
report while the profiler is still running or displaying it after
stopping the profiler.

[-- Attachment #1.2: Type: text/html, Size: 804 bytes --]

[-- Attachment #2: 0001-Allow-for-retrieving-profiler-logs-after-stopping.patch --]
[-- Type: text/x-diff, Size: 3675 bytes --]

From 3464446b83151ad894ff4ee7f62ed1cb7852b1b6 Mon Sep 17 00:00:00 2001
From: Vasilij Schneidermann <v.schneidermann@gmail.com>
Date: Tue, 8 Dec 2015 09:01:15 +0100
Subject: [PATCH] Allow for retrieving profiler logs after stopping

---
 lisp/profiler.el | 59 +++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

diff --git a/lisp/profiler.el b/lisp/profiler.el
index f28bbfe..10cdcfb 100644
--- a/lisp/profiler.el
+++ b/lisp/profiler.el
@@ -214,21 +214,23 @@ 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))
 
 \f
 ;;; Calltrees
@@ -828,7 +830,11 @@ 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")
@@ -839,26 +845,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)
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2019-06-30 12:34 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-08  8:13 bug#22114: 24.5; [PATCH] Allow profiler.el to display reports after stopping Vasilij Schneidermann
2015-12-08 16:22 ` Eli Zaretskii
2015-12-08 16:32   ` Vasilij Schneidermann
2015-12-08 17:28     ` Eli Zaretskii
2015-12-08 17:42       ` John Wiegley
2015-12-08 17:56         ` Vasilij Schneidermann
2015-12-08 18:02           ` John Wiegley
2015-12-08 18:12             ` Vasilij Schneidermann
2015-12-08 18:08         ` Eli Zaretskii
2015-12-08 18:14           ` John Wiegley
2015-12-10  9:18           ` Vasilij Schneidermann
2015-12-13 20:33           ` Vasilij Schneidermann
2015-12-13 22:18             ` Vasilij Schneidermann
2015-12-14  4:21               ` Stefan Monnier
2015-12-14  8:28                 ` Vasilij Schneidermann
2015-12-14 14:43                   ` Stefan Monnier
2015-12-14 18:23                     ` Vasilij Schneidermann
2015-12-15  4:29                       ` Stefan Monnier
2019-06-27 18:18                   ` Lars Ingebrigtsen
2019-06-30  9:21                     ` Vasilij Schneidermann
2019-06-30 12:34                       ` Basil L. Contovounesios
2015-12-08 16:40   ` Vasilij Schneidermann
2015-12-08 17:38     ` Eli Zaretskii
2015-12-08 17:44       ` Vasilij Schneidermann
2015-12-08 18:10         ` Eli Zaretskii
2015-12-08 19:15   ` Vasilij Schneidermann
2015-12-08 19:21     ` John Wiegley
2015-12-08 20:12       ` Eli Zaretskii
2015-12-08 20:39         ` John Wiegley
2015-12-08 20:10     ` Eli Zaretskii
2019-06-25 14:46   ` Lars Ingebrigtsen
2019-06-27 14:09     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).