Setting the width of Emacs profiler reports

2019/05/16

C: Tutorials

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).


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

truncated at column 29

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 documented, but through a bit of guesswork it happens that their caar is the width value.

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)))

not truncated even at column 37

I'm sure there are ways to make the width update when Emacs is resized, but IMO that should be implemented inside profiler.el itself, not as an extension. For now, this is a good enough workaround for me.

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.