Home | History | Annotate | Download | only in ioshark
      1 # Copyright (C) 2016 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 # # Unless required by applicable law or agreed to in writing, software
      9 # distributed under the License is distributed on an "AS IS" BASIS,
     10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11 # See the License for the specific language governing permissions and
     12 # limitations under the License.
     13 
     14 #!/bin/sh
     15 
     16 # When signal is received, the stracer will get killed
     17 # Call this (just to make sure anyway)
     18 kill_strace() {
     19     ps_line=`ps -ef | grep strace | grep adb `
     20     if [ $? == 0 ]; then
     21         echo Killing `echo $ps_line | awk '{s = ""; for (i=8; i <= NF ; i++) s = s \
     22 $i " "; print s}' `
     23         kill `echo $ps_line | awk '{print $2}' `
     24     fi
     25 }
     26 
     27 catch_sigint()
     28 {
     29     echo "signal INT received, killing streaming trace capture"
     30     kill_strace
     31 }
     32 
     33 compile_tracefiles()
     34 {
     35     for i in trace.*
     36     do
     37 	if [ $i != trace.begin ] && [ $i != trace.tar ];
     38 	then
     39 	    egrep '\/system\/|\/data\/|\/vendor\/' $i > bar
     40 # parse out /sys/devices/system/...
     41 	    egrep -v '\/sys\/devices\/system\/' bar > bar0
     42 	    mv bar0 bar
     43 	    fgrep -v '= -1'	bar > foo
     44 	    rm bar
     45 	    # begin_time is seconds since epoch
     46 	    begin_time=`cat trace.begin`
     47 	    # replace seconds since epoch with SECONDS SINCE BOOT in the
     48 	    # strace files
     49 	    awk -v begin="$begin_time" '{ printf "%f strace ", $1 - begin; $1=""; print $0}' foo > bar
     50 	    if [ -s bar ]
     51 	    then
     52 		echo parsing $i
     53 		pid=${i##*.}
     54 		compile_ioshark bar $pid.wl
     55 		rm -f bar
     56 	    else
     57 		rm -f $i bar
     58 	    fi
     59 	fi
     60     done
     61 }
     62 
     63 # main() starts here
     64 
     65 adb root && adb wait-for-device
     66 
     67 adb shell 'ps' | grep zygote > zygote_pids
     68 
     69 fgrep -v grep zygote_pids > bar
     70 mv bar zygote_pids
     71 pid1=`grep -w zygote zygote_pids | awk '{print $2}' `
     72 pid2=`grep -w zygote64 zygote_pids | awk '{print $2}' `
     73 rm -f zygote_pids
     74 
     75 trap 'catch_sigint' INT
     76 
     77 echo "^C this script once you finish running your test"
     78 
     79 adb shell "date +%s > /data/local/tmp/trace.begin ; strace -p $pid1,$pid2 -o /data/local/tmp/trace -q -qq -f -ff -y -ttt -e trace=mmap2,read,write,pread64,pwrite64,fsync,fdatasync,openat,close,lseek,_llseek"
     80 
     81 # Remove any remnant tracefiles first
     82 rm -f trace.*
     83 
     84 # Get the tracefiles from the device
     85 adb shell 'cd /data/local/tmp ; tar cvf trace.tar trace.*'
     86 adb pull /data/local/tmp/trace.tar
     87 
     88 # Extract the tracefiles from the device
     89 rm -f *.wl
     90 tar xf trace.tar
     91 
     92 # Compile the tracefiles
     93 compile_tracefiles
     94 
     95 # tar up the .wl files just created
     96 rm -f wl.tar
     97 tar cf wl.tar ioshark_filenames *.wl
     98