From xemacs-m  Thu Jun 26 10:44:42 1997
Received: from jagor.srce.hr (hniksic@jagor.srce.hr [161.53.2.130])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id KAA15919
	for <xemacs-beta@xemacs.org>; Thu, 26 Jun 1997 10:44:37 -0500 (CDT)
Received: (from hniksic@localhost)
          by jagor.srce.hr (8.8.5/8.8.4)
	  id RAA04731; Thu, 26 Jun 1997 17:44:35 +0200 (MET DST)
To: XEmacs Developers <xemacs-beta@xemacs.org>
Subject: [PATCH] Addition to profile.el
X-Attribution: Hrv
X-Face: Mie8:rOV<\c/~z{s.X4A{!?vY7{drJ([U]0O=W/<W*SMo/Mv:58:*_y~ki>xDi&N7XG
        KV^$k0m3Oe/)'e%3=$PCR&3ITUXH,cK>]bci&<qQ>Ff%x_>1`T(+M2Gg/fgndU%k*ft
        [(7._6e0n-V%|%'[c|q:;}td$#INd+;?!-V=c8Pqf}3J
From: Hrvoje Niksic <hniksic@srce.hr>
Date: 26 Jun 1997 17:44:34 +0200
Message-ID: <kigk9jhe5ct.fsf@jagor.srce.hr>
Lines: 97
X-Mailer: Gnus v5.4.59/XEmacs 20.3(beta9) - "Sofia"

With these addition, profiling is made almost useful.

M-x pretty-print-profiling-info now inserts the info to the current
buffer.

M-x profile-key-sequence lets you enter a key sequence, and profile
its execution.  For example, you can press
`M-x profile-key-sequence RET SPC' in a group buffer, and see where
Gnus loses so much time.  Right.


1997-06-26  Hrvoje Niksic  <hniksic@srce.hr>

	* prim/profile.el (profile-key-sequence): New function.
	(pretty-print-profiling-info): Allow interactive calls.


--- lisp/prim/profile.el.orig	Thu Jun 26 17:15:53 1997
+++ lisp/prim/profile.el	Thu Jun 26 17:43:00 1997
@@ -26,26 +26,37 @@
 
 ;;; Commentary:
 
+;; `profile' macro and `profile-key-sequence' added in June 1997 by
+;; hniksic.
+
+
 ;;; Code:
 
 ;;;###autoload
-(defun pretty-print-profiling-info (&optional info)
-  "Print profiling info INFO to standard output in a pretty format.
+(defun pretty-print-profiling-info (&optional info stream)
+  "Print profiling info INFO to STREAM in a pretty format.
 If INFO is omitted, the current profiling info is retrieved using
-`get-profiling-info'."
-  (if info (setq info (copy-alist info))
+`get-profiling-info'.
+If STREAM is omitted, either current buffer or standard output are used,
+ depending on whether the function was called interactively or not."
+  (interactive)
+  (if info
+      (setq info (copy-alist info))
     (setq info (get-profiling-info)))
-  (setq info (nreverse (sort info #'cdr-less-than-cdr)))
-  (princ "Function                                               Count        %\n")
-  (princ "---------------------------------------------------------------------\n")
-  (let ((sum 0.0))
-    (dolist (info2 info)
-      (incf sum (cdr info2)))
-    (while info
-      (let ((f (caar info)))
-	(princ (format "%-50s%10d   %6.3f\n" f (cdar info)
-		       (* 100 (/ (cdar info) sum)))))
-      (setq info (cdr info)))))
+  (let ((standard-output (or stream (if (interactive-p)
+					(current-buffer)
+				      standard-output))))
+    (setq info (nreverse (sort info #'cdr-less-than-cdr)))
+    (princ "Function                                               Count        %\n")
+    (princ "---------------------------------------------------------------------\n")
+    (let ((sum 0.0))
+      (dolist (info2 info)
+	(incf sum (cdr info2)))
+      (while info
+	(let ((f (caar info)))
+	  (princ (format "%-50s%10d   %6.3f\n" f (cdar info)
+			 (* 100 (/ (cdar info) sum)))))
+	(pop info)))))
 
 ;;;###autoload
 (defmacro profile (&rest forms)
@@ -60,5 +71,18 @@
      (get-profiling-info)))
 
 (put 'profile 'lisp-indent-function 0)
+
+;;;###autoload
+(defun profile-key-sequence (keys)
+  "Dispatch the key sequence KEYS and profile the execution.
+KEYS can be a vector of keypress events, a keypress event, or a character.
+The function returns the profiling info."
+  (interactive "kProfile keystroke: ")
+  (and (characterp keys)
+       (setq keys (character-to-event keys)))
+  (or (vectorp keys)
+      (setq keys (vector keys)))
+  (profile
+    (mapc 'dispatch-event keys)))
 
 ;;; profile.el ends here


-- 
Hrvoje Niksic <hniksic@srce.hr> | Student at FER Zagreb, Croatia
--------------------------------+--------------------------------
Which is worse: ignorance or apathy?  Who knows?  Who cares?

