Skip to content

Instantly share code, notes, and snippets.

@abel0b
Last active April 15, 2025 15:13
Show Gist options
  • Save abel0b/b1881e41b9e1c4b16d84e5e083c38a13 to your computer and use it in GitHub Desktop.
Save abel0b/b1881e41b9e1c4b16d84e5e083c38a13 to your computer and use it in GitHub Desktop.
Install perf on WSL 2
apt install flex bison
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8
sudo cp perf /usr/local/bin
@lcrownover
Copy link

Looks like it may be broken on newer Python versions:

util/scripting-engines/trace-event-python.c: In function ‘python_start_scrip’:
util/scripting-engines/trace-event-python.c:1851:9: error: ‘PySys_SetArgv’ is deprecated [-Werror=deprecated-declarations]
 1851 |         PySys_SetArgv(argc + 1, command_line);
      |         ^~~~~~~~~~~~~
In file included from /home/lcrown/.pyenv/versions/3.11.4/include/python3.11/Python.h:96,
                 from util/scripting-engines/trace-event-python.c:22:
/home/lcrown/.pyenv/versions/3.11.4/include/python3.11/sysmodule.h:13:38: note: declared here
   13 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
      |                                      ^~~~~~~~~~~~~
  CC      util/intel-bts.o
  LD      util/arm-spe-decoder/perf-in.o
  CC      util/arm-spe.o
  CC      util/s390-cpumsf.o
  CC      util/parse-branch-options.o
  CC      util/dump-insn.o
  CC      util/parse-regs-options.o
  CC      util/parse-sublevel-options.o
  CC      util/term.o
  CC      util/help-unknown-cmd.o
  CC      util/dlfilter.o
  CC      util/mem-events.o
  CC      util/vsprintf.o
  CC      util/units.o
  CC      util/time-utils.o
  BISON   util/expr-bison.c
  CC      util/branch.o
  CC      util/mem2node.o
  CC      util/clockid.o
  CC      util/bpf-loader.o
  CC      util/bpf_map.o
  CC      util/bpf-prologue.o
  CC      util/symbol-elf.o
  CC      util/probe-file.o
  CC      util/probe-event.o
  CC      util/probe-finder.o
  CC      util/dwarf-aux.o
  CC      util/dwarf-regs.o
cc1: all warnings being treated as errors
  CC      util/unwind-libunwind-local.o
make[5]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:96: util/scripting-engines/trace-event-python.o] Error 1
make[4]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:139: scripting-engines] Error 2
make[4]: *** Waiting for unfinished jobs....
  LD      util/intel-pt-decoder/perf-in.o
make[3]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:139: util] Error 2
make[2]: *** [Makefile.perf:658: perf-in.o] Error 2
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

@bighunter513
Copy link

same problem with you ~~

@bighunter513
Copy link

Looks like it may be broken on newer Python versions:

util/scripting-engines/trace-event-python.c: In function ‘python_start_scrip’:
util/scripting-engines/trace-event-python.c:1851:9: error: ‘PySys_SetArgv’ is deprecated [-Werror=deprecated-declarations]
 1851 |         PySys_SetArgv(argc + 1, command_line);
      |         ^~~~~~~~~~~~~
In file included from /home/lcrown/.pyenv/versions/3.11.4/include/python3.11/Python.h:96,
                 from util/scripting-engines/trace-event-python.c:22:
/home/lcrown/.pyenv/versions/3.11.4/include/python3.11/sysmodule.h:13:38: note: declared here
   13 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
      |                                      ^~~~~~~~~~~~~
  CC      util/intel-bts.o
  LD      util/arm-spe-decoder/perf-in.o
  CC      util/arm-spe.o
  CC      util/s390-cpumsf.o
  CC      util/parse-branch-options.o
  CC      util/dump-insn.o
  CC      util/parse-regs-options.o
  CC      util/parse-sublevel-options.o
  CC      util/term.o
  CC      util/help-unknown-cmd.o
  CC      util/dlfilter.o
  CC      util/mem-events.o
  CC      util/vsprintf.o
  CC      util/units.o
  CC      util/time-utils.o
  BISON   util/expr-bison.c
  CC      util/branch.o
  CC      util/mem2node.o
  CC      util/clockid.o
  CC      util/bpf-loader.o
  CC      util/bpf_map.o
  CC      util/bpf-prologue.o
  CC      util/symbol-elf.o
  CC      util/probe-file.o
  CC      util/probe-event.o
  CC      util/probe-finder.o
  CC      util/dwarf-aux.o
  CC      util/dwarf-regs.o
