mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-12-23 10:58:23 +01:00
perf archive: Add new option '--unpack' to expand tarballs
Archives generated by the command 'perf archive' have to be unpacked manually. Following the addition of option '--all' now there also exist a nested structure of tars, and after further discussion with Red Hat Global Support Services, they found a feature correctly unpacking archives of 'perf archive' convenient. Option '--unpack' of 'perf archive' unpacks archives generated by the command 'perf archive' as well as archives generated when used with option '--all'. The 'perf.data' file is placed in the current directory, while debug symbols are unpacked in '~/.debug' directory. A tar filename can be passed as an argument, and if not provided the command tries to find a viable perf.tar file for unpacking. Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Michael Petlan <mpetlan@redhat.com> Link: https://lore.kernel.org/r/20231212165909.14459-2-vmolnaro@redhat.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
624dda101e
commit
e43c64c971
|
|
@ -7,17 +7,72 @@ PERF_DATA=perf.data
|
||||||
PERF_SYMBOLS=perf.symbols
|
PERF_SYMBOLS=perf.symbols
|
||||||
PERF_ALL=perf.all
|
PERF_ALL=perf.all
|
||||||
ALL=0
|
ALL=0
|
||||||
|
UNPACK=0
|
||||||
|
|
||||||
while [ $# -gt 0 ] ; do
|
while [ $# -gt 0 ] ; do
|
||||||
if [ $1 == "--all" ]; then
|
if [ $1 == "--all" ]; then
|
||||||
ALL=1
|
ALL=1
|
||||||
shift
|
shift
|
||||||
|
elif [ $1 == "--unpack" ]; then
|
||||||
|
UNPACK=1
|
||||||
|
shift
|
||||||
else
|
else
|
||||||
PERF_DATA=$1
|
PERF_DATA=$1
|
||||||
|
UNPACK_TAR=$1
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ $UNPACK -eq 1 ]; then
|
||||||
|
if [ ! -z "$UNPACK_TAR" ]; then # tar given as an argument
|
||||||
|
if [ ! -e "$UNPACK_TAR" ]; then
|
||||||
|
echo "Provided file $UNPACK_TAR does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
TARGET="$UNPACK_TAR"
|
||||||
|
else # search for perf tar in the current directory
|
||||||
|
TARGET=`find . -regex "\./perf.*\.tar\.bz2"`
|
||||||
|
TARGET_NUM=`echo -n "$TARGET" | grep -c '^'`
|
||||||
|
|
||||||
|
if [ -z "$TARGET" -o $TARGET_NUM -gt 1 ]; then
|
||||||
|
echo -e "Error: $TARGET_NUM files found for unpacking:\n$TARGET"
|
||||||
|
echo "Provide the requested file as an argument"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Found target file for unpacking: $TARGET"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$TARGET" =~ (\./)?$PERF_ALL.*.tar.bz2 ]]; then # perf tar generated by --all option
|
||||||
|
TAR_CONTENTS=`tar tvf "$TARGET" | tr -s " " | cut -d " " -f 6`
|
||||||
|
VALID_TAR=`echo "$TAR_CONTENTS" | grep "$PERF_SYMBOLS.tar.bz2" | wc -l` # check if it contains a sub-tar perf.symbols
|
||||||
|
if [ $VALID_TAR -ne 1 ]; then
|
||||||
|
echo "Error: $TARGET file is not valid (contains zero or multiple sub-tar files with debug symbols)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
INTERSECT=`comm -12 <(ls) <(echo "$TAR_CONTENTS") | tr "\n" " "` # check for overwriting
|
||||||
|
if [ ! -z "$INTERSECT" ]; then # prompt if file(s) already exist in the current directory
|
||||||
|
echo "File(s) ${INTERSECT::-1} already exist in the current directory."
|
||||||
|
while true; do
|
||||||
|
read -p 'Do you wish to overwrite them? ' yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) break;;
|
||||||
|
[Nn]* ) exit 1;;
|
||||||
|
* ) echo "Please answer yes or no.";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# unzip the perf.data file in the current working directory and debug symbols in ~/.debug directory
|
||||||
|
tar xvf $TARGET && tar xvf $PERF_SYMBOLS.tar.bz2 -C ~/.debug
|
||||||
|
|
||||||
|
else # perf tar generated by perf archive (contains only debug symbols)
|
||||||
|
tar xvf $TARGET -C ~/.debug
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# PERF_BUILDID_DIR environment variable set by perf
|
# PERF_BUILDID_DIR environment variable set by perf
|
||||||
# path to buildid directory, default to $HOME/.debug
|
# path to buildid directory, default to $HOME/.debug
|
||||||
|
|
@ -55,17 +110,12 @@ if [ $ALL -eq 1 ]; then # pack perf.data file together with tar containing
|
||||||
tar cjf $PERF_SYMBOLS.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
|
tar cjf $PERF_SYMBOLS.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
|
||||||
tar cjf $PERF_ALL-$HOSTNAME-$DATE.tar.bz2 $PERF_DATA $PERF_SYMBOLS.tar.bz2
|
tar cjf $PERF_ALL-$HOSTNAME-$DATE.tar.bz2 $PERF_DATA $PERF_SYMBOLS.tar.bz2
|
||||||
rm $PERF_SYMBOLS.tar.bz2 $MANIFEST $BUILDIDS || true
|
rm $PERF_SYMBOLS.tar.bz2 $MANIFEST $BUILDIDS || true
|
||||||
|
|
||||||
echo -e "Now please run:\n"
|
|
||||||
echo -e "$ tar xvf $PERF_ALL-$HOSTNAME-$DATE.tar.bz2 && tar xvf $PERF_SYMBOLS.tar.bz2 -C ~/.debug\n"
|
|
||||||
echo "wherever you need to run 'perf report' on."
|
|
||||||
else # pack only the debug symbols
|
else # pack only the debug symbols
|
||||||
tar cjf $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
|
tar cjf $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST
|
||||||
rm $MANIFEST $BUILDIDS || true
|
rm $MANIFEST $BUILDIDS || true
|
||||||
|
|
||||||
echo -e "Now please run:\n"
|
|
||||||
echo -e "$ tar xvf $PERF_DATA.tar.bz2 -C ~/.debug\n"
|
|
||||||
echo "wherever you need to run 'perf report' on."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -e "Now please run:\n"
|
||||||
|
echo -e "$ perf archive --unpack\n"
|
||||||
|
echo "or unpack the tar manually wherever you need to run 'perf report' on."
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user