;;; Commentary:
-;;
+;;
;;; Code:
(profiler-calltree-walk child function)))
(defun profiler-calltree-build-1 (tree log &optional reverse)
+ ;; FIXME: Do a better job of reconstructing a complete call-tree
+ ;; when the backtraces have been truncated. Ideally, we should be
+ ;; able to reduce profiler-max-stack-depth to 3 or 4 and still
+ ;; get a meaningful call-tree.
(maphash
(lambda (backtrace count)
(when (vectorp backtrace)
(defun profiler-calltree-compute-percentages (tree)
(let ((total-count 0))
+ ;; FIXME: the memory profiler's total wraps around all too easily!
(dolist (child (profiler-calltree-children tree))
(cl-incf total-count (profiler-calltree-count child)))
(unless (zerop total-count)
If MODE is `cpu' or `cpu+mem', time-based profiler will be started.
Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started."
(interactive
- (list (intern (completing-read "Mode (default cpu): "
- '("cpu" "mem" "cpu+mem")
- nil t nil nil "cpu"))))
+ (list (if (not (fboundp 'profiler-cpu-start)) 'mem
+ (intern (completing-read "Mode (default cpu): "
+ '("cpu" "mem" "cpu+mem")
+ nil t nil nil "cpu")))))
(cl-ecase mode
(cpu
- (sample-profiler-start profiler-sample-interval)
+ (profiler-cpu-start profiler-sample-interval)
(message "CPU profiler started"))
(mem
- (memory-profiler-start)
+ (profiler-memory-start)
(message "Memory profiler started"))
(cpu+mem
- (sample-profiler-start profiler-sample-interval)
- (memory-profiler-start)
+ (profiler-cpu-start profiler-sample-interval)
+ (profiler-memory-start)
(message "CPU and memory profiler started"))))
(defun profiler-stop ()
"Stop started profilers. Profiler logs will be kept."
(interactive)
- (cond
- ((and (sample-profiler-running-p)
- (memory-profiler-running-p))
- (sample-profiler-stop)
- (memory-profiler-stop)
- (message "CPU and memory profiler stopped"))
- ((sample-profiler-running-p)
- (sample-profiler-stop)
- (message "CPU profiler stopped"))
- ((memory-profiler-running-p)
- (memory-profiler-stop)
- (message "Memory profiler stopped"))
- (t
- (error "No profilers started"))))
+ (let ((cpu (if (fboundp 'profiler-cpu-stop) (profiler-cpu-stop)))
+ (mem (profiler-memory-stop)))
+ (message "%s profiler stopped"
+ (cond ((and mem cpu) "CPU and memory")
+ (mem "Memory")
+ (cpu "CPU")
+ (t "No")))))
(defun profiler-reset ()
"Reset profiler log."
(interactive)
- (ignore (sample-profiler-log))
- (ignore (memory-profiler-log))
+ (when (fboundp 'profiler-cpu-log)
+ (ignore (profiler-cpu-log)))
+ (ignore (profiler-memory-log))
t)
(defun profiler--report-cpu ()
- (let ((log (sample-profiler-log)))
+ (let ((log (if (fboundp 'profiler-cpu-log) (profiler-cpu-log))))
(when log
(puthash 'type 'cpu log)
(puthash 'timestamp (current-time) log)
(profiler-report-log log))))
(defun profiler--report-memory ()
- (let ((log (memory-profiler-log)))
+ (let ((log (profiler-memory-log)))
(when log
(puthash 'type 'memory log)
(puthash 'timestamp (current-time) log)
\f
;;; Profiling helpers
-(cl-defmacro with-sample-profiling ((&key interval) &rest body)
- `(unwind-protect
- (progn
- (ignore (sample-profiler-log))
- (sample-profiler-start ,interval)
- ,@body)
- (sample-profiler-stop)
- (profiler--report-cpu)))
-
-(defmacro with-memory-profiling (&rest body)
- `(unwind-protect
- (progn
- (ignore (memory-profiler-log))
- (memory-profiler-start)
- ,@body)
- (memory-profiler-stop)
- (profiler--report-memory)))
+;; (cl-defmacro with-sample-profiling ((&key interval) &rest body)
+;; `(unwind-protect
+;; (progn
+;; (ignore (profiler-cpu-log))
+;; (profiler-cpu-start ,interval)
+;; ,@body)
+;; (profiler-cpu-stop)
+;; (profiler--report-cpu)))
+
+;; (defmacro with-memory-profiling (&rest body)
+;; `(unwind-protect
+;; (progn
+;; (ignore (profiler-memory-log))
+;; (profiler-memory-start)
+;; ,@body)
+;; (profiler-memory-stop)
+;; (profiler--report-memory)))
(provide 'profiler)
;;; profiler.el ends here