Tutorials

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.

1
2
(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.

https://d33wubrfki0l68.cloudfront.net/480baabfdf0ffcfe58bc1f1026553d51f565a94f/3f2b3/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):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(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.

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

And here is a minor mode to do it:

1
2
3
4
5
6
7
8
9
(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)))

https://d33wubrfki0l68.cloudfront.net/f3d6a6a9fe2ebec4f51c7e0cbd2aa649c52341d0/a0e5a/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.