Bug 204259 - can't compile trace-cmd-git on ArchLinux, unless a previous trace-cmd was already installed system-wide
Summary: can't compile trace-cmd-git on ArchLinux, unless a previous trace-cmd was alr...
Status: RESOLVED CODE_FIX
Alias: None
Product: Tools
Classification: Unclassified
Component: Trace-cmd/Kernelshark (show other bugs)
Hardware: x86-64 Linux
: P1 blocking
Assignee: Default virtual assignee for Trace-cmd and kernelshark
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-21 23:41 UTC by GYt2bW
Modified: 2019-07-24 12:07 UTC (History)
3 users (show)

See Also:
Kernel Version: 5.2.2-ge9b75c60f91a
Subsystem:
Regression: No
Bisected commit-id:


Attachments
CMakeOutput.log (61.71 KB, text/plain)
2019-07-21 23:41 UTC, GYt2bW
Details
CMakeError.log from a different compilation attempt(than the prev. CMakeOutput.log file) (6.71 KB, text/plain)
2019-07-21 23:48 UTC, GYt2bW
Details

Description GYt2bW 2019-07-21 23:41:50 UTC
Created attachment 283887 [details]
CMakeOutput.log

I've noticed something that slipped my test(s):
if trace-cmd-git isn't already installed on my system(ArchLinux), then compilation will fail:

```
...
-- Detecting CXX compile features - done

 project: Kernel Shark: (version: 0.9.8)

CMake Error at build/FindTraceCmd.cmake:58 (MESSAGE):
  

  Could not find trace-cmd!

Call Stack (most recent call first):
  CMakeLists.txt:16 (include)


-- Configuring incomplete, errors occurred!
See also "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/CMakeFiles/CMakeError.log".
make: *** [Makefile:259: /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/Makefile] Error 1
make: *** Waiting for unfinished jobs....
      ASCIIDOC            trace-cmd-start.1.xsl
```


1. first remove trace-cmd from system:
`$ sudo pacman -Rs trace-cmd-git`

2. try to compile it, using latest PKGBUILD https://aur.archlinux.org/cgit/aur.git/commit/?h=trace-cmd-git&id=d0913fea414ed795fdcc1c5c86a00fb030ec024d



full output:

