From: Tomohiro Matsuyama Date: Wed, 22 Aug 2012 09:15:17 +0000 (+0900) Subject: * profiler.el (with-sample-profiling): New macro. X-Git-Tag: emacs-24.2.90~244^2~77^2~8 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ce56157e5f8ab1b244a63faf2e09ab8cd7c5ee23;p=emacs.git * profiler.el (with-sample-profiling): New macro. (with-memory-profiling): New macro. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 366380b4ec4..d8134f2c046 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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 diff --git a/lisp/profiler.el b/lisp/profiler.el index db2d0eb461a..9e94f0d078c 100644 --- a/lisp/profiler.el +++ b/lisp/profiler.el @@ -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)))) + + +;;; 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