lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 9bc1f54 3/4: Document two different 'perf' te


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9bc1f54 3/4: Document two different 'perf' techniques
Date: Thu, 10 Dec 2020 16:13:24 -0500 (EST)

branch: master
commit 9bc1f544a4a6c4d9f991d9138ec3260e9a8151ac
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Document two different 'perf' techniques
    
    Building from source with '-static' sounded like a good idea, but it
    didn't turn out as well as was hoped. Hard-linking a distribution's
    'perf' and all its dependencies is cumbersome, but works properly.
---
 gwc/perf_ln.sh     | 60 +++++++++++++++++++++++++++++++++++
 gwc/perf_static.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+)

diff --git a/gwc/perf_ln.sh b/gwc/perf_ln.sh
new file mode 100755
index 0000000..081c510
--- /dev/null
+++ b/gwc/perf_ln.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# Hard-link host's 'perf' and its dependencies for use in a chroot.
+
+# Copyright (C) 2020 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# https://savannah.nongnu.org/projects/lmi
+# email: <gchicares@sbcglobal.net>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# See
+#   https://lists.nongnu.org/archive/html/lmi/2020-10/msg00016.html
+# for an initial attempt that used 'cp' instead of 'ln' (and included
+# a good deal of relevant discussion), and
+#   https://lists.nongnu.org/archive/html/lmi/2020-10/msg00019.html
+# for an improvement using 'ln' instead of 'cp'.
+
+set -vx
+d=/srv/cache_for_lmi/perf_ln
+mkdir -p $d
+for z in \
+  /usr/bin/perf_4.19                                   \
+  /usr/lib/x86_64-linux-gnu/libopencsd_c_api.so.0      \
+  /usr/lib/x86_64-linux-gnu/libopencsd_c_api.so.0.10.1 \
+  /usr/lib/x86_64-linux-gnu/libopencsd.so.0            \
+  /usr/lib/x86_64-linux-gnu/libopencsd.so.0.10.1       \
+  /usr/lib/x86_64-linux-gnu/libperl.so.5.28            \
+  /usr/lib/x86_64-linux-gnu/libperl.so.5.28.1          \
+  /usr/lib/x86_64-linux-gnu/libpython3.7m.so.1.0       \
+  /usr/lib/x86_64-linux-gnu/libbabeltrace-ctf.so.1     \
+  /usr/lib/x86_64-linux-gnu/libbabeltrace-ctf.so.1.0.0 \
+  /usr/lib/x86_64-linux-gnu/libbabeltrace.so.1         \
+  /usr/lib/x86_64-linux-gnu/libbabeltrace.so.1.0.0     \
+  ;
+do ln $z $d/"$(basename "$z")"; done
+
+# later, in a chroot that mounts /srv/cache_for_lmi/
+# cd /opt/lmi/bin
+#   library path required for perf's and lmi's binaries
+# 
LD_LIBRARY_PATH=.:/opt/lmi/local/gcc_x86_64-pc-linux-gnu/lib/:/srv/cache_for_lmi/perf_ln
 /srv/cache_for_lmi/perf_ln/perf_4.19 record --call-graph lbr ./lmi_cli_shared 