```
/home/user/build/1packages/4used/trace-cmd 
$ ./0
[sudo] password for user: 
syncing btrfs for root fs /

real	0m0.057s
user	0m0.001s
sys	0m0.014s
!! /dev/sda normal sync

real	0m0.084s
user	0m0.000s
sys	0m0.023s
!! /dev/sda hardware sync (sdparm)
    /dev/sda: ATA       Samsung SSD 840   DB6Q
/usr/bin/makepkg --nobuild --syncdeps --
==> Making package: trace-cmd-git 2.7.r451.gf1ef911-1 (Mon 22 Jul 2019 01:33:54 AM CEST)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating trace-cmd git repo...
Fetching origin
glibc64:../sysdeps/posix/getaddrinfo.c:2201/getaddrinfo: git-remote-https[13544](full:'/usr/lib/git-core/git-remote-https') for user user(1000(eff:user(1000))) 1of2 attempting to resolve (requested)hostname:
git.kernel.org
glibc64:../sysdeps/posix/getaddrinfo.c:2201/getaddrinfo: !! REENTRANT_NAME == 'gethostbyname2_r' hostname='git.kernel.org'
git-remote-https: git-remote-https[13544](full:'/usr/lib/git-core/git-remote-https') for user user(1000(eff:user(1000))) 2of2 successfully resolved requested hostname('git.kernel.org') which was not transformed('git.kernel.org') as follows:
136.144.49.103 git.kernel.org
  -> Found typo.patch
==> Validating source files with sha256sums...
    trace-cmd ... Skipped
    typo.patch ... Passed
==> Extracting sources...
  -> Creating working copy of trace-cmd git repo...
Cloning into 'trace-cmd'...
done.
==> Starting prepare()...
  -> [1/1] Applying patch 'typo.patch'
patching file lib/trace-cmd/trace-util.c
==> Starting pkgver()...
==> Updated version: trace-cmd-git 2.7.r453.g11d683a-1
==> Sources are ready.

real	0m2.176s
user	0m1.450s
sys	0m0.756s
/usr/bin/makepkg -s --noprepare --force --noextract --
==> Making package: trace-cmd-git 2.7.r453.g11d683a-1 (Mon 22 Jul 2019 01:33:55 AM CEST)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> WARNING: Using existing $srcdir/ tree
==> Starting pkgver()...
==> Removing existing $pkgdir/ directory...
==> Starting build()...
  COMPILE FPIC           tep_strerror.o
  COMPILE FPIC           kbuffer-parse.o
  COMPILE FPIC           trace-seq.o
  COMPILE FPIC           parse-filter.o
parse-filter.c: In function ‘arg_to_str’:
parse-filter.c:2161:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 2161 |   asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE");
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c: In function ‘op_to_str’:
parse-filter.c:1954:5: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 1954 |     asprintf(&str, val ? "TRUE" : "FALSE");
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c:1972:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 1972 |   asprintf(&str, "(%s) %s (%s)", left, op, right);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c:1988:4: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 1988 |    asprintf(&str, right_val ? "FALSE" : "TRUE");
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c:1991:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 1991 |   asprintf(&str, "%s(%s)", op, right);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c: In function ‘num_to_str’:
parse-filter.c:2109:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 2109 |   asprintf(&str, "%s %s %s", lstr, op, rstr);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c: In function ‘str_to_str’:
parse-filter.c:2144:3: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 2144 |   asprintf(&str, "%s %s \"%s\"",
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2145 |     arg->str.field->name, op, arg->str.val);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c: In function ‘val_to_str’:
parse-filter.c:2007:2: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 2007 |  asprintf(&str, "%lld", arg->value.val);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse-filter.c: In function ‘exp_to_str’:
parse-filter.c:2065:2: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
 2065 |  asprintf(&str, "%s %s %s", lstr, op, rstr);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  COMPILE FPIC           parse-utils.o
  COMPILE FPIC           event-plugin.o
  COMPILE FPIC           event-parse-api.o
  COMPILE FPIC           event-parse.o
  BUILD STATIC LIB       libtraceevent.a
  UPDATE                 trace_plugin_dir
  UPDATE                 trace_python_dir
make -C /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation all
Note: to build the gui, type "make gui"
      to build man pages, type "make doc"
Re-run cmake no build system arguments
-- The C compiler identification is GNU 9.1.0
-- The CXX compiler identification is GNU 9.1.0
-- Check for working C compiler: /usr/lib/ccache/bin/cc
      ASCIIDOC            trace-cmd-hist.1.xsl
      ASCIIDOC            trace-cmd-stream.1.xsl
      ASCIIDOC            trace-cmd-split.1.xsl
      ASCIIDOC            trace-cmd-show.1.xsl
      ASCIIDOC            trace-cmd-list.1.xsl
      ASCIIDOC            trace-cmd-options.1.xsl
      ASCIIDOC            trace-cmd-reset.1.xsl
      ASCIIDOC            trace-cmd-report.1.xsl
      ASCIIDOC            trace-cmd-check-events.1.xsl
      ASCIIDOC            trace-cmd-profile.1.xsl
      ASCIIDOC            trace-cmd-record.1.xsl
-- Check for working C compiler: /usr/lib/ccache/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/lib/ccache/bin/c++
-- Check for working CXX compiler: /usr/lib/ccache/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done

 project: Kernel Shark: (version: 0.9.8)

CMake Error at build/FindTraceCmd.cmake:58 (MESSAGE):
  

  Could not find trace-cmd!

Call Stack (most recent call first):
  CMakeLists.txt:16 (include)


-- Configuring incomplete, errors occurred!
See also "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/CMakeFiles/CMakeOutput.log".
See also "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/CMakeFiles/CMakeError.log".
make: *** [Makefile:259: /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/Makefile] Error 1
make: *** Waiting for unfinished jobs....
      ASCIIDOC            trace-cmd-start.1.xsl
      ASCIIDOC            trace-cmd-stat.1.xsl
      ASCIIDOC            trace-cmd-mem.1.xsl
      ASCIIDOC            trace-cmd-snapshot.1.xsl
      ASCIIDOC            kernelshark.1.xsl
      ASCIIDOC            trace-cmd-listen.1.xsl
      ASCIIDOC            trace-cmd-extract.1.xsl
      ASCIIDOC            trace-cmd-restore.1.xsl
      ASCIIDOC            trace-cmd-stack.1.xsl
      ASCIIDOC            trace-cmd-stop.1.xsl
      ASCIIDOC            trace-cmd.1.xsl
      ASCIIDOC            trace-cmd.dat.5.xsl
      XSLTPROC            trace-cmd-hist.1
      XSLTPROC            trace-cmd-stream.1
      XSLTPROC            trace-cmd-split.1
      XSLTPROC            trace-cmd-options.1
      XSLTPROC            trace-cmd-show.1
      XSLTPROC            trace-cmd-list.1
      XSLTPROC            trace-cmd-reset.1
      XSLTPROC            trace-cmd-check-events.1
      XSLTPROC            trace-cmd-report.1
      XSLTPROC            trace-cmd-profile.1
      XSLTPROC            trace-cmd-record.1
      XSLTPROC            trace-cmd-start.1
      XSLTPROC            trace-cmd-stat.1
      XSLTPROC            trace-cmd-mem.1
      XSLTPROC            trace-cmd-snapshot.1
      XSLTPROC            kernelshark.1
      XSLTPROC            trace-cmd-listen.1
      XSLTPROC            trace-cmd-extract.1
      XSLTPROC            trace-cmd-restore.1
      XSLTPROC            trace-cmd-stack.1
      XSLTPROC            trace-cmd-stop.1
      XSLTPROC            trace-cmd.1
      XSLTPROC            trace-cmd.dat.5
rm /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-stat.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-show.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-snapshot.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/kernelshark.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-report.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-mem.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-split.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-stack.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-check-events.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-listen.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-stop.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-list.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-restore.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-stream.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-extract.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-start.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-reset.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-options.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-record.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd.dat.5.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-profile.1.xsl /home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/Documentation/trace-cmd-hist.1.xsl
==> ERROR: A failure occurred in build().
    Aborting...

real	0m3.404s
user	0m18.545s
sys	0m1.661s

real	0m3.543s
user	0m18.548s
sys	0m1.672s

Compilation(failed) took 4 secs aka 4 seconds. date='Mon 22 Jul 2019 01:33:58 AM CEST'
Cleaning up

cache hit (direct)       	 470995 -  471007 =      12	 3.0000/sec
unsupported compiler option	   1097 -    1105 =       8	 2.0000/sec
no input file            	  77186 -   77190 =       4	 1.0000/sec
called for link          	 101237 -  101247 =      10	 2.5000/sec
preprocessor error       	   7756 -    7757 =       1	 0.2500/sec
^ nproc='12'
/proc/loadavg='1.30 0.80 0.50 1/590 15135'
/proc/cmdline='BOOT_IMAGE=/boot/vmlinuz-linux-stable root=UUID=2b8b9ab8-7ac5-4586-aa42-d7ffb12de92a rw root_trim=yes rd.luks.allow-discards rd.luks.options=discard ipv6.disable=1 ipv6.disable_ipv6=1 ipv6.autoconf=0 loglevel=15 log_buf_len=16M ignore_loglevel printk.always_kmsg_dump=y printk.time=y printk.devkmsg=on mminit_loglevel=4 memory_corruption_check=1 fbcon=scrollback:4096k fbcon=font:ProFont6x11 net.ifnames=0 nolvm dobtrfs console=tty1 earlyprintk=vga audit=0 systemd.log_target=kmsg systemd.journald.forward_to_console=1 enforcing=0 udev.children-max=1256 rd.udev.children-max=1256 nohz=on oops=panic crashkernel=256M panic=0 page_poison=1 psi=1 sysrq_always_enabled random.trust_cpu=off logo.nologo lpj=0 mce=bootlog reboot=force,cold noexec=on nohibernate scsi_mod.use_blk_mq=1 consoleblank=120 mitigations=off nospectre_v1 nospectre_v2 spectre_v2=off nospec_store_bypass_disable kvm-intel.vmentry_l1d_flush=never l1tf=off nopti pti=off no_stf_barrier noibrs noibpb ssbd=force-off spectre_v2_user=off noretpoline mds=off rd.log=all noefi cpuidle.governor=menu zram.num_devices=3 zswap.enabled=0 zswap.same_filled_pages_enabled=1 zswap.compressor=zstd zswap.max_pool_percent=40 zswap.zpool=z3fold i915.enable_fbc=1 i915.verbose_state_checks=1 i915.enable_hangcheck=1 i915.error_capture=1'
Linux i87k 5.2.2-ge9b75c60f91a #79 SMP Sun Jul 21 23:14:47 CEST 2019 x86_64 GNU/Linux
[sudo] password for user: 
BIOS Information
	Vendor: American Megatrends Inc.
	Version: 2201
	Release Date: 05/27/2019
analyzing CPU 0:
  current CPU frequency: 902205 (asserted by call to kernel)
analyzing CPU 1:
  current CPU frequency: 1168585 (asserted by call to kernel)
analyzing CPU 2:
  current CPU frequency: 929745 (asserted by call to kernel)
analyzing CPU 3:
  current CPU frequency: 1079013 (asserted by call to kernel)
analyzing CPU 4:
  current CPU frequency: 816223 (asserted by call to kernel)
analyzing CPU 5:
  current CPU frequency: 810416 (asserted by call to kernel)
analyzing CPU 6:
  current CPU frequency: 988761 (asserted by call to kernel)
analyzing CPU 7:
  current CPU frequency: 1104707 (asserted by call to kernel)
analyzing CPU 8:
  current CPU frequency: 872605 (asserted by call to kernel)
analyzing CPU 9:
  current CPU frequency: 835915 (asserted by call to kernel)
analyzing CPU 10:
  current CPU frequency: 842677 (asserted by call to kernel)
analyzing CPU 11:
  current CPU frequency: 871916 (asserted by call to kernel)
analyzing CPU 0:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 1:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 2:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 3:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 4:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 5:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 6:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 7:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 8:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 9:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 10:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
analyzing CPU 11:
  current policy: frequency should be within 800 MHz and 4.70 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
-----

real	0m36.597s
user	0m20.073s
sys	0m2.466s
```

