From ce56157e5f8ab1b244a63faf2e09ab8cd7c5ee23 Mon Sep 17 00:00:00 2001 From: Tomohiro Matsuyama Date: Wed, 22 Aug 2012 18:15:17 +0900 Subject: [PATCH] * profiler.el (with-sample-profiling): New macro. (with-memory-profiling): New macro. --- lisp/ChangeLog | 2 ++ lisp/profiler.el | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) 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 -- 2.39.5