1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # perf archive 3 # perf archive 4 # Arnaldo Carvalho de Melo <acme@redhat.com> 4 # Arnaldo Carvalho de Melo <acme@redhat.com> 5 5 6 PERF_DATA=perf.data 6 PERF_DATA=perf.data 7 PERF_SYMBOLS=perf.symbols 7 PERF_SYMBOLS=perf.symbols 8 PERF_ALL=perf.all 8 PERF_ALL=perf.all 9 ALL=0 9 ALL=0 10 UNPACK=0 10 UNPACK=0 11 11 12 while [ $# -gt 0 ] ; do 12 while [ $# -gt 0 ] ; do 13 if [ $1 == "--all" ]; then 13 if [ $1 == "--all" ]; then 14 ALL=1 14 ALL=1 15 shift 15 shift 16 elif [ $1 == "--unpack" ]; then 16 elif [ $1 == "--unpack" ]; then 17 UNPACK=1 17 UNPACK=1 18 shift 18 shift 19 else 19 else 20 PERF_DATA=$1 20 PERF_DATA=$1 21 UNPACK_TAR=$1 21 UNPACK_TAR=$1 22 shift 22 shift 23 fi 23 fi 24 done 24 done 25 25 26 if [ $UNPACK -eq 1 ]; then 26 if [ $UNPACK -eq 1 ]; then 27 if [ ! -z "$UNPACK_TAR" ]; then 27 if [ ! -z "$UNPACK_TAR" ]; then # tar given as an argument 28 if [ ! -e "$UNPACK_TAR" ]; the 28 if [ ! -e "$UNPACK_TAR" ]; then 29 echo "Provided file $U 29 echo "Provided file $UNPACK_TAR does not exist" 30 exit 1 30 exit 1 31 fi 31 fi 32 TARGET="$UNPACK_TAR" 32 TARGET="$UNPACK_TAR" 33 else 33 else # search for perf tar in the current directory 34 TARGET=`find . -regex "\./perf 34 TARGET=`find . -regex "\./perf.*\.tar\.bz2"` 35 TARGET_NUM=`echo -n "$TARGET" 35 TARGET_NUM=`echo -n "$TARGET" | grep -c '^'` 36 36 37 if [ -z "$TARGET" ] || [ $TARG 37 if [ -z "$TARGET" ] || [ $TARGET_NUM -gt 1 ]; then 38 echo -e "Error: $TARGE 38 echo -e "Error: $TARGET_NUM files found for unpacking:\n$TARGET" 39 echo "Provide the requ 39 echo "Provide the requested file as an argument" 40 exit 1 40 exit 1 41 else 41 else 42 echo "Found target fil 42 echo "Found target file for unpacking: $TARGET" 43 fi 43 fi 44 fi 44 fi 45 45 46 if [[ "$TARGET" =~ (\./)?$PERF_ALL.*.t 46 if [[ "$TARGET" =~ (\./)?$PERF_ALL.*.tar.bz2 ]]; then # perf tar generated by --all option 47 TAR_CONTENTS=`tar tvf "$TARGET 47 TAR_CONTENTS=`tar tvf "$TARGET" | tr -s " " | cut -d " " -f 6` 48 VALID_TAR=`echo "$TAR_CONTENTS 48 VALID_TAR=`echo "$TAR_CONTENTS" | grep "$PERF_SYMBOLS.tar.bz2" | wc -l` # check if it contains a sub-tar perf.symbols 49 if [ $VALID_TAR -ne 1 ]; then 49 if [ $VALID_TAR -ne 1 ]; then 50 echo "Error: $TARGET f 50 echo "Error: $TARGET file is not valid (contains zero or multiple sub-tar files with debug symbols)" 51 exit 1 51 exit 1 52 fi 52 fi 53 53 54 INTERSECT=`comm -12 <(ls) <(ec 54 INTERSECT=`comm -12 <(ls) <(echo "$TAR_CONTENTS") | tr "\n" " "` # check for overwriting 55 if [ ! -z "$INTERSECT" ]; then 55 if [ ! -z "$INTERSECT" ]; then # prompt if file(s) already exist in the current directory 56 echo "File(s) ${INTERS 56 echo "File(s) ${INTERSECT::-1} already exist in the current directory." 57 while true; do 57 while true; do 58 read -p 'Do yo 58 read -p 'Do you wish to overwrite them? ' yn 59 case $yn in 59 case $yn in 60 [Yy]* 60 [Yy]* ) break;; 61 [Nn]* 61 [Nn]* ) exit 1;; 62 * ) ec 62 * ) echo "Please answer yes or no.";; 63 esac 63 esac 64 done 64 done 65 fi 65 fi 66 66 67 # unzip the perf.data file in 67 # unzip the perf.data file in the current working directory and debug symbols in ~/.debug directory 68 tar xvf $TARGET && tar xvf $PE 68 tar xvf $TARGET && tar xvf $PERF_SYMBOLS.tar.bz2 -C ~/.debug 69 69 70 else 70 else # perf tar generated by perf archive (contains only debug symbols) 71 tar xvf $TARGET -C ~/.debug 71 tar xvf $TARGET -C ~/.debug 72 fi 72 fi 73 exit 0 73 exit 0 74 fi 74 fi 75 75 76 # 76 # 77 # PERF_BUILDID_DIR environment variable set by 77 # PERF_BUILDID_DIR environment variable set by perf 78 # path to buildid directory, default to $HOME/ 78 # path to buildid directory, default to $HOME/.debug 79 # 79 # 80 if [ -z $PERF_BUILDID_DIR ]; then 80 if [ -z $PERF_BUILDID_DIR ]; then 81 PERF_BUILDID_DIR=~/.debug/ 81 PERF_BUILDID_DIR=~/.debug/ 82 else 82 else 83 # append / to make substitutions work 83 # append / to make substitutions work 84 PERF_BUILDID_DIR=$PERF_BUILDID_DIR/ 84 PERF_BUILDID_DIR=$PERF_BUILDID_DIR/ 85 fi 85 fi 86 86 87 BUILDIDS=$(mktemp /tmp/perf-archive-buildids.X 87 BUILDIDS=$(mktemp /tmp/perf-archive-buildids.XXXXXX) 88 88 89 perf buildid-list -i $PERF_DATA --with-hits | 89 perf buildid-list -i $PERF_DATA --with-hits | grep -v "^ " > $BUILDIDS 90 if [ ! -s $BUILDIDS ] ; then 90 if [ ! -s $BUILDIDS ] ; then 91 echo "perf archive: no build-ids found 91 echo "perf archive: no build-ids found" 92 rm $BUILDIDS || true 92 rm $BUILDIDS || true 93 exit 1 93 exit 1 94 fi 94 fi 95 95 96 MANIFEST=$(mktemp /tmp/perf-archive-manifest.X 96 MANIFEST=$(mktemp /tmp/perf-archive-manifest.XXXXXX) 97 PERF_BUILDID_LINKDIR=$(readlink -f $PERF_BUILD 97 PERF_BUILDID_LINKDIR=$(readlink -f $PERF_BUILDID_DIR)/ 98 98 99 cut -d ' ' -f 1 $BUILDIDS | \ 99 cut -d ' ' -f 1 $BUILDIDS | \ 100 while read build_id ; do 100 while read build_id ; do 101 linkname=$PERF_BUILDID_DIR.build-id/${ 101 linkname=$PERF_BUILDID_DIR.build-id/${build_id:0:2}/${build_id:2} 102 filename=$(readlink -f $linkname) 102 filename=$(readlink -f $linkname) 103 echo ${linkname#$PERF_BUILDID_DIR} >> 103 echo ${linkname#$PERF_BUILDID_DIR} >> $MANIFEST 104 echo ${filename#$PERF_BUILDID_LINKDIR} 104 echo ${filename#$PERF_BUILDID_LINKDIR} >> $MANIFEST 105 done 105 done 106 106 107 if [ $ALL -eq 1 ]; then 107 if [ $ALL -eq 1 ]; then # pack perf.data file together with tar containing debug symbols 108 HOSTNAME=$(hostname) 108 HOSTNAME=$(hostname) 109 DATE=$(date '+%Y%m%d-%H%M%S') 109 DATE=$(date '+%Y%m%d-%H%M%S') 110 tar cjf $PERF_SYMBOLS.tar.bz2 -C $PERF 110 tar cjf $PERF_SYMBOLS.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST 111 tar cjf $PERF_ALL-$HOSTNAME-$DATE.tar. 111 tar cjf $PERF_ALL-$HOSTNAME-$DATE.tar.bz2 $PERF_DATA $PERF_SYMBOLS.tar.bz2 112 rm $PERF_SYMBOLS.tar.bz2 $MANIFEST $BU 112 rm $PERF_SYMBOLS.tar.bz2 $MANIFEST $BUILDIDS || true 113 else 113 else # pack only the debug symbols 114 tar cjf $PERF_DATA.tar.bz2 -C $PERF_BU 114 tar cjf $PERF_DATA.tar.bz2 -C $PERF_BUILDID_DIR -T $MANIFEST 115 rm $MANIFEST $BUILDIDS || true 115 rm $MANIFEST $BUILDIDS || true 116 fi 116 fi 117 117 118 echo -e "Now please run:\n" 118 echo -e "Now please run:\n" 119 echo -e "$ perf archive --unpack\n" 119 echo -e "$ perf archive --unpack\n" 120 echo "or unpack the tar manually wherever you 120 echo "or unpack the tar manually wherever you need to run 'perf report' on." 121 exit 0 121 exit 0
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.