avatar Kisaragi Hiu

Setting the width of Emacs profiler reports

TL;DR: setf the caar of profiler-report-cpu-line-format and profiler-report-memory-line-format to a larger width (default 50 and 55).

Update 2021-03-10: As of this commit on 2020-12-22 the profiler layout has been changed for Emacs 28, putting function names at the rightmost column, preventing them from being truncated. So this article only applies to Emacs up to 27.

(setf (caar profiler-report-cpu-line-format) 80
      (caar profiler-report-memory-line-format) 80)

Emacs's profiler reports have a fixed width, which makes debugging deeply nested function calls difficult.

/emacs-26.2-profiler.png

Ideally the columns would be resized along with the window, or perhaps profiler.el should define its formatting variables with defcustom. Either way, it is still relatively easy to change the format.

The formatting is stored in two variables, profiler-report-cpu-line-format and profiler-report-memory-line-format. They're not explicitly documented, but turns out their caar fields specify their widths.

In profiler.el (comments added):

(defvar profiler-report-cpu-line-format
  ;; ↓ this
  '((50 left)
    (24 right ((19 right)
	       (5 right)))))

(defvar profiler-report-memory-line-format
  ;; ↓ this
  '((55 left)
    (19 right ((14 right profiler-format-number)
	       (5 right)))))

To change the width of lines in the profiler report, simply set these to what you want.

(setf (caar profiler-report-cpu-line-format) 80
      (caar profiler-report-memory-line-format) 80)

And here is a minor mode to do it:

(require 'profiler)
(define-minor-mode kisaragi/profiler-wide-mode
  "Minor mode to widen profiler reports."
  :global t
  (if kisaragi/profiler-wide-mode
      (setf (caar profiler-report-cpu-line-format) 80
            (caar profiler-report-memory-line-format) 80)
    (setf (caar profiler-report-cpu-line-format) 50
          (caar profiler-report-memory-line-format) 55)))

/emacs-26.2-profiler-width-80.png

This is a solution to this StackExchange question. Specifically, a comment there pointed out that profiler-report mentions "width", which led me to find the relevant variables.