I'm attaching the referenced `/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/kernel-shark/build/CMakeFiles/CMakeOutput.log` file.

My current workaround is to avoid kernelshark build by not using `gui` and `install_gui` in the `make` commands invocations:
```diff
$ colordiff -up /tmp/PKGBUILD PKGBUILD
--- /tmp/PKGBUILD	2019-07-22 01:33:54.572995078 +0200
+++ PKGBUILD	2019-07-22 01:38:39.253992363 +0200
@@ -60,7 +60,7 @@ build() {
   # pkg-config --cflags --libs $PYTHON_VERS
   #make PYTHON_VERS=python3 prefix="/usr" DESTDIR="$pkgdir" TRACE_CMD="$srcdir/trace-cmd" all doc #gui
   make BUILD_TYPE=Release PYTHON_VERS=python2 \
-    prefix="/usr" DESTDIR="$pkgdir" all doc gui
+    prefix="/usr" DESTDIR="$pkgdir" all doc
 }
 
 package() {
@@ -72,5 +72,5 @@ package() {
   #make PYTHON_VERS=python3 prefix="/usr" DESTDIR="$pkgdir" \
   #  install install_doc #install_gui
   make BUILD_TYPE=Release PYTHON_VERS=python2 \
-    prefix="/usr" DESTDIR="$pkgdir" install install_doc install_gui
+    prefix="/usr" DESTDIR="$pkgdir" install install_doc
 }
```

