tools/android/instant_start/benchmark.py
def main():
    """Entry point of the benchmark script"""
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--control-apk',
                        default='out/Release/bin/monochrome_apk',
                        help='The APK script file for control behavior.')
    parser.add_argument('--experiment-apk',
                        default='out/Release/bin/monochrome_apk',
                        help='The APK script file for experiment behavior.')
    parser.add_argument('--reinstall',
                        action='store_true',
                        help='Uninstall before installing the APKs.')
    parser.add_argument('--repeat',
                        type=int,
                        default=3,
                        help='How many times to repeat running.')
    parser.add_argument('--data-output',
                        default='runs.pickle',
                        help='The output file for benchmark data.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='Be more verbose.')
    args, _ = parser.parse_known_args()

    level = logging.WARNING
    if args.verbose == 1:
        level = logging.INFO
    elif args.verbose >= 2:
        level = logging.DEBUG
    logging.basicConfig(level=level,
                        format='%(asctime)-2s %(levelname)-8s %(message)s')
    logging.addLevelName(
        logging.WARNING,
        "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.WARNING))
    logging.addLevelName(
        logging.ERROR,
        "\033[1;41m%s\033[1;0m" % logging.getLevelName(logging.ERROR))

    try:
        subprocess.check_output('which unbuffer', shell=True)
    except subprocess.CalledProcessError:
        sys.exit('ERROR: "unbuffer" not found. ' +
                 'Install by running "sudo apt install expect".')

    logging.warning('Make sure the device screen is unlocked. '
                    'Otherwise the benchmark might get stuck.')

    # List control/experiment APKs for side-by-side comparison.
    variants = []
    variants.append(('control', args.control_apk, []))
    variants.append(('experiment', args.experiment_apk, []))

    metadata = {'model': get_model(), 'start_time': datetime.now()}

    logging.warning('Pre-run for flag caching.')
    for variant in variants:
        run_apk(variant, dry_run=True, reinstall=args.reinstall)

    logging.warning('Dry-run for manual state checking.')
    for variant in variants:
        run_apk(variant, dry_run=True, check_state=True)

    runs = []
    for i in range(args.repeat):
        logging.warning('Run %d/%d', i + 1, args.repeat)
        random.shuffle(variants)
        for variant in variants:
            result = run_apk(variant)
            logging.info('Results: %s', result)
            runs.extend(result)
            time.sleep(10)  # try to avoid overloading the device.
        with open(args.data_output, 'wb') as pickle_file:
            pickle.dump(metadata, pickle_file)
            pickle.dump(runs, pickle_file)
            logging.info('Saved "%s"', args.data_output)
        stats.analyze.print_report(runs, metadata['model'])
Entry point of the benchmark script
Entry point of the benchmark script
Entry point of the benchmark script
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--control-apk',
                        default='out/Release/bin/monochrome_apk',
                        help='The APK script file for control behavior.')
    parser.add_argument('--experiment-apk',
                        default='out/Release/bin/monochrome_apk',
                        help='The APK script file for experiment behavior.')
    parser.add_argument('--reinstall',
                        action='store_true',
                        help='Uninstall before installing the APKs.')
    parser.add_argument('--repeat',
                        type=int,
                        default=3,
                        help='How many times to repeat running.')
    parser.add_argument('--data-output',
                        default='runs.pickle',
                        help='The output file for benchmark data.')
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        default=0,
                        help='Be more verbose.')
    args, _ = parser.parse_known_args()
    level = logging.WARNING
    if args.verbose == 1:
        level = logging.INFO
    elif args.verbose >= 2:
        level = logging.DEBUG
    logging.basicConfig(level=level,
                        format='%(asctime)-2s %(levelname)-8s %(message)s')
    logging.addLevelName(
        logging.WARNING,
        "\033[1;31m%s\033[1;0m" % logging.getLevelName(logging.WARNING))
    logging.addLevelName(
        logging.ERROR,
        "\033[1;41m%s\033[1;0m" % logging.getLevelName(logging.ERROR))
    try:
        subprocess.check_output('which unbuffer', shell=True)
    except subprocess.CalledProcessError:
        sys.exit('ERROR: "unbuffer" not found. ' +
                 'Install by running "sudo apt install expect".')
    logging.warning('Make sure the device screen is unlocked. '
                    'Otherwise the benchmark might get stuck.')
    variants = []
    variants.append(('control', args.control_apk, []))
    variants.append(('experiment', args.experiment_apk, []))
    metadata = {'model': get_model(), 'start_time': datetime.now()}
    logging.warning('Pre-run for flag caching.')
    for variant in variants:
        run_apk(variant, dry_run=True, reinstall=args.reinstall)
    logging.warning('Dry-run for manual state checking.')
    for variant in variants:
        run_apk(variant, dry_run=True, check_state=True)
    runs = []
    for i in range(args.repeat):
        logging.warning('Run %d/%d', i + 1, args.repeat)
        random.shuffle(variants)
        for variant in variants:
            result = run_apk(variant)
            logging.info('Results: %s', result)
            runs.extend(result)
            time.sleep(10)  
        with open(args.data_output, 'wb') as pickle_file:
            pickle.dump(metadata, pickle_file)
            pickle.dump(runs, pickle_file)
            logging.info('Saved "%s"', args.data_output)
        stats.analyze.print_report(runs, metadata['model'])