--accept --data_path=/opt/lmi/data --selftest
+# Failed to open [ext4], continuing without symbols
+# Failed to open [fscrypto], continuing without symbols
+# Failed to open [kvm], continuing without symbols
+# Failed to read max cpus, using default of 4096
+# [ perf record: Captured and wrote 123.760 MB perf.data (358633 samples) ]
+#
+# LD_LIBRARY_PATH=.:/srv/cache_for_lmi/perf_ln 
/srv/cache_for_lmi/perf_ln/perf_4.19 report
diff --git a/gwc/perf_static.sh b/gwc/perf_static.sh
new file mode 100755
index 0000000..6f49d52
--- /dev/null
+++ b/gwc/perf_static.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+# Hard-link host's static-built 'perf' for use in a chroot.
+
+# Copyright (C) 2020 Gregory W. Chicares.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+# https://savannah.nongnu.org/projects/lmi
+# email: <gchicares@sbcglobal.net>
+# snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+# Instead of hard-linking 'perf' and all its dependencies, build it
+# statically as suggested here:
+#   https://lists.nongnu.org/archive/html/lmi/2020-10/msg00020.html
+# Unfortunately, while the resulting static 'perf' seems to work just
+# fine for 'perf record', for 'perf report' it doesn't decode symbols
+# or present the expected interactive interface--see example below.
+
+set -vx
+
+# apt-get install linux-source
+# pushd /usr/src
+#   redirect because output is about 64K lines
+#   in an interactive session, press <Tab> where indicated:
+# tar xvf /usr/src/linux-source-*<Tab> 2>&1 |less
+#   here, the tab completion is inlined:
+# tar xvf /usr/src/linux-source-4.19.tar.xz  2>&1 |less
+# pushd   /usr/src/linux-source-4.19/tools/perf
+#   this fails...
+# make clean; make EXTRA_LDFLAGS=-static 2>&1 |less
+#   ...so do this instead
+# make clean; make EXTRA_LDFLAGS=-static 
EXTRA_CFLAGS=-Wno-discarded-qualifiers 2>&1 |less
+#   still, it's not purely static:
+# ldd /usr/src/linux-source-4.19/tools/perf/perf
+#   linux-vdso.so.1 (0x00007ffff5d2c000)
+#   libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 
(0x00007fd5341b6000)
+#   librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd5341ac000)
+#   libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd534029000)
+#   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd534024000)
+#   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd533e63000)
+#   /lib64/ld-linux-x86-64.so.2 (0x00007fd534727000)
+# ...but perhaps that doesn't actually matter.
+
+# For this static build (cf. 'allow_perf.sh'):
+# chgrp perf_users /usr/src/linux-source-4.19/tools/perf/perf
+# chmod o-rwx /usr/src/linux-source-4.19/tools/perf/perf
+
+d=/srv/cache_for_lmi/perf_static
+mkdir -p $d
+ln /usr/src/linux-source-4.19/tools/perf/perf $d/perf
+
+# later, in a chroot that mounts /srv/cache_for_lmi/
+# cd /opt/lmi/bin
+#   library path required only for lmi's libraries, not perf's
+# LD_LIBRARY_PATH=.:/opt/lmi/local/gcc_x86_64-pc-linux-gnu/lib/ 
/srv/cache_for_lmi/perf_static/perf record --call-graph lbr ./lmi_cli_shared 
--accept --data_path=/opt/lmi/data --selftest
+# Failed to open [ext4], continuing without symbols
+# Failed to open [kvm], continuing without symbols
+# Failed to open [fscrypto], continuing without symbols
+# Failed to read max cpus, using default of 4096
+# [ perf record: Captured and wrote 126.807 MB perf.data (367155 samples) ]
+#
+# specifying $LD_LIBRARY_PATH here neither hurts nor helps:
+# LD_LIBRARY_PATH=.:/srv/cache_for_lmi/perf_static 
/srv/cache_for_lmi/perf_static/perf report
+#
+#    34.35%     0.00%  lmi_cli_shared  liblmi.so              [.] 
0x00007f58de18d8e9
+#            |
+#            ---0x7f58de18d8e9
+#               |
+#               |--28.65%--0x7f58de222bce
+#
+# No runtime error is reported, but the customary text-mode interface
+# is not offered. This static 'perf' generates a valid 'perf.data'
+# output file, which can be viewed with the 'perf_static.sh' variant
+# of perf in the chroot (which then does present the customary text-
+# mode interface and does decode symbols).
+#
+# The usual advice is to make sure the program being profiled was
+# built with debugging enabled and with '-fno-omit-frame-pointer', but
+# that doesn't help here: the program was built with those options,
+# and the 'perf_ln.sh' technique works but this 'perf_static.sh'
+# technique leads to the problems above.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]