branch: elpa/magit
commit f637dd1877c76e89a1d423657425cdcde2e4d723
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit-toggle-profiling: New command
---
 docs/magit.org     |  5 +++++
 docs/magit.texi    |  5 +++++
 lisp/magit-mode.el | 17 +++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/docs/magit.org b/docs/magit.org
index 675ba9e358a..72a4cac0317 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -9370,6 +9370,11 @@ issue.
   This command profiles refreshing the current Magit buffer and then
   displays the results.
 
+- Key: M-x magit-toggle-profiling ::
+
+  This command starts profiling Magit and Forge, or if profiling is
+  already in progress, it instead stops that and displays the results.
+
 - Key: M-x with-editor-debug ::
 
   This command displays a buffer containing information about the
diff --git a/docs/magit.texi b/docs/magit.texi
index 74f15c1be55..e9bd7ec3422 100644
--- a/docs/magit.texi
+++ b/docs/magit.texi
@@ -11456,6 +11456,11 @@ Also see @ref{Git Executable}.
 This command profiles refreshing the current Magit buffer and then
 displays the results.
 
+@item @kbd{M-x magit-toggle-profiling}
+@findex magit-toggle-profiling
+This command starts profiling Magit and Forge, or if profiling is
+already in progress, it instead stops that and displays the results.
+
 @item @kbd{M-x with-editor-debug}
 @findex with-editor-debug
 This command displays a buffer containing information about the
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 617bf87a662..2a7b79fe1a2 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1109,6 +1109,23 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
   (elp-results)
   (elp-reset-all))
 
+(defun magit-toggle-profiling ()
+  "Start profiling Magit, or if in progress, stop and display the results."
+  (interactive)
+  (require (quote elp))
+  (cond ((catch 'in-progress
+           (mapatoms (lambda (symbol)
+                       (and (get symbol elp-timer-info-property)
+                            (throw 'in-progress t)))))
+         (message "Stop profiling and display results...")
+         (elp-results)
+         (elp-restore-all))
+        (t
+         (message "Start profiling Magit and Forge...")
+         (elp-reset-all)
+         (elp-instrument-package "magit-")
+         (elp-instrument-package "forge-"))))
+
 ;;; Save File-Visiting Buffers
 
 (defvar magit--disable-save-buffers nil)

Reply via email to