8

After installing perf with the linux-tools-common package, I still can't use the python/perl scripting abilities.

$ sudo perf script -g python
Python scripting not supported.  Install libpython and rebuild perf to enable it.
For example:
  # apt-get install python-dev (ubuntu)
  # yum install python-devel (Fedora)
  etc.

How can I install a perf version with scripting support, in Ubuntu?

7
  • I was just googling for an answer myself and came across this question. I'd like to extract each and every captured callstack.
    – Will
    Jan 26, 2015 at 21:51
  • @Will extracting callstacks is possible even without scripting support. The easiest way is perf report --stdio. Jan 27, 2015 at 6:55
  • Yes, unfortunately the call sacks in the raw output aren't annotated with function and library names. I've been trying to work it out by also looking at the MMAP events etc. Just not easy.
    – Will
    Jan 27, 2015 at 7:47
  • @Will if you don't have symbol information perf script won't help you here. Try installing debuginfo packages for relevant programs, see also brendangregg.com/blog/2014-09-11/perf-kernel-line-tracing.html Jan 27, 2015 at 9:19
  • Yes yes yes. When I use the standard perf reports I get symbol information; when I look at the raw dump the symbols aren't resolved.
    – Will
    Jan 27, 2015 at 9:36

1 Answer 1

6

Since Raring (13.04), perf is built without Python scripting enabled “to avoid a Python build dependency”. This came as a nasty shock to people like me who used perf in 12.04 LTS and upgraded to 14.04 LTS. This is documented in the debian-master/changelog file in the Ubuntu kernel git repos.

In short, if your kernel is 3.8.0-6.11 or later, you are — to use the precise technical terminology — “shit outta luck”: you have to build your own perf.

If you decide to do this the Ubuntu way, which is actually quite easy, you can google for tutorials with varying levels of detail (e.g. here or here). Once you have reached the stage where you have cloned the Ubuntu kernel git repo appropriate to your release and have checked out the tag corresponding to your current kernel (if your current kernel is 3.13.0-48-generic, the tag will be something like 3.13.0-48.80, i.e. with an extra number on the end), you must edit (w.r.t the root of the git repo) debian/rules.d/2-binary-arch.mk and remove NO_LIBPYTHON=1 from one of the make command-lines (it's used in \#ifdef checks, so changing it to NO_LIBPYTHON=0 won't work). This clause only appears once, so just search for it and take it out.

The distro's linux-tools-3.x.x-y package contains the actual perf binary, which ends up in /usr/lib/linux-tools-3.x.x-y/perf. This is built with fakeroot debian/rules binary-arch. This rule (binary-arch) takes a long time to build (~25 mins on my i7 laptop). If I'd paid more attention, I could probably have picked one that didn't build every kernel variant and module. Suggestions welcome.

Assuming that you've made no other changes, once this finishes, the package you want is linux-tools-3.13.0-48_3.13.0-48.80_amd64.deb (modulo your kernel version): this is the one with the binary, rather than symlinks or shell wrappers.

There may be a couple of other linux-tools packages, depending on exactly what you've built, linux-tools-3.13.0-48-generic_3.13.0-48.80_amd64.deb just contains symlinks and stuff (less likely to be different) and linux-tools-common_3.13.0-48.80_all.deb just contains the short generic perf wrapper script that ends up in /usr/bin; the latter is built with fakeroot debian/rules binary-indep.

You can install your new Python-capable perf with

# sudo dpkg -i linux-tools-3.13.0-48_3.13.0-48.80_amd64.deb

You can install as much, or as little, of the kernel, kernel modules, other tools packages, etc. as you're comfortable with. In principle, these should all be the same. I just installed the one package and everything seems to work OK: I have my Python-capable perf back.

Of course, you're going to have to do a lot of this again (from a git pull and checkout of the new tag onward) next time there's a kernel update. I'll have to keep up with this myself, so I was half-thinking of sticking my .debs into a PPA, but there doesn't seem to be much interest (this question upvoted twice in 3 months).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .