2012-08-22 06:38:59 +00:00
|
|
|
|
;;; profiler.el --- UI and helper functions for Emacs's native profiler -*- lexical-binding: t -*-
|
|
|
|
|
|
2013-01-01 09:11:05 +00:00
|
|
|
|
;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Tomohiro Matsuyama <tomo@cx4a.org>
|
|
|
|
|
;; Keywords: lisp
|
|
|
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
2012-09-24 21:15:53 +00:00
|
|
|
|
;;
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(require 'cl-lib)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defgroup profiler nil
|
|
|
|
|
"Emacs profiler."
|
|
|
|
|
:group 'lisp
|
2012-10-06 20:30:26 +00:00
|
|
|
|
:version "24.3"
|
2012-08-22 06:38:59 +00:00
|
|
|
|
:prefix "profiler-")
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defconst profiler-version "24.3")
|
|
|
|
|
|
2012-10-02 06:30:40 +00:00
|
|
|
|
(defcustom profiler-sampling-interval 1000000
|
|
|
|
|
"Default sampling interval in nanoseconds."
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
:type 'integer
|
|
|
|
|
:group 'profiler)
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
;;; Utilities
|
|
|
|
|
|
|
|
|
|
(defun profiler-ensure-string (object)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(cond ((stringp object)
|
|
|
|
|
object)
|
|
|
|
|
((symbolp object)
|
|
|
|
|
(symbol-name object))
|
|
|
|
|
((numberp object)
|
|
|
|
|
(number-to-string object))
|
|
|
|
|
(t
|
|
|
|
|
(format "%s" object))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-format-percent (number divisor)
|
|
|
|
|
(concat (number-to-string (/ (* number 100) divisor)) "%"))
|
|
|
|
|
|
|
|
|
|
(defun profiler-format-number (number)
|
|
|
|
|
"Format NUMBER in human readable string."
|
|
|
|
|
(if (and (integerp number) (> number 0))
|
|
|
|
|
(cl-loop with i = (% (1+ (floor (log10 number))) 3)
|
|
|
|
|
for c in (append (number-to-string number) nil)
|
|
|
|
|
if (= i 0)
|
|
|
|
|
collect ?, into s
|
|
|
|
|
and do (setq i 3)
|
|
|
|
|
collect c into s
|
|
|
|
|
do (cl-decf i)
|
|
|
|
|
finally return
|
|
|
|
|
(apply 'string (if (eq (car s) ?,) (cdr s) s)))
|
|
|
|
|
(profiler-ensure-string number)))
|
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(defun profiler-format (fmt &rest args)
|
2012-08-22 06:49:34 +00:00
|
|
|
|
(cl-loop for (width align subfmt) in fmt
|
|
|
|
|
for arg in args
|
2012-08-22 12:38:39 +00:00
|
|
|
|
for str = (cond
|
|
|
|
|
((consp subfmt)
|
|
|
|
|
(apply 'profiler-format subfmt arg))
|
|
|
|
|
((stringp subfmt)
|
|
|
|
|
(format subfmt arg))
|
|
|
|
|
((and (symbolp subfmt)
|
|
|
|
|
(fboundp subfmt))
|
|
|
|
|
(funcall subfmt arg))
|
|
|
|
|
(t
|
|
|
|
|
(profiler-ensure-string arg)))
|
2012-08-22 06:49:34 +00:00
|
|
|
|
for len = (length str)
|
|
|
|
|
if (< width len)
|
|
|
|
|
collect (substring str 0 width) into frags
|
|
|
|
|
else
|
|
|
|
|
collect
|
|
|
|
|
(let ((padding (make-string (- width len) ?\s)))
|
|
|
|
|
(cl-ecase align
|
|
|
|
|
(left (concat str padding))
|
|
|
|
|
(right (concat padding str))))
|
|
|
|
|
into frags
|
|
|
|
|
finally return (apply #'concat frags)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-08-22 12:38:39 +00:00
|
|
|
|
|
2012-08-23 12:11:12 +00:00
|
|
|
|
;;; Entries
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-format-entry (entry)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Format ENTRY in human readable string. ENTRY would be a
|
|
|
|
|
function name of a function itself."
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(cond ((memq (car-safe entry) '(closure lambda))
|
|
|
|
|
(format "#<lambda 0x%x>" (sxhash entry)))
|
|
|
|
|
((byte-code-function-p entry)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(format "#<compiled 0x%x>" (sxhash entry)))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
((or (subrp entry) (symbolp entry) (stringp entry))
|
|
|
|
|
(format "%s" entry))
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(t
|
|
|
|
|
(format "#<unknown 0x%x>" (sxhash entry)))))
|
2012-08-22 12:38:39 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-fixup-entry (entry)
|
|
|
|
|
(if (symbolp entry)
|
|
|
|
|
entry
|
|
|
|
|
(profiler-format-entry entry)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Backtraces
|
|
|
|
|
|
|
|
|
|
(defun profiler-fixup-backtrace (backtrace)
|
|
|
|
|
(apply 'vector (mapcar 'profiler-fixup-entry backtrace)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Logs
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
;; The C code returns the log in the form of a hash-table where the keys are
|
|
|
|
|
;; vectors (of size profiler-max-stack-depth, holding truncated
|
|
|
|
|
;; backtraces, where the first element is the top of the stack) and
|
|
|
|
|
;; the values are integers (which count how many times this backtrace
|
|
|
|
|
;; has been seen, multiplied by a "weight factor" which is either the
|
2012-09-30 22:21:25 +00:00
|
|
|
|
;; sampling-interval or the memory being allocated).
|
|
|
|
|
|
|
|
|
|
(defun profiler-compare-logs (log1 log2)
|
|
|
|
|
"Compare LOG1 with LOG2 and return diff."
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(let ((newlog (make-hash-table :test 'equal)))
|
|
|
|
|
;; Make a copy of `log1' into `newlog'.
|
|
|
|
|
(maphash (lambda (backtrace count) (puthash backtrace count newlog))
|
|
|
|
|
log1)
|
|
|
|
|
(maphash (lambda (backtrace count)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(puthash backtrace (- (gethash backtrace log1 0) count)
|
|
|
|
|
newlog))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
log2)
|
|
|
|
|
newlog))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-fixup-log (log)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(let ((newlog (make-hash-table :test 'equal)))
|
|
|
|
|
(maphash (lambda (backtrace count)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(puthash (profiler-fixup-backtrace backtrace)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
count newlog))
|
|
|
|
|
log)
|
|
|
|
|
newlog))
|
2012-08-23 12:11:12 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
|
|
|
|
|
;;; Profiles
|
|
|
|
|
|
|
|
|
|
(cl-defstruct (profiler-profile (:type vector)
|
|
|
|
|
(:constructor profiler-make-profile))
|
|
|
|
|
(tag 'profiler-profile)
|
|
|
|
|
(version profiler-version)
|
|
|
|
|
;; - `type' has a value indicating the kind of profile (`memory' or `cpu').
|
|
|
|
|
;; - `log' indicates the profile log.
|
|
|
|
|
;; - `timestamp' has a value giving the time when the profile was obtained.
|
|
|
|
|
;; - `diff-p' indicates if this profile represents a diff between two profiles.
|
|
|
|
|
type log timestamp diff-p)
|
|
|
|
|
|
|
|
|
|
(defun profiler-compare-profiles (profile1 profile2)
|
|
|
|
|
"Compare PROFILE1 with PROFILE2 and return diff."
|
|
|
|
|
(unless (eq (profiler-profile-type profile1)
|
|
|
|
|
(profiler-profile-type profile2))
|
|
|
|
|
(error "Can't compare different type of profiles"))
|
|
|
|
|
(profiler-make-profile
|
|
|
|
|
:type (profiler-profile-type profile1)
|
|
|
|
|
:timestamp (current-time)
|
|
|
|
|
:diff-p t
|
|
|
|
|
:log (profiler-compare-logs
|
|
|
|
|
(profiler-profile-log profile1)
|
|
|
|
|
(profiler-profile-log profile2))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-fixup-profile (profile)
|
|
|
|
|
"Fixup PROFILE so that the profile could be serialized into file."
|
|
|
|
|
(profiler-make-profile
|
|
|
|
|
:type (profiler-profile-type profile)
|
|
|
|
|
:timestamp (profiler-profile-timestamp profile)
|
|
|
|
|
:diff-p (profiler-profile-diff-p profile)
|
|
|
|
|
:log (profiler-fixup-log (profiler-profile-log profile))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-write-profile (profile filename &optional confirm)
|
|
|
|
|
"Write PROFILE into file FILENAME."
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(let (print-level print-length)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(print (profiler-fixup-profile profile)
|
|
|
|
|
(current-buffer)))
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(write-file filename confirm)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-read-profile (filename)
|
|
|
|
|
"Read profile from file FILENAME."
|
|
|
|
|
;; FIXME: tag and version check
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(with-temp-buffer
|
|
|
|
|
(insert-file-contents filename)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(read (current-buffer))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-cpu-profile ()
|
|
|
|
|
"Return CPU profile."
|
|
|
|
|
(when (and (fboundp 'profiler-cpu-running-p)
|
|
|
|
|
(fboundp 'profiler-cpu-log)
|
|
|
|
|
(profiler-cpu-running-p))
|
|
|
|
|
(profiler-make-profile
|
|
|
|
|
:type 'cpu
|
|
|
|
|
:timestamp (current-time)
|
|
|
|
|
:log (profiler-cpu-log))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-memory-profile ()
|
|
|
|
|
"Return memory profile."
|
|
|
|
|
(when (profiler-memory-running-p)
|
|
|
|
|
(profiler-make-profile
|
|
|
|
|
:type 'memory
|
|
|
|
|
:timestamp (current-time)
|
|
|
|
|
:log (profiler-memory-log))))
|
|
|
|
|
|
2012-08-23 12:11:12 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
;;; Calltrees
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-08-22 06:49:34 +00:00
|
|
|
|
(cl-defstruct (profiler-calltree (:constructor profiler-make-calltree))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
entry
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(count 0) (count-percent "")
|
2012-08-22 06:38:59 +00:00
|
|
|
|
parent children)
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-leaf-p (tree)
|
|
|
|
|
(null (profiler-calltree-children tree)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-count< (a b)
|
|
|
|
|
(cond ((eq (profiler-calltree-entry a) t) t)
|
|
|
|
|
((eq (profiler-calltree-entry b) t) nil)
|
|
|
|
|
(t (< (profiler-calltree-count a)
|
|
|
|
|
(profiler-calltree-count b)))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-count> (a b)
|
|
|
|
|
(not (profiler-calltree-count< a b)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-depth (tree)
|
|
|
|
|
(let ((parent (profiler-calltree-parent tree)))
|
|
|
|
|
(if (null parent)
|
|
|
|
|
0
|
|
|
|
|
(1+ (profiler-calltree-depth parent)))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-find (tree entry)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Return a child tree of ENTRY under TREE."
|
|
|
|
|
(let (result (children (profiler-calltree-children tree)))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
;; FIXME: Use `assoc'.
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(while (and children (null result))
|
|
|
|
|
(let ((child (car children)))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(when (equal (profiler-calltree-entry child) entry)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(setq result child))
|
|
|
|
|
(setq children (cdr children))))
|
|
|
|
|
result))
|
|
|
|
|
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(defun profiler-calltree-walk (calltree function)
|
|
|
|
|
(funcall function calltree)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(dolist (child (profiler-calltree-children calltree))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(profiler-calltree-walk child function)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-build-1 (tree log &optional reverse)
|
2012-09-26 15:19:10 +00:00
|
|
|
|
;; 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.
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(maphash
|
|
|
|
|
(lambda (backtrace count)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(let ((node tree)
|
|
|
|
|
(max (length backtrace)))
|
|
|
|
|
(dotimes (i max)
|
|
|
|
|
(let ((entry (aref backtrace (if reverse i (- max i 1)))))
|
|
|
|
|
(when entry
|
|
|
|
|
(let ((child (profiler-calltree-find node entry)))
|
|
|
|
|
(unless child
|
|
|
|
|
(setq child (profiler-make-calltree
|
|
|
|
|
:entry entry :parent node))
|
|
|
|
|
(push child (profiler-calltree-children node)))
|
|
|
|
|
(cl-incf (profiler-calltree-count child) count)
|
|
|
|
|
(setq node child)))))))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
log))
|
2012-08-23 12:11:12 +00:00
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(defun profiler-calltree-compute-percentages (tree)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(let ((total-count 0))
|
2012-09-24 21:15:53 +00:00
|
|
|
|
;; FIXME: the memory profiler's total wraps around all too easily!
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(dolist (child (profiler-calltree-children tree))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(cl-incf total-count (profiler-calltree-count child)))
|
|
|
|
|
(unless (zerop total-count)
|
|
|
|
|
(profiler-calltree-walk
|
|
|
|
|
tree (lambda (node)
|
|
|
|
|
(setf (profiler-calltree-count-percent node)
|
|
|
|
|
(profiler-format-percent (profiler-calltree-count node)
|
|
|
|
|
total-count)))))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-08-22 06:49:34 +00:00
|
|
|
|
(cl-defun profiler-calltree-build (log &key reverse)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(let ((tree (profiler-make-calltree)))
|
|
|
|
|
(profiler-calltree-build-1 tree log reverse)
|
|
|
|
|
(profiler-calltree-compute-percentages tree)
|
|
|
|
|
tree))
|
|
|
|
|
|
|
|
|
|
(defun profiler-calltree-sort (tree predicate)
|
|
|
|
|
(let ((children (profiler-calltree-children tree)))
|
|
|
|
|
(setf (profiler-calltree-children tree) (sort children predicate))
|
|
|
|
|
(dolist (child (profiler-calltree-children tree))
|
|
|
|
|
(profiler-calltree-sort child predicate))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Report rendering
|
|
|
|
|
|
|
|
|
|
(defcustom profiler-report-closed-mark "+"
|
|
|
|
|
"An indicator of closed calltrees."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'profiler)
|
|
|
|
|
|
|
|
|
|
(defcustom profiler-report-open-mark "-"
|
|
|
|
|
"An indicator of open calltrees."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'profiler)
|
|
|
|
|
|
|
|
|
|
(defcustom profiler-report-leaf-mark " "
|
|
|
|
|
"An indicator of calltree leaves."
|
|
|
|
|
:type 'string
|
|
|
|
|
:group 'profiler)
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defvar profiler-report-cpu-line-format
|
2012-10-02 06:30:40 +00:00
|
|
|
|
'((50 left)
|
|
|
|
|
(24 right ((19 right)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(5 right)))))
|
|
|
|
|
|
|
|
|
|
(defvar profiler-report-memory-line-format
|
2012-08-22 12:38:39 +00:00
|
|
|
|
'((55 left)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(19 right ((14 right profiler-format-number)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(5 right)))))
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defvar-local profiler-report-profile nil
|
|
|
|
|
"The current profile.")
|
2012-08-23 12:11:12 +00:00
|
|
|
|
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(defvar-local profiler-report-reversed nil
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"True if calltree is rendered in bottom-up. Do not touch this
|
|
|
|
|
variable directly.")
|
|
|
|
|
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(defvar-local profiler-report-order nil
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"The value can be `ascending' or `descending'. Do not touch
|
|
|
|
|
this variable directly.")
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-report-make-entry-part (entry)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(let ((string (cond
|
|
|
|
|
((eq entry t)
|
|
|
|
|
"Others")
|
|
|
|
|
((and (symbolp entry)
|
|
|
|
|
(fboundp entry))
|
|
|
|
|
(propertize (symbol-name entry)
|
|
|
|
|
'face 'link
|
|
|
|
|
'mouse-face 'highlight
|
2012-10-27 09:54:04 +00:00
|
|
|
|
'help-echo "\
|
|
|
|
|
mouse-2: jump to definition\n\
|
|
|
|
|
RET: expand or collapse"))
|
2012-08-23 12:11:12 +00:00
|
|
|
|
(t
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-format-entry entry)))))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(propertize string 'profiler-entry entry)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-report-make-name-part (tree)
|
|
|
|
|
(let* ((entry (profiler-calltree-entry tree))
|
|
|
|
|
(depth (profiler-calltree-depth tree))
|
|
|
|
|
(indent (make-string (* (1- depth) 2) ?\s))
|
|
|
|
|
(mark (if (profiler-calltree-leaf-p tree)
|
|
|
|
|
profiler-report-leaf-mark
|
|
|
|
|
profiler-report-closed-mark))
|
|
|
|
|
(entry (profiler-report-make-entry-part entry)))
|
|
|
|
|
(format "%s%s %s" indent mark entry)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-header-line-format (fmt &rest args)
|
|
|
|
|
(let* ((header (apply 'profiler-format fmt args))
|
|
|
|
|
(escaped (replace-regexp-in-string "%" "%%" header)))
|
|
|
|
|
(concat " " escaped)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-line-format (tree)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(let ((diff-p (profiler-profile-diff-p profiler-report-profile))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(name-part (profiler-report-make-name-part tree))
|
|
|
|
|
(count (profiler-calltree-count tree))
|
|
|
|
|
(count-percent (profiler-calltree-count-percent tree)))
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-format (cl-ecase (profiler-profile-type profiler-report-profile)
|
|
|
|
|
(cpu profiler-report-cpu-line-format)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(memory profiler-report-memory-line-format))
|
|
|
|
|
name-part
|
|
|
|
|
(if diff-p
|
|
|
|
|
(list (if (> count 0)
|
|
|
|
|
(format "+%s" count)
|
|
|
|
|
count)
|
|
|
|
|
"")
|
|
|
|
|
(list count count-percent)))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-report-insert-calltree (tree)
|
|
|
|
|
(let ((line (profiler-report-line-format tree)))
|
|
|
|
|
(insert (propertize (concat line "\n") 'calltree tree))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-insert-calltree-children (tree)
|
|
|
|
|
(mapc 'profiler-report-insert-calltree
|
|
|
|
|
(profiler-calltree-children tree)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Report mode
|
|
|
|
|
|
|
|
|
|
(defvar profiler-report-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
;; FIXME: Add menu.
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(define-key map "n" 'profiler-report-next-entry)
|
|
|
|
|
(define-key map "p" 'profiler-report-previous-entry)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
;; I find it annoying more than helpful to not be able to navigate
|
|
|
|
|
;; normally with the cursor keys. --Stef
|
|
|
|
|
;; (define-key map [down] 'profiler-report-next-entry)
|
|
|
|
|
;; (define-key map [up] 'profiler-report-previous-entry)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(define-key map "\r" 'profiler-report-toggle-entry)
|
|
|
|
|
(define-key map "\t" 'profiler-report-toggle-entry)
|
|
|
|
|
(define-key map "i" 'profiler-report-toggle-entry)
|
|
|
|
|
(define-key map "f" 'profiler-report-find-entry)
|
|
|
|
|
(define-key map "j" 'profiler-report-find-entry)
|
|
|
|
|
(define-key map [mouse-2] 'profiler-report-find-entry)
|
|
|
|
|
(define-key map "d" 'profiler-report-describe-entry)
|
|
|
|
|
(define-key map "C" 'profiler-report-render-calltree)
|
|
|
|
|
(define-key map "B" 'profiler-report-render-reversed-calltree)
|
|
|
|
|
(define-key map "A" 'profiler-report-ascending-sort)
|
|
|
|
|
(define-key map "D" 'profiler-report-descending-sort)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(define-key map "=" 'profiler-report-compare-profile)
|
|
|
|
|
(define-key map (kbd "C-x C-w") 'profiler-report-write-profile)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(define-key map "q" 'quit-window)
|
|
|
|
|
map))
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-make-buffer-name (profile)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(format "*%s-Profiler-Report %s*"
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(cl-ecase (profiler-profile-type profile) (cpu 'CPU) (memory 'Memory))
|
|
|
|
|
(format-time-string "%Y-%m-%d %T" (profiler-profile-timestamp profile))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-setup-buffer-1 (profile)
|
|
|
|
|
"Make a buffer for PROFILE and return it."
|
|
|
|
|
(let* ((buf-name (profiler-report-make-buffer-name profile))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(buffer (get-buffer-create buf-name)))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(profiler-report-mode)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(setq profiler-report-profile profile
|
2012-08-22 06:38:59 +00:00
|
|
|
|
profiler-report-reversed nil
|
|
|
|
|
profiler-report-order 'descending))
|
|
|
|
|
buffer))
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-setup-buffer (profile)
|
|
|
|
|
"Make a buffer for PROFILE with rendering the profile and
|
|
|
|
|
return it."
|
|
|
|
|
(let ((buffer (profiler-report-setup-buffer-1 profile)))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(profiler-report-render-calltree))
|
|
|
|
|
buffer))
|
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(define-derived-mode profiler-report-mode special-mode "Profiler-Report"
|
|
|
|
|
"Profiler Report Mode."
|
|
|
|
|
(setq buffer-read-only t
|
|
|
|
|
buffer-undo-list t
|
|
|
|
|
truncate-lines t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Report commands
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-calltree-at-point (&optional point)
|
|
|
|
|
(get-text-property (or point (point)) 'calltree))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-report-move-to-entry ()
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(let ((point (next-single-property-change
|
|
|
|
|
(line-beginning-position) 'profiler-entry)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(if point
|
|
|
|
|
(goto-char point)
|
|
|
|
|
(back-to-indentation))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-next-entry ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Move cursor to next entry."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(forward-line)
|
|
|
|
|
(profiler-report-move-to-entry))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-previous-entry ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Move cursor to previous entry."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(profiler-report-move-to-entry))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-expand-entry ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Expand entry at point."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(when (search-forward (concat profiler-report-closed-mark " ")
|
|
|
|
|
(line-end-position) t)
|
|
|
|
|
(let ((tree (profiler-report-calltree-at-point)))
|
|
|
|
|
(when tree
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(let ((inhibit-read-only t))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(replace-match (concat profiler-report-open-mark " "))
|
|
|
|
|
(forward-line)
|
|
|
|
|
(profiler-report-insert-calltree-children tree)
|
|
|
|
|
t))))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-collapse-entry ()
|
2012-10-05 05:57:24 +00:00
|
|
|
|
"Collapse entry at point."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(beginning-of-line)
|
|
|
|
|
(when (search-forward (concat profiler-report-open-mark " ")
|
|
|
|
|
(line-end-position) t)
|
|
|
|
|
(let* ((tree (profiler-report-calltree-at-point))
|
|
|
|
|
(depth (profiler-calltree-depth tree))
|
|
|
|
|
(start (line-beginning-position 2))
|
|
|
|
|
d)
|
|
|
|
|
(when tree
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(let ((inhibit-read-only t))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(replace-match (concat profiler-report-closed-mark " "))
|
|
|
|
|
(while (and (eq (forward-line) 0)
|
|
|
|
|
(let ((child (get-text-property (point) 'calltree)))
|
|
|
|
|
(and child
|
|
|
|
|
(numberp (setq d (profiler-calltree-depth child)))))
|
|
|
|
|
(> d depth)))
|
|
|
|
|
(delete-region start (line-beginning-position)))))
|
|
|
|
|
t)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-toggle-entry ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Expand entry at point if the tree is collapsed,
|
|
|
|
|
otherwise collapse."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(or (profiler-report-expand-entry)
|
|
|
|
|
(profiler-report-collapse-entry)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-find-entry (&optional event)
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Find entry at point."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive (list last-nonmenu-event))
|
|
|
|
|
(if event (posn-set-point (event-end event)))
|
|
|
|
|
(let ((tree (profiler-report-calltree-at-point)))
|
|
|
|
|
(when tree
|
|
|
|
|
(let ((entry (profiler-calltree-entry tree)))
|
|
|
|
|
(find-function entry)))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-describe-entry ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Describe entry at point."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(let ((tree (profiler-report-calltree-at-point)))
|
|
|
|
|
(when tree
|
|
|
|
|
(let ((entry (profiler-calltree-entry tree)))
|
|
|
|
|
(require 'help-fns)
|
|
|
|
|
(describe-function entry)))))
|
|
|
|
|
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(cl-defun profiler-report-render-calltree-1
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profile &key reverse (order 'descending))
|
|
|
|
|
(let ((calltree (profiler-calltree-build
|
|
|
|
|
(profiler-profile-log profile)
|
|
|
|
|
:reverse reverse)))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(setq header-line-format
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(cl-ecase (profiler-profile-type profile)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(cpu
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(profiler-report-header-line-format
|
2012-09-30 22:21:25 +00:00
|
|
|
|
profiler-report-cpu-line-format
|
2012-10-02 06:30:40 +00:00
|
|
|
|
"Function" (list "CPU samples" "%")))
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
(memory
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(profiler-report-header-line-format
|
|
|
|
|
profiler-report-memory-line-format
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
"Function" (list "Bytes" "%")))))
|
|
|
|
|
(let ((predicate (cl-ecase order
|
|
|
|
|
(ascending #'profiler-calltree-count<)
|
|
|
|
|
(descending #'profiler-calltree-count>))))
|
|
|
|
|
(profiler-calltree-sort calltree predicate))
|
|
|
|
|
(let ((inhibit-read-only t))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(erase-buffer)
|
|
|
|
|
(profiler-report-insert-calltree-children calltree)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(profiler-report-move-to-entry))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-rerender-calltree ()
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-report-render-calltree-1 profiler-report-profile
|
2012-08-22 06:38:59 +00:00
|
|
|
|
:reverse profiler-report-reversed
|
|
|
|
|
:order profiler-report-order))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-render-calltree ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Render calltree view."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq profiler-report-reversed nil)
|
|
|
|
|
(profiler-report-rerender-calltree))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-render-reversed-calltree ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Render reversed calltree view."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
|
|
|
|
(setq profiler-report-reversed t)
|
|
|
|
|
(profiler-report-rerender-calltree))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-ascending-sort ()
|
|
|
|
|
"Sort calltree view in ascending order."
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq profiler-report-order 'ascending)
|
|
|
|
|
(profiler-report-rerender-calltree))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-descending-sort ()
|
|
|
|
|
"Sort calltree view in descending order."
|
|
|
|
|
(interactive)
|
|
|
|
|
(setq profiler-report-order 'descending)
|
|
|
|
|
(profiler-report-rerender-calltree))
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-profile (profile)
|
|
|
|
|
(switch-to-buffer (profiler-report-setup-buffer profile)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-profile-other-window (profile)
|
|
|
|
|
(switch-to-buffer-other-window (profiler-report-setup-buffer profile)))
|
|
|
|
|
|
|
|
|
|
(defun profiler-report-profile-other-frame (profile)
|
|
|
|
|
(switch-to-buffer-other-frame (profiler-report-setup-buffer profile)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-compare-profile (buffer)
|
|
|
|
|
"Compare the current profile with another."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive (list (read-buffer "Compare to: ")))
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(let* ((profile1 (with-current-buffer buffer profiler-report-profile))
|
|
|
|
|
(profile2 profiler-report-profile)
|
|
|
|
|
(diff-profile (profiler-compare-profiles profile1 profile2)))
|
|
|
|
|
(profiler-report-profile diff-profile)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-write-profile (filename &optional confirm)
|
|
|
|
|
"Write the current profile into file FILENAME."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(list (read-file-name "Write profile: " default-directory)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(not current-prefix-arg)))
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-write-profile profiler-report-profile
|
|
|
|
|
filename
|
|
|
|
|
confirm))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Profiler commands
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun profiler-start (mode)
|
Rewrite sampler to use Elisp hash-tables.
* src/profiler.c: Remove filtering functionality.
(is_in_trace, Qgc): Remove vars.
(make_log, record_backtrace, Fsample_profiler_log):
Rewrite, using Elisp hash-tables.
(approximate_median, evict_lower_half): New functions.
(cpu_log): Rename from sample_log.
(cpu_gc_count): New var.
(Fsample_profiler_reset, Fmemory_profiler_reset): Remove.
(sigprof_handler): Add count to cpu_gc_count during GC, detected via
backtrace_list.
(block_sigprof, unblock_sigprof): Remove.
(gc_probe, mark_profiler): Remove functions.
(syms_of_profiler): Staticpro cpu_log and memory_log.
* lisp/profiler.el (profiler-sample-interval): Move before first use.
Change default to 1ms.
(profiler-entry=, profiler-backtrace-reverse, profiler-log-fixup-slot)
(profiler-calltree-elapsed<, profiler-calltree-elapsed>): Remove functions.
(profiler-entry-format): Don't use type-of.
(profiler-slot, profiler-log): Remove structs.
(profiler-log-timestamp, profiler-log-type, profiler-log-diff-p):
Redefine for new log representation.
(profiler-log-diff, profiler-log-fixup, profiler-calltree-build-1):
Rewrite for new log representation.
(profiler-calltree): Remove `elapsed' fields.
(profiler-calltree-count<, profiler-report-make-entry-part):
Remove gc special case.
(profiler-calltree-find): Use equal.
(profiler-calltree-walk): Remove `args'; rely on closures instead.
(profiler-calltree-compute-percentages-1): Remove; inlined.
(profiler-calltree-compute-percentages): Simplify.
(profiler-report-log, profiler-report-reversed)
(profiler-report-order): Use defvar-local.
(profiler-report-line-format): Remove `elapsed', do a bit of CSE.
(profiler-report-mode-map): Remove up/down bindings.
(profiler-report-make-buffer-name): Simplify by CSE.
(profiler-report-mode): Remove redundant code.
(profiler-report-expand-entry, profiler-report-collapse-entry):
Use inhibit-read-only.
(profiler-report-render-calltree-1): Simplify by CSE.
(profiler-reset): Rewrite for new subroutines.
(profiler--report-cpu): Rename from sample-profiler-report.
(profiler--report-memory): Rename from memory-profiler-report.
* src/alloc.c (Fgarbage_collect): Record itself in backtrace_list.
Don't set is_in_trace any more. Don't call mark_profiler.
Only call gc_probe for the memory profiler.
(syms_of_alloc): Define Qautomatic_gc.
* src/lisp.h (SXHASH_COMBINE): Move back to...
* src/fns.c (SXHASH_COMBINE): ...here.
* src/xdisp.c (Qautomatic_redisplay): New constant.
(redisplay_internal): Record itself in backtrace_list.
(syms_of_xdisp): Define Qautomatic_redisplay.
* .dir-locals.el (indent-tabs-mode): Remove personal preference.
2012-09-24 14:38:10 +00:00
|
|
|
|
"Start/restart profilers.
|
|
|
|
|
MODE can be one of `cpu', `mem', or `cpu+mem'.
|
|
|
|
|
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."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive
|
2012-09-26 04:02:21 +00:00
|
|
|
|
(list (if (not (fboundp 'profiler-cpu-start)) 'mem
|
|
|
|
|
(intern (completing-read "Mode (default cpu): "
|
|
|
|
|
'("cpu" "mem" "cpu+mem")
|
|
|
|
|
nil t nil nil "cpu")))))
|
2012-08-22 06:49:34 +00:00
|
|
|
|
(cl-ecase mode
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(cpu
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-cpu-start profiler-sampling-interval)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(message "CPU profiler started"))
|
2012-08-22 07:08:36 +00:00
|
|
|
|
(mem
|
2012-09-25 02:30:46 +00:00
|
|
|
|
(profiler-memory-start)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(message "Memory profiler started"))
|
2012-08-22 07:08:36 +00:00
|
|
|
|
(cpu+mem
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-cpu-start profiler-sampling-interval)
|
2012-09-25 02:30:46 +00:00
|
|
|
|
(profiler-memory-start)
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(message "CPU and memory profiler started"))))
|
|
|
|
|
|
|
|
|
|
(defun profiler-stop ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Stop started profilers. Profiler logs will be kept."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
2012-09-26 04:02:21 +00:00
|
|
|
|
(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")))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
|
|
|
|
(defun profiler-reset ()
|
2012-09-30 22:21:25 +00:00
|
|
|
|
"Reset profiler logs."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive)
|
2012-09-26 04:02:21 +00:00
|
|
|
|
(when (fboundp 'profiler-cpu-log)
|
|
|
|
|
(ignore (profiler-cpu-log)))
|
2012-09-25 02:30:46 +00:00
|
|
|
|
(ignore (profiler-memory-log))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
t)
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-cpu ()
|
|
|
|
|
(let ((profile (profiler-cpu-profile)))
|
|
|
|
|
(when profile
|
|
|
|
|
(profiler-report-profile-other-window profile))))
|
2012-08-22 09:15:17 +00:00
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-report-memory ()
|
|
|
|
|
(let ((profile (profiler-memory-profile)))
|
|
|
|
|
(when profile
|
|
|
|
|
(profiler-report-profile-other-window profile))))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-08-22 09:15:17 +00:00
|
|
|
|
(defun profiler-report ()
|
2012-08-23 12:11:12 +00:00
|
|
|
|
"Report profiling results."
|
2012-08-22 09:15:17 +00:00
|
|
|
|
(interactive)
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(profiler-report-cpu)
|
|
|
|
|
(profiler-report-memory))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun profiler-find-profile (filename)
|
|
|
|
|
"Open profile FILENAME."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (read-file-name "Find profile: " default-directory)))
|
|
|
|
|
(profiler-report-profile (profiler-read-profile filename)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun profiler-find-profile-other-window (filename)
|
|
|
|
|
"Open profile FILENAME."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (read-file-name "Find profile: " default-directory)))
|
|
|
|
|
(profiler-report-profile-other-window (profiler-read-profile filename)))
|
2012-08-22 09:15:17 +00:00
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
;;;###autoload
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(defun profiler-find-profile-other-frame (filename)
|
|
|
|
|
"Open profile FILENAME."
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(interactive
|
2012-09-30 22:21:25 +00:00
|
|
|
|
(list (read-file-name "Find profile: " default-directory)))
|
|
|
|
|
(profiler-report-profile-other-frame(profiler-read-profile filename)))
|
2012-08-22 06:38:59 +00:00
|
|
|
|
|
2012-08-22 09:15:17 +00:00
|
|
|
|
|
|
|
|
|
;;; Profiling helpers
|
|
|
|
|
|
2012-09-30 22:21:25 +00:00
|
|
|
|
;; (cl-defmacro with-cpu-profiling ((&key sampling-interval) &rest body)
|
2012-09-26 15:19:10 +00:00
|
|
|
|
;; `(unwind-protect
|
|
|
|
|
;; (progn
|
|
|
|
|
;; (ignore (profiler-cpu-log))
|
2012-09-30 22:21:25 +00:00
|
|
|
|
;; (profiler-cpu-start ,sampling-interval)
|
2012-09-26 15:19:10 +00:00
|
|
|
|
;; ,@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)))
|
2012-08-22 09:15:17 +00:00
|
|
|
|
|
2012-08-22 06:38:59 +00:00
|
|
|
|
(provide 'profiler)
|
|
|
|
|
;;; profiler.el ends here
|