def main ( ) : parser = argparse . ArgumentParser ( description = __doc__ , formatter_class = argparse . ArgumentDefaultsHelpFormatter ) parser . add_argument ( '--control-apk' , default = 'out/Release/bin/monochrome_apk' , help = 'The APK script file for control behavior.' ) parser . add_argument ( '--experiment-apk' , default = 'out/Release/bin/monochrome_apk' , help = 'The APK script file for experiment behavior.' ) parser . add_argument ( '--reinstall' , action = 'store_true' , help = 'Uninstall before installing the APKs.' ) parser . add_argument ( '--repeat' , type = int , default = 3 , help = 'How many times to repeat running.' ) parser . add_argument ( '--data-output' , default = 'runs.pickle' , help = 'The output file for benchmark data.' ) parser . add_argument ( '-v' , '--verbose' , action = 'count' , default = 0 , help = 'Be more verbose.' ) args , _ = parser . parse_known_args ( ) level = logging . WARNING if args . verbose == 1 : level = logging . INFO elif args . verbose >= 2 : level = logging . DEBUG logging . basicConfig ( level = level , format = '%(asctime)-2s %(levelname)-8s %(message)s' ) logging . addLevelName ( logging . WARNING , "\033[1;31m%s\033[1;0m" % logging . getLevelName ( logging . WARNING ) ) logging . addLevelName ( logging . ERROR , "\033[1;41m%s\033[1;0m" % logging . getLevelName ( logging . ERROR ) ) try : subprocess . check_output ( 'which unbuffer' , shell = True ) except subprocess . CalledProcessError : sys . exit ( 'ERROR: "unbuffer" not found. ' + 'Install by running "sudo apt install expect".' ) logging . warning ( 'Make sure the device screen is unlocked. ' 'Otherwise the benchmark might get stuck.' ) variants = [ ] variants . append ( ( 'control' , args . control_apk , [ ] ) ) variants . append ( ( 'experiment' , args . experiment_apk , [ ] ) ) metadata = { 'model' : get_model ( ) , 'start_time' : datetime . now ( ) } logging . warning ( 'Pre-run for flag caching.' ) for variant in variants : run_apk ( variant , dry_run = True , reinstall = args . reinstall ) logging . warning ( 'Dry-run for manual state checking.' ) for variant in variants : run_apk ( variant , dry_run = True , check_state = True ) runs = [ ] for i in range ( args . repeat ) : logging . warning ( 'Run %d/%d' , i + 1 , args . repeat ) random . shuffle ( variants ) for variant in variants : result = run_apk ( variant ) logging . info ( 'Results: %s' , result ) runs . extend ( result ) time . sleep ( 10 ) with open ( args . data_output , 'wb' ) as pickle_file : pickle . dump ( metadata , pickle_file ) pickle . dump ( runs , pickle_file ) logging . info ( 'Saved "%s"' , args . data_output ) stats . analyze . print_report ( runs , metadata [ 'model' ] )
Entry point of the benchmark script
Entry point of the benchmark script
"""Entry point of the benchmark script""" # List control/experiment APKs for side-by-side comparison. # try to avoid overloading the device.