Home | History | Annotate | Download | only in experiments
      1 #!/usr/bin/env python
      2 # SPDX-License-Identifier: Apache-2.0
      3 #
      4 # Copyright (C) 2017, ARM Limited, Google, and contributors.
      5 #
      6 # Licensed under the Apache License, Version 2.0 (the "License"); you may
      7 # not use this file except in compliance with the License.
      8 # You may obtain a copy of the License at
      9 #
     10 # http://www.apache.org/licenses/LICENSE-2.0
     11 #
     12 # Unless required by applicable law or agreed to in writing, software
     13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 # See the License for the specific language governing permissions and
     16 # limitations under the License.
     17 #
     18 
     19 import logging
     20 
     21 from conf import LisaLogging
     22 LisaLogging.setup()
     23 import json
     24 import os
     25 import devlib
     26 from env import TestEnv
     27 from android import Screen, Workload, System
     28 from trace import Trace
     29 import trappy
     30 import pandas as pd
     31 import sqlite3
     32 import argparse
     33 import shutil
     34 
     35 parser = argparse.ArgumentParser(description='Jankbench tests')
     36 
     37 parser.add_argument('--out_prefix', dest='out_prefix', action='store', default='default',
     38                     help='prefix for out directory')
     39 
     40 parser.add_argument('--collect', dest='collect', action='store', default='systrace',
     41                     help='what to collect (default systrace)')
     42 
     43 parser.add_argument('--test', dest='test_name', action='store',
     44                     default='overdraw',
     45                     help='which test to run')
     46 
     47 parser.add_argument('--iterations', dest='iterations', action='store',
     48                     default=10, type=int,
     49                     help='Number of times to repeat the tests per run (default 10)')
     50 
     51 parser.add_argument('--serial', dest='serial', action='store',
     52                     help='Serial number of device to test')
     53 
     54 parser.add_argument('--all', dest='run_all', action='store_true',
     55                     help='Run all tests')
     56 
     57 parser.add_argument('--reinstall', dest='reinstall', action='store_true',
     58                     help='Rebuild and reinstall test apks')
     59 
     60 parser.add_argument('--reimage', dest='reimage', action='store',
     61                     default='',
     62                     help='Flag to reimage target device (kernel-update kernel image | all-update complete android image)')
     63 
     64 parser.add_argument('--kernel_path', dest='kernel_path', action='store',
     65                     default='',
     66                     help='Path to kernel source directory. Required if reimage option is used')
     67 
     68 args = parser.parse_args()
     69 
     70 def make_dir(outdir):
     71     try:
     72         shutil.rmtree(outdir)
     73     except:
     74         print "couldn't remove " + outdir
     75         pass
     76     os.makedirs(outdir)
     77 
     78 def print_results(te, test_outdir, test_name, wload):
     79     res_df = wload.get_results(test_outdir).describe(percentiles=[0.25,0.5,0.75,0.95,0.99])
     80     stats_df = res_df['total_duration']
     81     te._log.info("==============================================")
     82     te._log.info("JANKBENCH TEST RESULT: Frame stats: {}".format(test_name))
     83     stats_str = stats_df.to_string().split('\n')
     84     for s in stats_str:
     85         te._log.info(s)
     86     te._log.info("==============================================")
     87 
     88 def experiment():
     89     def run_test(outdir, test_name):
     90         te._log.info("Running test {}".format(test_name))
     91         wload.run(outdir, test_name=test_name, iterations=args.iterations, collect=args.collect)
     92 
     93     if args.reimage:
     94         System.reimage(te, args.kernel_path, args.reimage)
     95 
     96     # Get workload
     97     wload = Workload.getInstance(te, 'Jankbench', args.reinstall)
     98 
     99     outdir=te.res_dir + '_' + args.out_prefix
    100     make_dir(outdir)
    101 
    102     # Run Jankbench
    103     if args.run_all:
    104         te._log.info("Running all tests: {}".format(wload.test_list))
    105         for test in wload.get_test_list():
    106             test_outdir = os.path.join(outdir, test)
    107             make_dir(test_outdir)
    108             run_test(test_outdir, test)
    109             print_results(te, test_outdir, test, wload)
    110     else:
    111         test_outdir = os.path.join(outdir, args.test_name)
    112         make_dir(test_outdir)
    113         run_test(test_outdir, args.test_name)
    114         print_results(te, test_outdir, args.test_name, wload)
    115 
    116     # Dump platform descriptor
    117     te.platform_dump(te.res_dir)
    118 
    119     te._log.info('RESULTS are in out directory: {}'.format(outdir))
    120 
    121 # Setup target configuration
    122 my_conf = {
    123 
    124     # Target platform and board
    125     "platform"     : 'android',
    126 
    127     # Useful for reading names of little/big cluster
    128     # and energy model info, its device specific and use
    129     # only if needed for analysis
    130     # "board"        : 'pixel',
    131 
    132     # Device
    133     # By default the device connected is detected, but if more than 1
    134     # device, override the following to get a specific device.
    135     # "device"       : "HT6880200489",
    136 
    137     # Folder where all the results will be collected
    138     "results_dir" : "Jankbench",
    139 
    140     # Define devlib modules to load
    141     "modules"     : [
    142         'cpufreq',      # enable CPUFreq support
    143         'cpuidle',      # enable cpuidle support
    144         # 'cgroups'     # Enable for cgroup support
    145     ],
    146 
    147     "emeter" : {
    148         'instrument': 'monsoon',
    149         'conf': { }
    150     },
    151 
    152     # Tools required by the experiments
    153     "tools"   : [ 'taskset'],
    154 
    155     "skip_nrg_model" : True,
    156 }
    157 
    158 if args.serial:
    159     my_conf["device"] = args.serial
    160 
    161 # Initialize a test environment using:
    162 te = TestEnv(my_conf, wipe=False)
    163 target = te.target
    164 
    165 results = experiment()
    166