25 echo "Usage: $0 [-r|-w]"
30 model=`adb shell getprop ro.product.name`
31 # Releases are inconsistent with various trailing characters, remove them all
32 model=`echo $model | sed 's/[ \t\r\n]*$//' `
33 echo Found $model Device
40 get_marlin_sailfish_devnames
52 echo Unknown Device $model
59 # Hardcoding all of the mmcblk0 device for now
64 get_volantis_devnames() {
69 get_bullhead_devnames() {
74 get_marlin_sailfish_devnames() {
79 get_angler_devnames () {
80 # Get the underlying bdev from the "by-name" mapping
81 block_device=`adb shell 'find /dev/block/platform -name by-name | xargs ls -l' | grep system | awk '{ print $10 }' `
82 # extract the last component of the absolute device pathname we got above
83 block_device=`echo $block_device | awk 'BEGIN { FS ="/" } ; { print $4 }' | sed 's/p.*//g' `
88 if [ $bdev_set == true ]; then
89 DISKSTATS=`adb shell 'cat /proc/diskstats' | fgrep -w $block_device `
90 if [ $trace_reads == true ]; then
91 # Get BEFORE read stats for bdev
92 BEFORE_RD_IOS=`echo $DISKSTATS | awk '{ print $4 }' `
93 BEFORE_RD_SECTORS=`echo $DISKSTATS | awk '{ print $6 }' `
95 if [ $trace_writes == true ]; then
96 # Get BEFORE write stats for bdev
97 BEFORE_WR_IOS=`echo $DISKSTATS | awk '{ print $8 }' `
98 BEFORE_WR_SECTORS=`echo $DISKSTATS | awk '{ print $10 }' `
104 if [ $bdev_set == true ]; then
105 DISKSTATS=`adb shell 'cat /proc/diskstats' | fgrep -w $block_device `
106 if [ $trace_reads == true ]; then
107 # Get AFTER read stats for bdev
108 AFTER_RD_IOS=`echo $DISKSTATS | awk '{ print $4 }' `
109 AFTER_RD_SECTORS=`echo $DISKSTATS | awk '{ print $6 }' `
111 if [ $trace_writes == true ]; then
112 # Get BEFORE write stats for bdev
113 AFTER_WR_IOS=`echo $DISKSTATS | awk '{ print $8 }' `
114 AFTER_WR_SECTORS=`echo $DISKSTATS | awk '{ print $10 }' `
119 disk_stats_delta_rd() {
121 if [ $bdev_set == true ]; then
123 READ_KB=`expr $AFTER_RD_SECTORS - $BEFORE_RD_SECTORS`
124 READ_KB=`expr $READ_KB / 2`
125 echo "Total (ALL) Read KB $block_device = "$READ_KB
126 BLOCK_MINUS_FILE=`expr $READ_KB - $file_data_KB`
127 echo "READ DELTA: Total Blockdev Reads KB - Total File Data Reads KB = "$BLOCK_MINUS_FILE KB
128 echo "Total (ALL) Read IOs $block_device = "`expr $AFTER_RD_IOS - $BEFORE_RD_IOS`
132 disk_stats_delta_wr() {
134 if [ $bdev_set == true ]; then
136 WRITE_KB=`expr $AFTER_WR_SECTORS - $BEFORE_WR_SECTORS`
137 WRITE_KB=`expr $WRITE_KB / 2`
138 echo "Total (ALL) Write KB $block_device = "$WRITE_KB
139 BLOCK_MINUS_FILE=`expr $WRITE_KB - $file_data_KB`
140 echo "WRITE DELTA: Total Blockdev Writes KB - Total File Data Writes KB = "$BLOCK_MINUS_FILE KB
141 echo "Total (ALL) Write IOs $block_device = "`expr $AFTER_WR_IOS - $BEFORE_WR_IOS`
145 # For good measure clean up traces and reenable traces
146 clean_up_tracepoints() {
147 # This is a good point to check if the Android FS tracepoints are enabled in the
149 tracepoint_exists=`adb shell 'if [ -d /sys/kernel/debug/tracing/events/android_fs ]; then echo 0; else echo 1; fi' `
150 if [ $tracepoint_exists == 1 ]; then
151 echo "Android FS tracepoints not enabled in kernel. Exiting..."
154 adb shell 'echo 0 > /sys/kernel/debug/tracing/tracing_on'
155 adb shell 'echo 0 > /sys/kernel/debug/tracing/trace'
156 if [ $trace_reads == true ]; then
157 adb shell 'echo 1 > /sys/kernel/debug/tracing/events/android_fs/android_fs_dataread_start/enable'
158 adb shell 'echo 1 > /sys/kernel/debug/tracing/events/android_fs/android_fs_dataread_end/enable'
160 if [ $trace_writes == true ]; then
161 adb shell 'echo 1 > /sys/kernel/debug/tracing/events/android_fs/android_fs_datawrite_start/enable'
162 adb shell 'echo 1 > /sys/kernel/debug/tracing/events/android_fs/android_fs_datawrite_end/enable'
164 adb shell 'echo 1 > /sys/kernel/debug/tracing/tracing_on'
167 # stream trace out of trace_pipe
168 # Start this in the background ('&')
169 streamtrace_start() {
170 adb shell cat /sys/kernel/debug/tracing/trace_pipe > trace_saved
173 # When signal is received, the trace_pipe reader will get killed
174 # Call this (just to make sure anyway)
176 ps_line=`ps -ef | grep trace_pipe | grep adb `
178 echo Killing `echo $ps_line | awk '{s = ""; for (i=8; i <= NF ; i++) s = s $i " "; print s}' `
179 kill `echo $ps_line | awk '{print $2}' `
185 if [ $trace_reads == true ]; then
186 adb shell 'echo 0 > /sys/kernel/debug/tracing/events/android_fs/android_fs_dataread_start/enable'
187 adb shell 'echo 0 > /sys/kernel/debug/tracing/events/android_fs/android_fs_dataread_end/enable'
189 if [ $trace_writes == true ]; then
190 adb shell 'echo 0 > /sys/kernel/debug/tracing/events/android_fs/android_fs_datawrite_start/enable'
191 adb shell 'echo 0 > /sys/kernel/debug/tracing/events/android_fs/android_fs_datawrite_end/enable'
193 adb shell 'echo 0 > /sys/kernel/debug/tracing/tracing_on'
196 prep_tracefile_common() {
197 cp trace_saved $infile
198 # Strip away all the extraneous stuff first
199 fgrep $1 $infile | sed 's/^.* \[.*\] //' | sed s/://g | sed s/,//g > foo
203 prep_tracefile_rd() {
204 prep_tracefile_common android_fs_dataread
205 # Strip away unnecessary stuff so we can compute latencies easily
206 fgrep android_fs_dataread_start $infile > foo0
207 # Throw away everything upto and including android_fs_dataread:
208 cat foo0 | sed -n -e 's/^.*android_fs_dataread_start //p' > foo1
210 # At this stage, $infile should the following format :
211 # entry_name <filename> offset <offset> bytes <bytes> cmdline <cmdline> pid <pid> i_size <i_size> ino <ino>
215 # Latencies not supported for Writes. 'Write End' is just when the data has been
216 # written back to page cache.
217 prep_tracefile_wr() {
218 prep_tracefile_common android_fs_datawrite
219 fgrep android_fs_datawrite_start $infile > foo0
220 # Throw away everything upto and including android_fs_datawrite:
221 cat foo0 | sed -n -e 's/^.*android_fs_datawrite_start //p' > foo1
223 # At this stage, $infile should the following format :
224 # entry_name <filename> offset <offset> bytes <bytes> cmdline <cmdline> pid <pid> i_size <i_size> ino <ino>
229 # Sort first by filename, then by pid
230 cat $infile | sed s/,//g | sort -d -k2,2 -k8,8 > foo1
232 # $infile now contains lines sorted by <filename, pid>
233 # How many unique files are there ?
234 cat $infile | awk '{ print $2 }' > foo1
235 cat foo1 | uniq > uniq_files
239 get_unique_pids_byfile() {
240 # How many unique pids are there reading this file ?
241 cat $1 | awk '{ print $8 }' > foo1
242 cat foo1 | uniq > uniq_pids_byfile
247 # Sort first by pid, then by filename
248 cat $infile | sed s/,//g | sort -d -k8,8 -k2,2 > foo1
250 # $infile now contains lines sorted by <pid, filename>
251 # How many unique pids are there ?
252 cat $infile | awk '{ print $8 }' > foo1
253 cat foo1 | uniq > uniq_pids
257 get_unique_files_bypid() {
258 # How many unique files are there read by this pid ?
259 cat $1 | awk '{ print $2 }' > foo1
260 cat foo1 | uniq > uniq_files_bypid
266 echo "signal INT received, killing streaming trace capture"
271 prep_to_do_something() {
272 # adb shell "am force-stop com.android.chrome"
273 # adb shell "am force-stop com.google.android.gm"
274 adb shell 'echo 3 > /proc/sys/vm/drop_caches'
279 # Arrange things so that the first SIGINT will kill the
280 # child process (sleep), but will return to the parent.
281 trap 'catch_sigint' INT
282 echo "OK to kill sleep when test is done"
284 # adb shell "am start -W -n com.android.chrome/com.google.android.apps.chrome.Main"
285 # adb shell "am start -W -n com.google.android.gm/.ConversationListActivityGmail"
288 # Get the aggregate list of files read/written. For each file, break up the IOs by pid
292 list_of_files=`cat uniq_files`
293 # $list_of_files is a list of all the files involved in IO
295 # Loop over each file that was involved in IO
296 # Find all the pids doing IO on that file
297 # Aggregate the IO done by each pid on that file and dump it out
300 for i in $list_of_files
304 # Get just the tracepoints for this file
305 fgrep -w "$i" $infile > subtrace
306 # Get all the pids doing IO on this file
307 get_unique_pids_byfile subtrace
308 list_of_pids=`cat uniq_pids_byfile`
309 # $list_of_pids is a list of all the pids doing IO to file $i
310 for j in $list_of_pids
312 echo -n " $j $read_write: "
313 pid_KB=`fgrep -w "$j" subtrace | awk '{ bytes += $6 } END { print bytes }' `
314 pid_KB=`expr $pid_KB / 1024`
316 total_file_KB=`expr $total_file_KB + $pid_KB`
318 i_size=`tail -n1 subtrace | awk '{ if ($12 > 1024) printf "%d KB", ($12/1024); else printf "%d bytes", $12; }' `
319 echo " Total $read_write: $total_file_KB KB i_size: $i_size"
320 grand_total_KB=`expr $grand_total_KB + $total_file_KB`
322 echo "Grand Total File DATA KB $read_write $grand_total_KB"
325 # Get the aggregate list of pids. For each pid, break up the IOs by file
329 list_of_pids=`cat uniq_pids`
330 # $list_of_pids is a list of all the pids involved in IO
332 # Loop over each pid that was involved in IO
333 # Find all the files the pid was doing IO on
334 # Aggregate the IO done by the pid for each file and dump it out
337 for i in $list_of_pids
341 # Get just the tracepoints for this pid
342 fgrep -w "$i" $infile > subtrace
343 # Get all the pids doing IO on this file
344 get_unique_files_bypid subtrace
345 list_of_files=`cat uniq_files_bypid`
346 # $list_of_files is a list of all the files IO'ed by this pid
347 for j in $list_of_files
349 i_size=`fgrep -w "$j" subtrace | tail -n1 | awk '{ if ($12 > 1024) printf "%d KB", ($12/1024); else printf "%d bytes", $12; }' `
350 file_KB=`fgrep -w "$j" subtrace | awk '{ bytes += $6 } END { print bytes }' `
351 file_KB=`expr $file_KB / 1024`
352 echo " $j $read_write: $file_KB KB i_size: $i_size"
353 total_pid_KB=`expr $total_pid_KB + $file_KB`
355 echo " Total $read_write: $total_pid_KB KB"
356 grand_total_KB=`expr $grand_total_KB + $total_pid_KB`
358 echo "Grand Total File DATA KB $read_write $grand_total_KB"
361 # main() starts here :
363 if [ $# -lt 1 ]; then
378 # Start streaming the trace into the tracefile
388 if [ $trace_reads == true ]; then
394 # Get file specific stats - for each file, how many pids read that file ?
397 # Get pid specific stats - for each pid, what files do they do IO on ?
400 disk_stats_delta_rd $grand_total_KB
402 debug_FileKB_rd=`cat $infile | awk '{ bytes += $6 } END { printf "%d", bytes/1024 }' `
403 echo Debug Grand Total KB READ $debug_FileKB_rd
406 if [ $trace_writes == true ]; then
412 # Get file specific stats - for each file, how many pids read that file ?
415 # Get pid specific stats - for each pid, what files do they do IO on ?
418 disk_stats_delta_wr $grand_total_KB
420 debug_FileKB_wr=`cat $infile | awk '{ bytes += $6 } END { printf "%d", bytes/1024 }' `
421 echo Debug Grand Total KB WRITTEN $debug_FileKB_wr
424 rm -rf tracefile* uniq_* subtrace trace_saved