Skip to content

Instantly share code, notes, and snippets.

@abel0b
Last active February 17, 2024 06:01
  • Star 81 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
@henryleberre
Copy link

Thank you!

@StephanDollberg
Copy link

Does perf stat work for people? Think perf counters are disabled? microsoft/WSL#4678

@henryleberre
Copy link

henryleberre commented Aug 19, 2020

@StephanDollberg, sadly it didn’t work for me in the end since WSL does not support them but this gist still is helpful as it will work once they do support it. I just switched to linux!

@StephanDollberg
Copy link

StephanDollberg commented Aug 20, 2020 via email

@MatthieuHernandez
Copy link

MatthieuHernandez commented Nov 13, 2020

Hello, I did that but I have a compilation error when I use 'make' command.

Makefile.config:844: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
  CC       util/env.o
Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
  CC       pmu-events/pmu-events.o
  CC       util/event.o
  CC       util/evlist.o
  CC       util/evsel.o
  CC       util/evsel_fprintf.o
  CC       util/find_bit.o
  CC       util/kallsyms.o
util/env.c: In function ‘perf_env__arch’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
util/env.c:166:17: note: declared here
  166 |  struct utsname uts;

How can I fix this error ? I'm using Ubuntu 18.04, did I need to switch on version 20.04 ? Maybe the problem come from my GCC version ?

@abel0b
Copy link
Author

abel0b commented Nov 14, 2020

Hello, I did that but I have a compilation error when I use 'make' command.

Makefile.config:844: No alternatives command found, you need to set JDIR= to point to the root of your Java directory
  CC       util/env.o
Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'
  CC       pmu-events/pmu-events.o
  CC       util/event.o
  CC       util/evlist.o
  CC       util/evsel.o
  CC       util/evsel_fprintf.o
  CC       util/find_bit.o
  CC       util/kallsyms.o
util/env.c: In function ‘perf_env__arch’:
cc1: error: function may return address of local variable [-Werror=return-local-addr]
util/env.c:166:17: note: declared here
  166 |  struct utsname uts;

How can I fix this error ? I'm using Ubuntu 18.04, did I need to switch on version 20.04 ? Maybe the problem come from my GCC version ?

I don't know. I used WSL2 with Ubuntu 20.04 which has gcc 9.3 and it worked. You could try with an other compiler.
As pointed by @StephanDollberg, note that most features of perf will not work because WSL doesnt support hardware counters.

@MatthieuHernandez
Copy link

I switched to Ubuntu 20.04 and it works perfectly, thanks. I think the problem came from my GCC version that I updated to version 10.

@danieldaeschle
Copy link

i get

