all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Vasilij Schneidermann <v.schneidermann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: John Wiegley <jwiegley@gmail.com>,
	Paul Eggert <eggert@cs.ucla.edu>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	22114@debbugs.gnu.org
Subject: bug#22114: 24.5; [PATCH] Allow profiler.el to display reports after stopping
Date: Sun, 13 Dec 2015 23:18:25 +0100	[thread overview]
Message-ID: <20151213221825.GC1296@odonien.fritz.box> (raw)
In-Reply-To: <20151213203323.GB1296@odonien.fritz.box>

[-- Attachment #1: Type: text/plain, Size: 712 bytes --]

On 12/13/15 at 09:33pm, Vasilij Schneidermann wrote:
> What if one would just create a deep copy of the log that can be
> safely used externally?

Apparently not even that is necessary.  I wrote another variant of the
patch that disables the check for a running profiler before generating a
report, avoids erroring out if generating a report for a non-running
profiler and doesn't reset the log after stopping.  Either my testing
has been too superficial and something unexpected will come bite me or
the comments are simply outdated.

I've taken the liberty to include Paul Eggert and Stefan Monnier into
the CC as they've contributed several patches to profiler.c and should
be able to illuminate this matter.

[-- Attachment #2: 0001-Disable-profiler-log-reset-on-stop.patch --]
[-- Type: text/x-diff, Size: 3829 bytes --]

From 7153c42d55d14ad6d367f4e7f8a5482cb814e810 Mon Sep 17 00:00:00 2001
From: Vasilij Schneidermann <v.schneidermann@gmail.com>
Date: Sun, 13 Dec 2015 23:09:12 +0100
Subject: [PATCH] Disable profiler log reset on stop

---
 lisp/profiler.el | 31 +++++++++++++++----------------
 src/profiler.c   | 16 +---------------
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/lisp/profiler.el b/lisp/profiler.el
index f28bbfe..90a4241 100644
--- a/lisp/profiler.el
+++ b/lisp/profiler.el
@@ -216,19 +216,17 @@ Optional argument MODE means only check for the specified mode (cpu or mem)."
 
 (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
@@ -845,20 +843,21 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
   t)
 
 (defun profiler-report-cpu ()
+  (when (profiler-cpu-log))
   (let ((profile (profiler-cpu-profile)))
-    (when profile
-      (profiler-report-profile-other-window profile))))
+    (profiler-report-profile-other-window profile)))
 
 (defun profiler-report-memory ()
   (let ((profile (profiler-memory-profile)))
-    (when profile
-      (profiler-report-profile-other-window profile))))
+    (profiler-report-profile-other-window profile)))
 
 (defun profiler-report ()
   "Report profiling results."
   (interactive)
-  (profiler-report-cpu)
-  (profiler-report-memory))
+  (when (and (fboundp 'profiler-cpu-log) (profiler-cpu-log))
+    (profiler-report-cpu))
+  (when (profiler-memory-log)
+    (profiler-report-memory)))
 
 ;;;###autoload
 (defun profiler-find-profile (filename)
diff --git a/src/profiler.c b/src/profiler.c
index efdb1d9..4cd6bb0 100644
--- a/src/profiler.c
+++ b/src/profiler.c
@@ -41,9 +41,7 @@ static Lisp_Object
 make_log (EMACS_INT heap_size, EMACS_INT max_stack_depth)
 {
   /* We use a standard Elisp hash-table object, but we use it in
-     a special way.  This is OK as long as the object is not exposed
-     to Elisp, i.e. until it is returned by *-profiler-log, after which
-     it can't be used any more.  */
+     a special way.  */
   Lisp_Object log = make_hash_table (hashtest_profiler,
 				     make_number (heap_size),
 				     make_float (DEFAULT_REHASH_SIZE),
@@ -412,12 +410,6 @@ Before returning, a new log is allocated for future samples.  */)
   (void)
 {
   Lisp_Object result = cpu_log;
-  /* Here we're making the log visible to Elisp, so it's not safe any
-     more for our use afterwards since we can't rely on its special
-     pre-allocated keys anymore.  So we have to allocate a new one.  */
-  cpu_log = (profiler_cpu_running
-	     ? make_log (profiler_log_size, profiler_max_stack_depth)
-	     : Qnil);
   Fputhash (Fmake_vector (make_number (1), Qautomatic_gc),
 	    make_number (cpu_gc_count),
 	    result);
@@ -487,12 +479,6 @@ Before returning, a new log is allocated for future samples.  */)
   (void)
 {
   Lisp_Object result = memory_log;
-  /* Here we're making the log visible to Elisp , so it's not safe any
-     more for our use afterwards since we can't rely on its special
-     pre-allocated keys anymore.  So we have to allocate a new one.  */
-  memory_log = (profiler_memory_running
-		? make_log (profiler_log_size, profiler_max_stack_depth)
-		: Qnil);
   return result;
 }
 
-- 
2.6.2


  reply	other threads:[~2015-12-13 22:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151213221825.GC1296@odonien.fritz.box \
    --to=v.schneidermann@gmail.com \
    --cc=22114@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=jwiegley@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.