]> git.eshelyaron.com Git - emacs.git/commitdiff
* profiler.el (with-sample-profiling): New macro.
authorTomohiro Matsuyama <tomo@cx4a.org>
Wed, 22 Aug 2012 09:15:17 +0000 (18:15 +0900)
committerTomohiro Matsuyama <tomo@cx4a.org>
Wed, 22 Aug 2012 09:15:17 +0000 (18:15 +0900)
(with-memory-profiling): New macro.

lisp/ChangeLog
lisp/profiler.el

index 366380b4ec49b8bb263b997950578545ec7e4f5e..d8134f2c04665b2ae4ff4aa2a98598fb05dcbe8f 100644 (file)
@@ -2,6 +2,8 @@
 
        * profiler.el: Switch to cl-lib.
        (profiler-start): Change mode spec.
+       (with-sample-profiling): New macro.
+       (with-memory-profiling): New macro.
 
 2012-08-22  Daiki Ueno  <ueno@unixuser.org>
 
index db2d0eb461a5df4ef098418522a0afa5792e0aa3..9e94f0d078c5ecc7271d6e5125c3de6700ce156b 100644 (file)
@@ -575,17 +575,23 @@ otherwise collapse the entry."
   (memory-profiler-reset)
   t)
 
-(defun profiler-report ()
-  (interactive)
+(defun sample-profiler-report ()
   (let ((sample-log (sample-profiler-log)))
     (when sample-log
       (profiler-log-fixup sample-log)
-      (profiler-report-log sample-log)))
+      (profiler-report-log sample-log))))
+
+(defun memory-profiler-report ()
   (let ((memory-log (memory-profiler-log)))
     (when memory-log
       (profiler-log-fixup memory-log)
       (profiler-report-log memory-log))))
 
+(defun profiler-report ()
+  (interactive)
+  (sample-profiler-report)
+  (memory-profiler-report))
+
 ;;;###autoload
 (defun profiler-find-log (filename)
   (interactive
@@ -596,5 +602,29 @@ otherwise collapse the entry."
     (let ((log (read (current-buffer))))
       (profiler-report-log log))))
 
+\f
+
+;;; Profiling helpers
+
+(cl-defmacro with-sample-profiling ((&key (interval profiler-sample-interval)) &rest body)
+  `(progn
+     (sample-profiler-start ,interval)
+     (sample-profiler-reset)
+     (unwind-protect
+        (progn ,@body)
+       (sample-profiler-stop)
+       (sample-profiler-report)
+       (sample-profiler-reset))))
+
+(cl-defmacro with-memory-profiling (() &rest body)
+  `(progn
+     (memory-profiler-start)
+     (memory-profiler-reset)
+     (unwind-protect
+        (progn ,@body)
+       (memory-profiler-stop)
+       (memory-profiler-report)
+       (memory-profiler-reset))))
+
 (provide 'profiler)
 ;;; profiler.el ends here