make[1]: *** [Makefile.perf:206: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

@huangjj27
Copy link

i get

make[1]: *** [Makefile.perf:206: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

encountering the same error. it seems things had been changed

@micahsnyder
Copy link

I'm running into this error:

jvmti/jvmti_agent.c:48:21: error: static declaration of ‘gettid’ follows non-static declaration
   48 | static inline pid_t gettid(void)
      |                     ^~~~~~

A search online has me thinking that the perf build may be broken with newer glibc versions: https://lkml.org/lkml/2019/6/13/1409

However, I had luck compiling perf from the linux-msft-wsl-5.10.16.3 branch, which is newer than what's in master at present:

git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1 --branch linux-msft-wsl-5.10.16.3

@izlyforever
Copy link

Thanks, that help me a lot

@KarstenB
Copy link

KarstenB commented Nov 9, 2021

i get

make[1]: *** [Makefile.perf:206: sub-make] Error 2
make: *** [Makefile:70: all] Error 2

encountering the same error. it seems things had been changed

This is a crlf issue. It can be fixed by running dos2unix over all files, or setting git config --global core.autocrlf input before checkout.

@tbarbette
Copy link

tbarbette commented Nov 24, 2021

Thanks for the gist! To actually make sense of the perf record, and get the interactive menu, also install theses on top of flex and bison to let perf demangle binaries :
libdwarf-dev libelf-dev libnuma-dev libpython3-dev libunwind-dev libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev

@jayg-hive
Copy link

jayg-hive commented Jan 5, 2022

Just adding to this one. The source code to perf can also be downloaded from here. The instructions would change a bit:

  • Download the tar.gz file for the version you want. Here I picked 5.10.0, so the file is perf-5.10.0.tar.gz
  • Copy the tar file to your target destination (i.e., in ~)
  • Run tar -xvf perf-5.10.0.tar.gz
  • cd perf-5.10.0/tools/perf and run the rest of the instructions to build the binary.

@WalterWoshid
Copy link

@jayg-hive Thank you, this worked for me!

@MondayCha
Copy link

Thanks for the gist! To actually make sense of the perf record, and get the interactive menu, also install theses on top of flex and bison to let perf demangle binaries :谢谢你的要点!要真正理解 perf 记录,并获得交互式菜单,还要在 flex 和 bison 上安装这些文件,让 perf demangle 二进制文件: libdwarf-dev libelf-dev libnuma-dev libpython3-dev libunwind-dev libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev

Thanks, I am using ubuntu 22.04 on WSL 2 with kernel version v5.15.90.1, after installing the following packages, my perf works well:

# windows
wsl --update 
# wsl 2
sudo apt update
sudo apt install flex bison 
sudo apt install libdwarf-dev libelf-dev libnuma-dev libunwind-dev \
libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev \
systemtap-sdt-dev libssl-dev libperl-dev python-dev-is-python3 \
binutils-dev libiberty-dev libzstd-dev libcap-dev libbabeltrace-dev
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8 # parallel build
sudo cp perf /usr/local/bin

@MillionthOdin16
Copy link

Awesome! Worked great after running this ty :)

windows

wsl --update

wsl 2

sudo apt update
sudo apt install flex bison
sudo apt install libdwarf-dev libelf-dev libnuma-dev libunwind-dev
libnewt-dev libdwarf++0 libelf++0 libdw-dev libbfb0-dev
systemtap-sdt-dev libssl-dev libperl-dev python-dev-is-python3
binutils-dev libiberty-dev libzstd-dev libcap-dev libbabeltrace-dev
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8 # parallel build
sudo cp perf /usr/local/bin

@ProExpertProg
Copy link

After fixing CRLF, worked like a charm!

@LuisPeMoraRod
Copy link

Worked great on WSL2 -> Ubuntu 20.04
Thanks for the help

@ryanpeach
Copy link

ryanpeach commented Oct 7, 2023

Can anyone decifer this

  BUILD:   Doing 'make -j16' parallel build
Warning: Kernel ABI header at 'tools/include/uapi/linux/const.h' differs from latest version at 'include/uapi/linux/const.h'
diff -u tools/include/uapi/linux/const.h include/uapi/linux/const.h
Warning: Kernel ABI header at 'tools/include/uapi/linux/in.h' differs from latest version at 'include/uapi/linux/in.h'
diff -u tools/include/uapi/linux/in.h include/uapi/linux/in.h
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/disabled-features.h' differs from latest version at 'arch/x86/include/asm/disabled-features.h'
diff -u tools/arch/x86/include/asm/disabled-features.h arch/x86/include/asm/disabled-features.h
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/required-features.h' differs from latest version at 'arch/x86/include/asm/required-features.h'
diff -u tools/arch/x86/include/asm/required-features.h arch/x86/include/asm/required-features.h
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/cpufeatures.h' differs from latest version at 'arch/x86/include/asm/cpufeatures.h'
diff -u tools/arch/x86/include/asm/cpufeatures.h arch/x86/include/asm/cpufeatures.h
Warning: Kernel ABI header at 'tools/arch/x86/include/asm/msr-index.h' differs from latest version at 'arch/x86/include/asm/msr-index.h'
diff -u tools/arch/x86/include/asm/msr-index.h arch/x86/include/asm/msr-index.h
Warning: Kernel ABI header at 'tools/arch/arm64/include/uapi/asm/kvm.h' differs from latest version at 'arch/arm64/include/uapi/asm/kvm.h'
diff -u tools/arch/arm64/include/uapi/asm/kvm.h arch/arm64/include/uapi/asm/kvm.h
Makefile.config:1080: No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel
  GEN     python/perf.so
/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/perf/util/setup.py:31: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.core import setup, Extension
  CC      scripts/perl/Perf-Trace-Util/Context.o
  LD      trace/beauty/perf-in.o
trace/beauty/tracepoints/perf-in.o: file not recognized: file format not recognized
make[4]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:145: trace/beauty/perf-in.o] Error 1
make[3]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:139: trace/beauty] Error 2
make[3]: *** Waiting for unfinished jobs....
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:2999,
                 from Context.xs:8:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h: In function ‘Perl_is_utf8_valid_partial_char_flags’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/handy.h:125:23: error: cast from function call of type ‘STRLEN’ {aka ‘long unsigned int’} to non-matching type ‘_Bool’ [-Werror=bad-function-cast]
  125 | #define cBOOL(cbool) ((bool) (cbool))
      |                       ^
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h:2363:12: note: in expansion of macro ‘cBOOL’
 2363 |     return cBOOL(is_utf8_char_helper_(s0, e, flags));
      |            ^~~~~
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:7242,
                 from Context.xs:8:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h: In function ‘Perl_cop_file_avn’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h:3489:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
 3489 |     const char *file = CopFILE(cop);
      |     ^~~~~
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:7243,
                 from Context.xs:8:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/sv_inline.h: In function ‘Perl_newSV_type’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/sv_inline.h:376:5: error: enumeration value ‘SVt_LAST’ not handled in switch [-Werror=switch-enum]
  376 |     switch (type) {
      |     ^~~~~~
In file included from Context.xs:8:
Context.c: In function ‘XS_Perf__Trace__Context_common_pc’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/handy.h:125:23: error: cast from function call of type ‘long int’ to non-matching type ‘_Bool’ [-Werror=bad-function-cast]
  125 | #define cBOOL(cbool) ((bool) (cbool))
      |                       ^
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3867:62: note: in definition of macro ‘EXPECT’
 3867 | #  define EXPECT(expr,val)                  __builtin_expect(expr,val)
      |                                                              ^~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3887:52: note: in expansion of macro ‘cBOOL’
 3887 | #define LIKELY(cond)                        EXPECT(cBOOL(cond),TRUE)
      |                                                    ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:411:13: note: in expansion of macro ‘LIKELY’
  411 |         if (LIKELY(                                                     \
      |             ^~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:906:34: note: in expansion of macro ‘cBOOL’
  906 | #   define TAINT_get            (cBOOL(UNLIKELY(PL_tainted)))    /* Is something tainted? */
      |                                  ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:413:28: note: in expansion of macro ‘TAINT_get’
  413 |             & (do_taint ? !TAINT_get : 1)))                             \
      |                            ^~~~~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:476:38: note: in expansion of macro ‘TARGi’
  476 | #define PUSHi(i)        STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
      |                                      ^~~~~
Context.c:60:13: note: in expansion of macro ‘PUSHi’
Context.c: In function ‘XS_Perf__Trace__Context_common_flags’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/handy.h:125:23: error: cast from function call of type ‘long int’ to non-matching type ‘_Bool’ [-Werror=bad-function-cast]
  125 | #define cBOOL(cbool) ((bool) (cbool))
      |                       ^
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3867:62: note: in definition of macro ‘EXPECT’
 3867 | #  define EXPECT(expr,val)                  __builtin_expect(expr,val)
      |                                                              ^~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3887:52: note: in expansion of macro ‘cBOOL’
 3887 | #define LIKELY(cond)                        EXPECT(cBOOL(cond),TRUE)
      |                                                    ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:411:13: note: in expansion of macro ‘LIKELY’
  411 |         if (LIKELY(                                                     \
      |             ^~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:906:34: note: in expansion of macro ‘cBOOL’
  906 | #   define TAINT_get            (cBOOL(UNLIKELY(PL_tainted)))    /* Is something tainted? */
      |                                  ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:413:28: note: in expansion of macro ‘TAINT_get’
  413 |             & (do_taint ? !TAINT_get : 1)))                             \
      |                            ^~~~~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:476:38: note: in expansion of macro ‘TARGi’
  476 | #define PUSHi(i)        STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
      |                                      ^~~~~
Context.c:83:13: note: in expansion of macro ‘PUSHi’
Context.c: In function ‘XS_Perf__Trace__Context_common_lock_depth’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/handy.h:125:23: error: cast from function call of type ‘long int’ to non-matching type ‘_Bool’ [-Werror=bad-function-cast]
  125 | #define cBOOL(cbool) ((bool) (cbool))
      |                       ^
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3867:62: note: in definition of macro ‘EXPECT’
 3867 | #  define EXPECT(expr,val)                  __builtin_expect(expr,val)
      |                                                              ^~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:3887:52: note: in expansion of macro ‘cBOOL’
 3887 | #define LIKELY(cond)                        EXPECT(cBOOL(cond),TRUE)
      |                                                    ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:411:13: note: in expansion of macro ‘LIKELY’
  411 |         if (LIKELY(                                                     \
      |             ^~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:906:34: note: in expansion of macro ‘cBOOL’
  906 | #   define TAINT_get            (cBOOL(UNLIKELY(PL_tainted)))    /* Is something tainted? */
      |                                  ^~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:413:28: note: in expansion of macro ‘TAINT_get’
  413 |             & (do_taint ? !TAINT_get : 1)))                             \
      |                            ^~~~~~~~~
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/pp.h:476:38: note: in expansion of macro ‘TARGi’
  476 | #define PUSHi(i)        STMT_START { TARGi(i,1); PUSHs(TARG); } STMT_END
      |                                      ^~~~~
Context.c:106:13: note: in expansion of macro ‘PUSHi’
cc1: all warnings being treated as errors
make[5]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:97: scripts/perl/Perf-Trace-Util/Context.o] Error 1
make[4]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:139: perl/Perf-Trace-Util] Error 2
make[3]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:139: scripts] Error 2
  CC      util/scripting-engines/trace-event-perl.o
  CC      util/bpf-event.o
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:2999,
                 from util/scripting-engines/trace-event-perl.c:35:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h: In function ‘Perl_is_utf8_valid_partial_char_flags’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/handy.h:125:23: error: cast from function call of type ‘STRLEN’ {aka ‘long unsigned int’} to non-matching type ‘_Bool’ [-Werror=bad-function-cast]
  125 | #define cBOOL(cbool) ((bool) (cbool))
      |                       ^
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h:2363:12: note: in expansion of macro ‘cBOOL’
 2363 |     return cBOOL(is_utf8_char_helper_(s0, e, flags));
      |            ^~~~~
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:7242,
                 from util/scripting-engines/trace-event-perl.c:35:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h: In function ‘Perl_cop_file_avn’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/inline.h:3489:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
 3489 |     const char *file = CopFILE(cop);
      |     ^~~~~