It appears as if the making of `gui`(aka kernelshark?) is attempted well before trace-cmd finished compiling? I'm not sure.
But as soon as I install trace-cmd(using above workaround) system-wide using pacman, once, subsequent compilations of trace-cmd-git with `gui` will succeed - I'm guessing because it can find the system-wide trace-cmd installation.
Comment 1 GYt2bW 2019-07-21 23:48:50 UTC
Created attachment 283889 [details]
CMakeError.log from a different compilation attempt(than the prev. CMakeOutput.log file)

I forgot to also attach `CMakeError.log` (didn't notice it was a different filename!)

So here's another (new)run, to generate `CMakeError.log`
Comment 2 GYt2bW 2019-07-22 00:01:22 UTC
> It appears as if the making of gui(aka kernelshark?) is attempted well before trace-cmd finished compiling? I'm not sure.

that guess is incorrect, because if it were true, then running these two commands would work:

1. make BUILD_TYPE=Release PYTHON_VERS=python2 prefix=/usr DESTDIR=/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/pkg/trace-cmd-git all doc

2. make BUILD_TYPE=Release PYTHON_VERS=python2 prefix=/usr DESTDIR=/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/pkg/trace-cmd-git gui

but I get the same error for the second one.

Then there must be some issue in `build/FindTraceCmd.cmake` that can be improved to fix this, maybe. I'll try to look into it, noting that I've basically no idea how these cmake/make stuff works.
Comment 3 GYt2bW 2019-07-22 00:22:46 UTC
Ok, two things are causing this:

1. `kernel-shark/build/FindTraceCmd.cmake` has code that says find `TRACECMD_EXECUTABLE` only if `CMAKE_BUILD_TYPE MATCHES Debug`, so this issue will always happen if trace-cmd isn't already installed system-wide AND you're trying to compile a non-debug trace-cmd (ie. `make BUILD_TYPE=Release` I guess).

2. you cannot run `make all doc gui` in one command (you have to run `make all doc` then `make gui`) or else, `kernel-shark`(aka gui) build is attempted before trace-cmd is finished, and thus the code in `kernel-shark/build/FindTraceCmd.cmake` will fail to find both `TRACECMD_EXECUTABLE` and `TRACECMD_LIBRARY` but it will find `TRACECMD_INCLUDE_DIR` (didn't check `TRACEEVENT_LIBRARY`)

(so correction: Comment 2 is true(aka guess being incorrect) only because 1.(above) is also happening, otherwise, that was a good guess: that `gui` build was being attempted before the `trace-cmd`(cli?) was compiled)


This 2.(above) might happen because `MAKEFLAGS="-j12"`, checking... yup, that is correct: if `MAKEFLAGS="-j1"` then step 2.(above) will not be hit.
ie. in ArchLinux:
`MAKEFLAGS='-j1'` in `/etc/makepkg.conf`
Comment 4 GYt2bW 2019-07-22 00:38:53 UTC
ok, there might be a problem with step 1. in Comment 3, such that, if `TRACECMD_EXECUTABLE` is allowed to be set there, then `kernelshark` executable that's eventually installed in the system (via `pacman`, on ArchLinux) will apparently link to the absolute path of that `trace-cmd` executable from the built dir, and thus will fail to run it if that build dir is later removed, instead of using the `trace-cmd` that is now available in PATH for example.

How I tested this?

By commenting out the code:
#if (CMAKE_BUILD_TYPE MATCHES Debug)
#endif (CMAKE_BUILD_TYPE MATCHES Debug)
and thus allowing it to work for `Release` too, ie. this remained:
```
#if (CMAKE_BUILD_TYPE MATCHES Debug)
   find_program(TRACECMD_EXECUTABLE   NAMES  trace-cmd
                                      PATHS  $ENV{TRACE_CMD}/tracecmd/
                                             ${CMAKE_SOURCE_DIR}/../tracecmd/
                                      NO_DEFAULT_PATH)
#endif (CMAKE_BUILD_TYPE MATCHES Debug)
```
(clearly this cannot possibly be the fix)

and after install, ran `kernelshark`, pressed ctrl+r to record, the pressed Capture button three times which showed, when the build dir was removed, this:
```

trace-cmd record -e all -o /home/user/trace.dat sleep 0.1



trace-cmd record -e all -o /home/user/trace.dat sleep 0.1



trace-cmd record -e all -o /home/user/trace.dat sleep 0.1

```
no errors, just that.

But when the build dir was restored (ie. `trace-cmd` executable from build dir was made available again), then pressing Capture once yielded:
```

trace-cmd record -e all -o /home/user/trace.dat sleep 0.1
trace-cmd: No such file or directory
  opening '/sys/kernel/debug/tracing/tracing_on'

Capture process failed: Unknown error
```
In other words, there was a `trace-cmd` that was executed this time.
The other errors are to be expected because I completely disabled some required tracing CONFIG_* from my kernel. To be more precise I've disabled exactly these CONFIG_* ones, seen here: https://bugzilla.kernel.org/show_bug.cgi?id=204231#c3


Note that `/usr/bin/trace-cmd` was available this whole time that `kernelshark` was, which tells me it tried to use absolute path of `trace-cmd` from the build dir instead! 
To double-check:
```$ grep -Fl '/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/tracecmd/trace-cmd' -- `pacman -Qlq trace-cmd`
/usr/lib/kernelshark/libkshark-gui.so.0.9.8
```
Comment 5 GYt2bW 2019-07-22 01:34:23 UTC
To add to Comment 4, to help find the exe hardcoding:
```
trace-cmd $ grep -nrIFw TRACECMD_EXECUTABLE
kernel-shark/src/KsCaptureDialog.cpp:490:		captureExe = TRACECMD_EXECUTABLE;
kernel-shark/src/KsCmakeDef.hpp:21:#define TRACECMD_EXECUTABLE "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/tracecmd/trace-cmd"
kernel-shark/build/deff.h.cmake:21:#cmakedefine TRACECMD_EXECUTABLE "@TRACECMD_EXECUTABLE@"
kernel-shark/build/CMakeCache.txt:273:TRACECMD_EXECUTABLE:FILEPATH=/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/tracecmd/trace-cmd
```

or with some context:
```
trace-cmd $ grep -nrIFw -C4  TRACECMD_EXECUTABLE
kernel-shark/src/KsCaptureDialog.cpp-486-
kernel-shark/src/KsCaptureDialog.cpp-487-	if (!KsUtils::isInstalled())
kernel-shark/src/KsCaptureDialog.cpp-488-		captureExe = QString(_INSTALL_PREFIX) + QString("/bin/trace-cmd");
kernel-shark/src/KsCaptureDialog.cpp-489-	else
kernel-shark/src/KsCaptureDialog.cpp:490:		captureExe = TRACECMD_EXECUTABLE;
kernel-shark/src/KsCaptureDialog.cpp-491-
kernel-shark/src/KsCaptureDialog.cpp-492-	_captureProc.setProgram(captureExe);
kernel-shark/src/KsCaptureDialog.cpp-493-
kernel-shark/src/KsCaptureDialog.cpp-494-	_captureMon.connectMe(&_captureProc, &_captureCtrl);
--
kernel-shark/src/KsCmakeDef.hpp-17-/** KernelShark plugins installation prefix path. */
kernel-shark/src/KsCmakeDef.hpp-18-#define KS_PLUGIN_INSTALL_PREFIX "/usr/lib/kernelshark/plugins/"
kernel-shark/src/KsCmakeDef.hpp-19-
kernel-shark/src/KsCmakeDef.hpp-20-/** Location of the trace-cmd executable. */
kernel-shark/src/KsCmakeDef.hpp:21:#define TRACECMD_EXECUTABLE "/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/tracecmd/trace-cmd"
kernel-shark/src/KsCmakeDef.hpp-22-
kernel-shark/src/KsCmakeDef.hpp-23-/** "pkexec" executable. */
kernel-shark/src/KsCmakeDef.hpp-24-#define DO_AS_ROOT "/usr/bin/pkexec"
kernel-shark/src/KsCmakeDef.hpp-25-
--
kernel-shark/build/deff.h.cmake-17-/** KernelShark plugins installation prefix path. */
kernel-shark/build/deff.h.cmake-18-#cmakedefine KS_PLUGIN_INSTALL_PREFIX "@KS_PLUGIN_INSTALL_PREFIX@"
kernel-shark/build/deff.h.cmake-19-
kernel-shark/build/deff.h.cmake-20-/** Location of the trace-cmd executable. */
kernel-shark/build/deff.h.cmake:21:#cmakedefine TRACECMD_EXECUTABLE "@TRACECMD_EXECUTABLE@"
kernel-shark/build/deff.h.cmake-22-
kernel-shark/build/deff.h.cmake-23-/** "pkexec" executable. */
kernel-shark/build/deff.h.cmake-24-#cmakedefine DO_AS_ROOT "@DO_AS_ROOT@"
kernel-shark/build/deff.h.cmake-25-
--
kernel-shark/build/CMakeCache.txt-269-//The directory containing a CMake configuration file for Qt5Widgets.
kernel-shark/build/CMakeCache.txt-270-Qt5Widgets_DIR:PATH=/usr/lib64/cmake/Qt5Widgets
kernel-shark/build/CMakeCache.txt-271-
kernel-shark/build/CMakeCache.txt-272-//Path to a program.
kernel-shark/build/CMakeCache.txt:273:TRACECMD_EXECUTABLE:FILEPATH=/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/tracecmd/trace-cmd
kernel-shark/build/CMakeCache.txt-274-
kernel-shark/build/CMakeCache.txt-275-//Path to a file.
kernel-shark/build/CMakeCache.txt-276-TRACECMD_INCLUDE_DIR:PATH=/home/user/build/1packages/4used/trace-cmd/makepkg_pacman/trace-cmd-git/src/trace-cmd/include
kernel-shark/build/CMakeCache.txt-277-
--
```
Comment 6 Yordan Karadzhov 2019-07-22 11:16:13 UTC
Hi howaboutsynergy,

Thanks for the detailed report!

The problem here is the following. In order to record trace data the "Record" dialog actually starts trace-cmd as a child process. However, there is a list very good arguments why unconsciously starting as root an executable from your $HOME folder is a very bad idea. This is the reason why by default CMake searches for the trace-cmd executable only in the default system paths.

On the other hand, when we develop new features, we often make changes in both KernelShark and trace-cmd. In such a case it makes sense to configure KernelShark to use the modified version of trace-cmd from the build location because this way you do not have to type "sudo make install" every time when you want to test your new code. Another advantage is that this way all your modifications are kept in the build location and the already installed libraries/executable are untouched.

This is why if your build type is "Debug" CMake will first search for trace-cmd from your build dir.

cheers,
Yordan
Comment 7 Steven Rostedt 2019-07-22 19:10:07 UTC
Hi Yordan,

We need to come up with a different solution to this. KernelShark must be able to be built when trace-cmd is not installed on the system. We can not expect that the code is built for where it is going to run.

-- Steve
Comment 8 Steven Rostedt 2019-07-22 19:14:15 UTC
Perhaps we should show the full path of the trace-cmd that is being executed by kshark-record, and not default to relative paths.
Comment 9 Steven Rostedt 2019-07-22 19:29:17 UTC
Another solution is to hardcode it to whatever "prefix" is defined to, and assume that kernelshark will be installed in the same location as trace-cmd.
Comment 10 Steven Rostedt 2019-07-23 18:47:50 UTC
Yordan created this patch:

  https://patchwork.kernel.org/patch/11055097/

I applied it and tested it this way:

On my build system, I removed all trace-cmd and kernelshark code, and
did this:

 $ mkdir /tmp/packages
 $ make clean
 $ make DESTDIR=/tmp/packages prefix=/usr install_gui
 $ cd /tmp/packages
 $ tar -cvjf /tmp/ks-package.tar.bz2 .
 $ scp /tmp/ks-package.tar.bz2 test-machine:/tmp

on test-machine:

 $ su -
 # cd /
 # tar xvf /tmp/ks-package.tar.bz2
 # cd ~
 # which kernelshark
/usr/bin/kernelshark
 # kernelshark

And tried a Tools->Record, and all seems to be working!
Comment 11 GYt2bW 2019-07-24 00:06:23 UTC
The patch works for me also(on ArchLinux), thanks Yordan and Steven.
Comment 12 Steven Rostedt 2019-07-24 12:07:24 UTC
Fixed by commit 80940d027767d ("kernel-shark: Get the path to trace-cmd executable from _INSTALL_PREFIX")

Note You need to log in before you can comment on or make changes to this bug.