1,java
批量替換STDC++ 宏定義爲 STDCPLUSPLUS31637linux
grep -r "STDC++" ./| awk -F : '{print $1}' |sort|uniq > tmpandroid
while read line; do echo $line; sed -i s/STDC++/STDCPLUSPLUS/g $line; done < tmpsql
grep -r "STDC++" ./| awk -F : '{print $1}' |sort|uniq | 過濾./下文件內容中有STDC++ 的文件,按順序排列,取重複 |
while read line; do echo $line; done < tmp | 讀文件的的每一行並打印到標準輸出 |
sed -i s/STDC++/STDCPLUSPLUS/g $line | 替換STDC++ 爲 STDCPLUSPLUS |
//批量替換字符shell
sed -i -e 's/namespace liyl {/LIYL_NAMESPACE_START/i' -e 's/}.*\/\/ namespace liyl/LIYL_NAMESPACE_END/i' *.hapache
Android malloc 調試.tomcat
#########################################################################
# File Name: XXXX_malloc_debug.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: Wed 07 Dec 2016 03:02:31 PM CST
#########################################################################
#!/bin/bash
echo "IP: $1"
adb connect $1
adb root
adb connect $1
adb remount
adb shell stop
#leak
adb shell setprop libc.debug.malloc 10
echo "setprop libc.debug.malloc 10"
adb shell setprop libc.debug.malloc.program /system/bin/mediaserver
echo "setprop libc.debug.malloc.program"
adb shell setprop libc.debug.malloc.options backtrace
#adb shell setprop libc.debug.malloc.options "\"backtrace guards\""
echo "libc.debug.malloc.options backtrace"
adb shell start
echo "wait-devices"
adb wait-for-device
adb connect $1
echo "connect $1"bash
Android valgrind DEBUGapp
#########################################################################
# File Name: valgrind_mediaserver.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: Mon 13 Feb 2017 03:06:24 PM CST
#########################################################################
#!/bin/bash
OUT=/home/liyl/source/MSTAR918/out/target/product/mstarnapoli
adb shell mkdir /data/local/tmp
adb shell chmod 777 /data/local/tmptcp
#For debug symbols, push unstripped libraries to /data/local/symbols:
adb shell mkdir /data/local/symbols
adb push $OUT/symbols /data/local/symbols
#adb shell setprop wrap.mediaserver "logwrapper /data/local/val.sh"
adb shell stop media
adb shell valgrind --tool=callgrind --log-file=/sdcard/callgrind.media.liyl --trace-children=yes /system/bin/mediaserver
Android dump 日誌
adb shell setprop xx.omx.log 1
adb shell setprop xx.mstplayer.omx 1
adb shell setprop xx.adec.log 1
adb shell setprop xx.vdec.log 1
adb shell setprop xx.vsync_bridge.log 1
adb shell setprop test.adec.log_on 99
adb shell setprop xx.avp.debug.demuxer 1
adb shell chmod 777 /mnt/usb/sda1
adb shell rm /mnt/usb/sda1/dump*
adb shell logcat -c
adb shell logcat -v threadtime -f /mnt/usb/sda1/dump1.log &
for i in `seq 100`;
do
echo "$$ $i"
#adb shell logcat -v threadtime -f /mnt/usb/sda1/dump$i.log &
echo "pid = $$ start write $i"
adb shell ps > ps.log
sleep 900
echo "$? start write $i done "
awk '$NF~/logcat/{print $2}' ps.log > logcat_process.log
while read pid;
do
echo "adb shell kill $pid"
adb shell kill $pid
done < logcat_process.log
echo "adb logcat dump$((i+1)).log "
adb shell logcat -c
adb shell logcat -v threadtime -f /mnt/usb/sda1/dump$((i+1)).log &
adb pull /mnt/usb/sda1/dump$i.log ./
echo " adb pull $i done "
adb shell rm /mnt/usb/sda1/dump$i.log
echo "adb shell rm $i done "
done
Android GDB 腳本
########################gdbserver.sh#############################
#########################################################################
# File Name: gdbserver.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: Thu 01 Dec 2016 04:09:36 PM CST
#########################################################################
#!/bin/bash
APP_BIN_NAME=$1
if [ -n $APP_BIN_NAME ] ;then
APP_BIN_NAME=mediaserver
echo "defalt debug mediaserver"
fi
SO_LIB_DIR=$2
if [ -n $SO_LIB_DIR ] ;then
SO_LIB_DIR=/home/liyl/source/MSTAR928/out/target/product/guava/symbols/system/lib
echo "defalt debug mediaserver"
fi
echo $SO_LIB_DIR
#export MY_NDK_BIN_DIR=/home/liyl/android_env/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin
#/home/liyl/source/MSTAR928/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/
#MY_NDK_BIN_DIR=/home/liyl/android_env/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin
MY_NDK_BIN_DIR=/home/liyl/source/MSTAR928/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin
export MediaPID=`adb shell ps |busybox awk '/mediaserver/{print $2}'`
export MYPORT=8825
echo $MediaPID
adb shell gdbserver :$MYPORT --attach $MediaPID &
sleep 5
echo $MY_NDK_BIN_DIR
$MY_NDK_BIN_DIR/arm-linux-androideabi-gdb --write -l 360000 $SO_LIB_DIR/../bin/$APP_BIN_NAME -x gdb_cmd.sh
shell adb forward tcp:$MYPORT tcp:$MYPORT
target remote localhost:$MYPORT
######################gdbserver.sh###############################
#########################################################################
# File Name: gdb_cmd.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: Thu 01 Dec 2016 04:09:36 PM CST
#########################################################################
#!/bin/bash
shell adb forward tcp:8825 tcp:8825
target remote localhost:8825
最後一列逐行累加
#########################################################################
# File Name: colums_plus_awk.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: 2017年05月19日 星期五 10時27分58秒
#########################################################################
#!/bin/bash
#awk -F ' ' '{print $0 " " $1}' tmp
awk -F ' ' 'BEGIN{print "liyl add "NR ;b=0}$1 ~ /1/{b +=$NF;percent = $NF*100;percentsum = b*100; print " "$0" "percent"% "percentsum"%"}END{print "liyl add :"NR}' tmp
// sql 拼接
for i in `seq 100`;
do
# echo "$$ $i"
reg1=`expr $i \* 40`
reg2=$(($i*40+40))
echo "WHEN val1 > '${reg1}' AND val1 <= '${reg2}' THEN '${reg1}-${reg2}'"
done
//解析native hprof
前提是 libc.debug.malloc 1
#!/bin/bash
#
# Native heap dump not available. To enable, run these commands (requires root):
# adb shell setprop libc.debug.malloc 1
# $ adb shell stop
# $ adb shell start
adb root
adb enforce 0
export MYPID=`adb shell ps |busybox awk '/com.xxx.xxx[^:]/{print $2}'`
echo "youku PID = $MYPID"
adb shell rm /sdcard/ee.trace
adb shell am dumpheap -n $MYPID /sdcard/ee.trace
sleep 10
adb pull /sdcard/ee.trace ./
java -version
java -jar /home/xxx/Downloads/nativeMemTool/nativeMemory_jar/motu_android_native_memory_analyze.jar -n out/target/product/generic/symbols/system/lib/libxxx.so ee.trace
//setup opengrok
7 #!/bin/bash
8 ps aux |grep -iE "ctag|opengrok"
9 export MY_OPENGROK_LOCAL_PATH=`pwd`
10 echo "PWD = $MY_OPENGROK_LOCAL_PATH"
11 sh $MY_OPENGROK_LOCAL_PATH/apache-tomcat-8.5.13/bin/startup.sh
12 sh $MY_OPENGROK_LOCAL_PATH/opengrok-1.0/bin/README.sh
README.sh
#local path
#MY_OPENGROK_LOCAL_PATH=`pwd`
echo "pwd = $MY_OPENGROK_LOCAL_PATH"
#deploy opengrok to tomcat
OPENGROK_TOMCAT_BASE=$MY_OPENGROK_LOCAL_PATH/apache-tomcat-8.5.13 $MY_OPENGROK_LOCAL_PATH/opengrok-1.0/bin/OpenGrok deploy
#creat index of source && create ../ect/ ../data/
#OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=$MY_OPENGROK_LOCAL_PATH/opengrok-1.0/myproject $MY_OPENGROK_LOCAL_PATH/opengrok-1.0/bin/OpenGrok index /home/source/xxx
OPENGROK_WEBAPP_CONTEXT=/xxx OPENGROK_VERBOSE=true OPENGROK_INSTANCE_BASE=$MY_OPENGROK_LOCAL_PATH/opengrok-1.0/xxx $MY_OPENGROK_LOCAL_PATH/opengrok-1.0/bin/OpenGrok index /home/source/xxx
// android 打印backtrace
#!/bin/bash
export MYPID=`adb shell ps |busybox awk '/test/{print $2}'`
adb shell debuggerd -b $MYPID
//解析tomstone
#!/bin/bash
adb pull /data/tombstones/tombstone_00 ./
$NDK/ndk-stack -sym obj/local/armeabi-v7a/ -dump tombstone_00 |tee 2.log
adb shell rm -rf /data/tombstones/tombstone_*
APP_BIN_NAME=$1
MOBILE_DIR=/data/local/tmp
if [ -n $APP_BIN_NAME ] ;then
APP_BIN_NAME=netcache_test
echo "defalt debug $MOBILE_DIR/$APP_BIN_NAME"
fi
SO_LIB_DIR=$2
if [ -n $SO_LIB_DIR ] ;then
SO_LIB_DIR=/home/lyl/source/xxx/obj/local/armeabi-v7a
echo "defalt so_lib_dir = $SO_LIB_DIR"
fi
echo $SO_LIB_DIR
#MY_NDK_BIN_DIR=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
MY_NDK_BIN_DIR=/home/lyl/android_env/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
export MYPORT=8825
adb shell LD_LIBRARY_PATH=/data/local/tmp $MOBILE_DIR/gdbserver :$MYPORT $MOBILE_DIR/$APP_BIN_NAME &
sleep 5
echo $MY_NDK_BIN_DIR
$MY_NDK_BIN_DIR/arm-linux-androideabi-gdb --write -l 360000 $SO_LIB_DIR/$APP_BIN_NAME -x gdb_cmd.sh
#!/bin/bash
shell adb forward tcp:8825 tcp:8825
target remote localhost:8825
#source /home/lyl/source/netcache/NetCache/libs/armeabi-v7a/gdb.setup
source ./libs/armeabi-v7a/gdb.setup
#file /home/lyl/source/netcache/NetCache/gtest/obj/local/armeabi-v7a/libnetcache.so
#b /home/lyl/source/netcache/NetCache/jni/downloader/cache_http_downloader.cpp:42
# default allow pending breakpoint,YES
set breakpoint pending on
b class::class::freeNode()
//valgrind
#!/bin/bash
adb shell "VALGRIND_LIB=/data/local/valgrind/lib64 LD_LIBRARY_PATH=/data/local/tmp /data/local/valgrind/valgrind --trace-children=yes --tool=memcheck --show-reachable=yes --leak-check=full --keep-stacktraces=alloc-then-free --track-origins=yes /data/local/tmp/xxx_test --gtest_filter=xxx.test9"
// app valgrind
vg_app.sh
#!/bin/bash
export TMPDIR=/data/data/com.xxx.xxx
export VALGRIND_LIB=/data/local/valgrind/lib64
VGPARAMS=' --error-limit=no --trace-children=yes --tool=memcheck --show-reachable=yes --leak-check=full'
exec /data/local/valgrind/valgrind $VGPARAMS $*
valgrind_app.sh
#!/bin/bash
adb push vg_app.sh /data/local/
adb shell chmod a+x /data/local/vg_app.sh
adb shell setprop wrap.com.xxx.xxx \'logwrapper /data/local/vg_app.sh\'
#kill youku app
export MYPID=`adb shell ps |busybox awk '/com.xxx.xxx[^:]/{print $2}'`
echo "youku PID = $MYPID"
adb shell kill -9 $MYPID
objdump.sh
#!/bin/bash
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objdump -S -d -C obj/local/armeabi-v7a/libxxx.so >libxxx.so.s
$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-objdump -S -d -C obj/local/armeabi-v7a/xxx_test >xxx_test.s
#getTastStatusByName
#!/bin/bash
#########################################################################
# File Name: get_task.sh
# Author: liyl
# mail: liyunlong_88@126.com
# Created Time: 2017年07月24日 星期一 11時26分20秒
#########################################################################
export MYPID=`adb shell ps |busybox awk '/com.xxx.phone[^:-]/{print $2}'`
echo "youku PID = $MYPID"
for i in `seq 100`;
do
echo "$i "
adb shell ls -la /proc/$MYPID/task/ > $i.task
cat $i.task | sort > ${i}_tast.status
while read line;
do
taskId=`echo $line | awk '{gsub("\r","");print $NF}'`
echo "\r\ncat /proc/$MYPID/task/$taskId/status" >> ${i}_tast.status
adb shell cat /proc/$MYPID/task/$taskId/status >> ${i}_tast.status&
wait
#wait behind thread exit
done < $i.task
rm $i.task
sleep 60
done
//十進制數批量轉ascii 碼
printf "%x" 1094995529 | sed 's/\(..\)/\\\\x\1/g' | xargs echo -e