-1

I'm trying to automatically collect performance data (loading and screen rendering times) from an Android app. I use test-runner.py (an internal tool) to build the app and run the tests before using the adb command to get the performance data. My bash script looks like this:

BASE_DIR=../Application/app/src/custom-feeds
CTF_DIR=../../../../ComponentTestFramework
OUTPUT_FILE=out.txt

if test -e $OUTPUT_FILE
then
    rm $OUTPUT_FILE
fi

teardown ()
{
    cd $BASE_DIR
    adb logcat -d PerformanceTest:D *:S | grep 'Loading' | tee -a $OUTPUT_FILE
    adb logcat -d ActivityManager:I *:S | grep 'ContentBrowseActivity:\s+\+' | tee -a $OUTPUT_FILE
    ./restore.sh
}

# small sample feed

echo Testing sample feed with 10 initial items
echo size = 10 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-10.json
teardown

# medium sample feed

echo Testing sample feed with 100 initial items
echo size = 100 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-100.json
teardown

# large sample feed

echo Testing sample feed with 500 initial items
echo size = 500 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-500.json
teardown

# super large sample feed

echo Testing sample feed with 5000 initial items
echo size = 5000 > $OUTPUT_FILE
cd $CTF_DIR
python3 test_runner.py -f $BASE_DIR/config-B-5000.json
teardown

When the script is first run, the data gets written to the output file as expected:

size = 100

However, nothing else gets written until the script finishes executing. The output file now looks like this:

size = 5000
D/PerformanceTest( 1458): Loading time: 332874 ms
I/ActivityManager( 1843): Displayed com.amazon.android.calypso/com.amazon.android.tv.tenfoot.ui.activities.ContentBrowseActivity: +563ms

There are two issues:

  1. The original data ("size = 100") has been written. This shouldn't happen because of the -a switch in tee.
  2. The intermediate results aren't being written to the file even though the command works when I execute it outside the script.

What am I doing wrong?

Danny
  • 705
  • 1
  • 7
  • 23
  • It's not uncommon for `tee` or many others to buffer their output, so it wouldn't write until a certain amount of data was in the queue or the end of the stream is reached. I wouldn't be surprised if that's what's going on here. [See here](http://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe) for some options to deal with that if it's what's happening here – Eric Renouf Nov 21 '16 at 01:00
  • "size = 100" is not going through tee. `size = 100` is redirected, and that redirection truncates the file discarding the results of the previous run. – William Pursell Nov 21 '16 at 01:23
  • Ah, I see the issue now. Thanks for the responses. I meant to append to the file using `>>` but wrote `>` instead. \*facepalm\*. – Danny Nov 21 '16 at 01:32

1 Answers1

0

Answering my own question in embarrassment.

The issue was due to my use of > (which overwrites the file) than >> (which appends to it). Using >> obviously solved the problem. I'm still facepalming as I type this.

Danny
  • 705
  • 1
  • 7
  • 23