1*288bf522SAndroid Build Coastguard Worker#!/bin/sh 2*288bf522SAndroid Build Coastguard Worker 3*288bf522SAndroid Build Coastguard Worker# This function just re-writes the timestamp of the strace entries to be 4*288bf522SAndroid Build Coastguard Worker# seconds.usecs since boot. To match the timestamping of ftrace (so we can 5*288bf522SAndroid Build Coastguard Worker# merge them later). 6*288bf522SAndroid Build Coastguard Workerprocess_strace() 7*288bf522SAndroid Build Coastguard Worker{ 8*288bf522SAndroid Build Coastguard Worker strace=$1 9*288bf522SAndroid Build Coastguard Worker # parse in data/system/vendor and parse out /sys/devices/system/... 10*288bf522SAndroid Build Coastguard Worker egrep '\/system\/|\/data\/|\/vendor\/' $strace | egrep -v '\/sys\/devices\/system\/' > bar 11*288bf522SAndroid Build Coastguard Worker fgrep -v '= -1' bar > foo 12*288bf522SAndroid Build Coastguard Worker mv foo bar 13*288bf522SAndroid Build Coastguard Worker # begin_time is seconds since epoch 14*288bf522SAndroid Build Coastguard Worker begin_time=`cat trace.begin` 15*288bf522SAndroid Build Coastguard Worker # replace seconds since epoch with SECONDS SINCE BOOT in the 16*288bf522SAndroid Build Coastguard Worker # strace files 17*288bf522SAndroid Build Coastguard Worker awk -v begin="$begin_time" '{ printf "%f strace ", $1 - begin; $1=""; print $0}' bar > $2 18*288bf522SAndroid Build Coastguard Worker rm bar 19*288bf522SAndroid Build Coastguard Worker} 20*288bf522SAndroid Build Coastguard Worker 21*288bf522SAndroid Build Coastguard Worker# 22*288bf522SAndroid Build Coastguard Worker# This function processes the ftrace file, removing the fields that we don't care 23*288bf522SAndroid Build Coastguard Worker# about, breaks up the ftrace file into one file per pid. 24*288bf522SAndroid Build Coastguard Worker# Input : One single fstrace file. 25*288bf522SAndroid Build Coastguard Worker# Output : Multiple fstrace.pid files. 26*288bf522SAndroid Build Coastguard Workerprep_fstrace() 27*288bf522SAndroid Build Coastguard Worker{ 28*288bf522SAndroid Build Coastguard Worker # Remove leading junk 29*288bf522SAndroid Build Coastguard Worker fgrep f2fs_data $1 | sed 's/^.* \[.*\] //' | sed s/://g | sed s/,//g > foo 30*288bf522SAndroid Build Coastguard Worker sed 's/f2fs_dataread_start/read/' foo > bar1 31*288bf522SAndroid Build Coastguard Worker mv bar1 bar 32*288bf522SAndroid Build Coastguard Worker # First column is timestamp SECONDS SINCE BOOT 33*288bf522SAndroid Build Coastguard Worker awk '{ print $2, "ftrace", $3, $5, $7, $9, $13 }' bar > foo 34*288bf522SAndroid Build Coastguard Worker rm bar 35*288bf522SAndroid Build Coastguard Worker # Get all the uniq pids 36*288bf522SAndroid Build Coastguard Worker awk '{print $7}' foo | sort | uniq > pidlist 37*288bf522SAndroid Build Coastguard Worker for i in `cat pidlist` 38*288bf522SAndroid Build Coastguard Worker do 39*288bf522SAndroid Build Coastguard Worker awk -v pid=$i '{ if (pid == $7) print $0}' foo > fstrace.$i 40*288bf522SAndroid Build Coastguard Worker done 41*288bf522SAndroid Build Coastguard Worker rm pidlist 42*288bf522SAndroid Build Coastguard Worker rm foo 43*288bf522SAndroid Build Coastguard Worker} 44*288bf522SAndroid Build Coastguard Worker 45*288bf522SAndroid Build Coastguard Worker# Merge straces and ftraces. 46*288bf522SAndroid Build Coastguard Worker# The goal here is to catch mmap'ed IO (reads) that won't be in the 47*288bf522SAndroid Build Coastguard Worker# strace file. The algorithm is to look for mmaps in the strace file, 48*288bf522SAndroid Build Coastguard Worker# use the files tha are mmap'ed to search in the ftraces to pick up 49*288bf522SAndroid Build Coastguard Worker# tracepoints from there, and merge those with the straces. 50*288bf522SAndroid Build Coastguard Worker# The output of this function is a set of parsed_input_trace.<pid> 51*288bf522SAndroid Build Coastguard Worker# files, that can then be compiled into .wl files 52*288bf522SAndroid Build Coastguard Workermerge_compile() 53*288bf522SAndroid Build Coastguard Worker{ 54*288bf522SAndroid Build Coastguard Worker for stracefile in trace.* 55*288bf522SAndroid Build Coastguard Worker do 56*288bf522SAndroid Build Coastguard Worker if [ $stracefile == trace.begin ] || [ $stracefile == trace.tar ]; 57*288bf522SAndroid Build Coastguard Worker then 58*288bf522SAndroid Build Coastguard Worker continue 59*288bf522SAndroid Build Coastguard Worker fi 60*288bf522SAndroid Build Coastguard Worker # Get the pid from the strace filename (pid is the extension) 61*288bf522SAndroid Build Coastguard Worker pid=${stracefile##*.} 62*288bf522SAndroid Build Coastguard Worker process_strace $stracefile foo.$pid 63*288bf522SAndroid Build Coastguard Worker if ! [ -s foo.$pid ]; then 64*288bf522SAndroid Build Coastguard Worker rm foo.$pid 65*288bf522SAndroid Build Coastguard Worker continue 66*288bf522SAndroid Build Coastguard Worker fi 67*288bf522SAndroid Build Coastguard Worker # 68*288bf522SAndroid Build Coastguard Worker # If we have matching strace and ftrace files, then look for mmaps in 69*288bf522SAndroid Build Coastguard Worker # the strace pluck the corresponding entries for the mmap (mmaped IO) 70*288bf522SAndroid Build Coastguard Worker # from the ftrace and merge them into the strace 71*288bf522SAndroid Build Coastguard Worker # 72*288bf522SAndroid Build Coastguard Worker if [ -f fstrace.$pid ]; then 73*288bf522SAndroid Build Coastguard Worker fgrep mmap foo.$pid > bar 74*288bf522SAndroid Build Coastguard Worker if [ -s bar ]; then 75*288bf522SAndroid Build Coastguard Worker # Get all the unique mmap'ed filenames from the strace 76*288bf522SAndroid Build Coastguard Worker awk '{ print $7 }' bar | sed 's/^[^<]*<//g' | sed 's/>,//g' > mapped_files 77*288bf522SAndroid Build Coastguard Worker # Pluck all the lines from the ftrace corresponding to the mmaps 78*288bf522SAndroid Build Coastguard Worker cat /dev/null > footemp 79*288bf522SAndroid Build Coastguard Worker for j in `sort mapped_files | uniq` 80*288bf522SAndroid Build Coastguard Worker do 81*288bf522SAndroid Build Coastguard Worker # Merge the readpage(s) traces from the ftrace into strace 82*288bf522SAndroid Build Coastguard Worker # for this mmaped file. 83*288bf522SAndroid Build Coastguard Worker grep -w $j fstrace.$pid > foobar 84*288bf522SAndroid Build Coastguard Worker if [ $? == 0 ]; then 85*288bf522SAndroid Build Coastguard Worker sort foo.$pid foobar >> footemp 86*288bf522SAndroid Build Coastguard Worker fi 87*288bf522SAndroid Build Coastguard Worker rm foobar 88*288bf522SAndroid Build Coastguard Worker done 89*288bf522SAndroid Build Coastguard Worker rm mapped_files 90*288bf522SAndroid Build Coastguard Worker if [ -s footemp ]; then 91*288bf522SAndroid Build Coastguard Worker mv footemp parsed_input_trace.$pid 92*288bf522SAndroid Build Coastguard Worker else 93*288bf522SAndroid Build Coastguard Worker mv foo.$pid parsed_input_trace.$pid 94*288bf522SAndroid Build Coastguard Worker fi 95*288bf522SAndroid Build Coastguard Worker else 96*288bf522SAndroid Build Coastguard Worker mv foo.$pid parsed_input_trace.$pid 97*288bf522SAndroid Build Coastguard Worker fi 98*288bf522SAndroid Build Coastguard Worker rm bar 99*288bf522SAndroid Build Coastguard Worker else 100*288bf522SAndroid Build Coastguard Worker mv foo.$pid parsed_input_trace.$pid 101*288bf522SAndroid Build Coastguard Worker fi 102*288bf522SAndroid Build Coastguard Worker echo compiling parsed_input_trace.$pid 103*288bf522SAndroid Build Coastguard Worker compile_ioshark parsed_input_trace.$pid $pid.wl 104*288bf522SAndroid Build Coastguard Worker rm parsed_input_trace.$pid 105*288bf522SAndroid Build Coastguard Worker rm -f foo.$pid 106*288bf522SAndroid Build Coastguard Worker done 107*288bf522SAndroid Build Coastguard Worker} 108*288bf522SAndroid Build Coastguard Worker 109*288bf522SAndroid Build Coastguard Worker# main() starts here 110*288bf522SAndroid Build Coastguard Worker 111*288bf522SAndroid Build Coastguard Workerrm -f *.wl 112*288bf522SAndroid Build Coastguard Workerrm -f parsed* 113*288bf522SAndroid Build Coastguard Workerrm -f ioshark_filenames 114*288bf522SAndroid Build Coastguard Worker 115*288bf522SAndroid Build Coastguard Worker# Pre-process the ftrace file 116*288bf522SAndroid Build Coastguard Workerprep_fstrace fstrace 117*288bf522SAndroid Build Coastguard Worker# Merge the ftrace file(s) with the strace files 118*288bf522SAndroid Build Coastguard Workermerge_compile 119*288bf522SAndroid Build Coastguard Worker 120*288bf522SAndroid Build Coastguard Worker# tar up the .wl files just created 121*288bf522SAndroid Build Coastguard Workertar cf wl-test.tar ioshark_filenames *.wl 122