In file included from /home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/perl.h:7243,
                 from util/scripting-engines/trace-event-perl.c:35:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/sv_inline.h: In function ‘Perl_newSV_type’:
/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.36/x86_64-linux-thread-multi/CORE/sv_inline.h:376:5: error: enumeration value ‘SVt_LAST’ not handled in switch [-Werror=switch-enum]
  376 |     switch (type) {
      |     ^~~~~~
cc1: all warnings being treated as errors
make[5]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:96: util/scripting-engines/trace-event-perl.o] Error 1
make[4]: *** [/mnt/c/Users/ryanp/Documents/Workspace/WSL2-Linux-Kernel/tools/build/Makefile.build:139: scripting-engines] Error 2
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [/mnt/c/Users/ryanp/Documents/Workspace/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

I followed @MondayCha 's instructions.
I think maybe I have another perf installed and don't know how to get rid of it.

openjdk-8-jdk is already the newest version (8u382-ga-1~22.04.1).

@ryanpeach
Copy link

Fixed by resetting my WSL back to base and using the latest. Idk what was up with it.

@patrick-nicodemus
Copy link

PSA, if you have installed a different version of gdb than the version that usually comes with your system installation, you may fail to build perf.
I am on Ubuntu 22.04 and tried to do this.
I had previously compiled from source and installed gdb 13.1 and perf failed to build with an obscure warning.
After downgrading gdb to 12.1, which is the same version which is available from the apt repository, perf built successfully.
In my case it was not as simple as doing 'sudo apt-get install gdb' as my installation of gdb from source had overwritten many files. I needed to download the source of gdb 12.1, build it, and install it, overwriting all the existing 13.1 files.

@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

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