cc1: all warnings being treated as errors
  CC      util/unwind-libunwind-local.o
make[5]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:96: util/scripting-engines/trace-event-python.o] Error 1
make[4]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:139: scripting-engines] Error 2
make[4]: *** Waiting for unfinished jobs....
  LD      util/intel-pt-decoder/perf-in.o
make[3]: *** [/home/lcrown/code/repos/WSL2-Linux-Kernel/tools/build/Makefile.build:139: util] Error 2
make[2]: *** [Makefile.perf:658: perf-in.o] Error 2
make[1]: *** [Makefile.perf:238: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

yes, python 3.10.12 is ok, but 3.11 will broken

@dinhani
Copy link

dinhani commented Mar 9, 2024

Downgraded to Python 3.10.13 and it also worked.

@zxcqirara
Copy link

Downgraded to Python 3.10.13 and it also worked.

Ty, worked

@abdennour
Copy link

what about WSL1 ?

@zxcqirara
Copy link

Why do you even use it?

@vaqxai
Copy link

vaqxai commented Aug 14, 2024

What about this one?

In file included from /home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/evsel.c:43:
/home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/trace-event.h:152:62: error: operator '&&' has no right operand
  152 | #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
      |                                                              ^~
error: command '/usr/bin/gcc' failed with exit code 1

@NyxWh1sper
Copy link

What about this one?

In file included from /home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/evsel.c:43:
/home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/trace-event.h:152:62: error: operator '&&' has no right operand
  152 | #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
      |                                                              ^~
error: command '/usr/bin/gcc' failed with exit code 1

I delete ./util/debug.c:31 and it works for me.

@crucinal1
Copy link

What about this one?

In file included from /home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/evsel.c:43:
/home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/trace-event.h:152:62: error: operator '&&' has no right operand
  152 | #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
      |                                                              ^~
error: command '/usr/bin/gcc' failed with exit code 1

I delete ./util/debug.c:31 and it works for me.

didn't work for me

@Gabrielcarvfer
Copy link

Also missing libpfm4-dev libtraceevent-dev pkg-config

@abdeldiaz
Copy link

abdeldiaz commented Oct 23, 2024

With sudo apt install libpfm4-dev libtraceevent-dev pkg-config the compilation error issue get solved.

@OmarZohir
Copy link

With sudo apt install libpfm4-dev libtraceevent-dev pkg-config the compilation error issue get solved.

Had the same issue as crucinal1, and that solution worked.

@Dino1844
Copy link

With sudo apt install libpfm4-dev libtraceevent-dev pkg-config the compilation error issue get solved.

Thanks, that works.

@ChrisJefferson
Copy link

For people seeing errors, try make -j8 WERROR=0, as the kernel automatically turns warning into errors. This stops that behaviour.

@ghj1222
Copy link

ghj1222 commented Mar 2, 2025

What about this one?

In file included from /home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/evsel.c:43:
/home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/trace-event.h:152:62: error: operator '&&' has no right operand
  152 | #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
      |                                                              ^~
error: command '/usr/bin/gcc' failed with exit code 1

apt install pkg-config and it works for me

@ryanrhu
Copy link

ryanrhu commented Mar 4, 2025

What about this one?

In file included from /home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/evsel.c:43:
/home/vaqxai/perf-install/perf-6.9.0/tools/perf/util/trace-event.h:152:62: error: operator '&&' has no right operand
  152 | #if defined(LIBTRACEEVENT_VERSION) &&  LIBTRACEEVENT_VERSION >= MAKE_LIBTRACEEVENT_VERSION(1, 5, 0)
      |                                                              ^~
error: command '/usr/bin/gcc' failed with exit code 1

apt install pkg-config and it works for me

finally it work, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment