How can I make perf script -g python work?

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