reversed(top()) code tags rss about

How to make perf TUI work

November 14, 2017
[terminal] [issue] [howto] [profiling]

perf is a quite handy tool to quickly measure performance of your application on GNU/Linux without recompiling it. The only issue seemed to be inconvenience of viewing report in a pager. It turned into concern after realising that it should start TUI on perf report by default, but for some reason it didn’t.

Basic usage

Everything is quite simple:

perf record -g command arg1 arg2
perf report

Front-ends

There are three ways of viewing report which can be selected via options:

  1. --stdio runs a pager.
  2. --tui should start TUI (default when output is a tty).
  3. --gtk starts simple GTK application, which seems to only be able to display table of results without any actions which are available in the TUI.

The issue

Even explicitly specifying --tui didn’t make TUI start. The situation got even more confusing after seeing via strace that libncurses is loaded by the process.

Since the issue doesn’t seem to happen to many people according to an Internet search, the next step was to look at the sources, with the first result giving the clue of what’s actually going on (from /usr/src/linux/tools/perf/config/Makefile):

  # ...
  ifneq ($(feature-libslang), 1)
    msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
    NO_SLANG := 1
  else
  # ...

The solution

Since TUI just gets silently disabled during build if libslang isn’t available, the obvious solution is to install S-Lang and rebuild perf.

The TUI itself unfortunately doesn’t have Vim-like key bindings and since all keys are hard-coded it can’t be configured. Anyway, it’s more convenient than a pager where one needs to rerun perf multiple times with different options.

Advice to software developers

Either drop options on disabling a feature or print a warning when user tries to use them. Another useful thing to do is to mention how things are build in --version information or even actually stopping build instead of just printing a warning, which is easy to miss.