def setup(self, context): self.capture_file = _f( os.path.join(context.output_directory, 'streamline', 'capture.apc')) self.report_file = _f( os.path.join(context.output_directory, 'streamline', 'streamline.csv'))
def setup(self, context): # Note: the config file needs to be copies on each iteration's setup # because gator appears to "consume" it on invocation... if self.configuration_file: self.device.push_file(self.configuration_file, self.on_device_config) self._initialize_daemon() self.capture_file = _f(os.path.join(context.output_directory, 'streamline', 'capture.apc')) self.report_file = _f(os.path.join(context.output_directory, 'streamline', 'streamline.csv'))
def get(self, resource, **kwargs): if resource.owner.name != 'streamline': return None test_path = _f(os.path.join(self.dependencies_directory, resource.path)) if os.path.isfile(test_path): return test_path test_path = _f(os.path.join(self.old_dependencies_directory, resource.path)) if os.path.isfile(test_path): return test_path
def setup(self, context): if self.loglevel: self.old_loglevel = self.device.get_sysfile_value( self.loglevel_file) self.device.set_sysfile_value(self.loglevel_file, self.loglevel, verify=False) self.before_file = _f( os.path.join(context.output_directory, 'dmesg', 'before')) self.after_file = _f( os.path.join(context.output_directory, 'dmesg', 'after'))
def create_uiauto_project(path, name, target='1'): sdk_path = get_sdk_path() android_path = os.path.join(sdk_path, 'tools', 'android') package_name = 'com.arm.wlauto.uiauto.' + name.lower() # ${ANDROID_HOME}/tools/android create uitest-project -n com.arm.wlauto.uiauto.linpack -t 1 -p ../test2 command = '{} create uitest-project --name {} --target {} --path {}'.format(android_path, package_name, target, path) try: check_output(command, shell=True) except subprocess.CalledProcessError as e: if 'is is not valid' in e.output: message = 'No Android SDK target found; have you run "{} update sdk" and download a platform?' raise CommandError(message.format(android_path)) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: template = string.Template(UIAUTO_BUILD_SCRIPT) wfh.write(template.substitute({'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f(os.path.join(path, 'src', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write(render_template('UiAutomation.java', {'name': name, 'package_name': package_name}))
def create_uiauto_project(path, name): package_name = 'com.arm.wlauto.uiauto.' + name.lower() shutil.copytree(os.path.join(TEMPLATES_DIR, 'uiauto_template'), path) manifest_path = os.path.join(path, 'app', 'src', 'main') mainifest = os.path.join(_d(manifest_path), 'AndroidManifest.xml') with open(mainifest, 'w') as wfh: wfh.write(render_template('uiauto_AndroidManifest.xml', {'package_name': package_name})) build_gradle_path = os.path.join(path, 'app') build_gradle = os.path.join(_d(build_gradle_path), 'build.gradle') with open(build_gradle, 'w') as wfh: wfh.write(render_template('uiauto_build.gradle', {'package_name': package_name})) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: wfh.write(render_template('uiauto_build_script', {'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f(os.path.join(path, 'app', 'src', 'main', 'java', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write(render_template('UiAutomation.java', {'name': name, 'package_name': package_name}))
def update_result(self, context): for label in self.labels: device_file = self._get_device_outfile(label) host_relpath = os.path.join('perf', os.path.basename(device_file)) host_file = _f(os.path.join(context.output_directory, host_relpath)) self.device.pull_file(device_file, host_file) context.add_iteration_artifact(label, kind='raw', path=host_relpath) with open(host_file) as fh: in_results_section = False for line in fh: if 'Performance counter stats' in line: in_results_section = True fh.next() # skip the following blank line if in_results_section: if not line.strip(): # blank line in_results_section = False break else: line = line.split('#')[0] # comment match = PERF_COUNT_REGEX.search(line) if match: classifiers = {} cpu = match.group(1) if cpu is not None: classifiers['cpu'] = int(cpu.replace('CPU', '')) count = int(match.group(2)) metric = '{}_{}'.format(label, match.group(3)) context.result.add_metric(metric, count, classifiers=classifiers)
def create_uiauto_project(path, name, target='1'): sdk_path = get_sdk_path() android_path = os.path.join(sdk_path, 'tools', 'android') package_name = 'com.arm.wlauto.uiauto.' + name.lower() # ${ANDROID_HOME}/tools/android create uitest-project -n com.arm.wlauto.uiauto.linpack -t 1 -p ../test2 command = '{} create uitest-project --name {} --target {} --path {}'.format( android_path, package_name, target, path) check_output(command, shell=True) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: template = string.Template(UIAUTO_BUILD_SCRIPT) wfh.write(template.substitute({'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f( os.path.join(path, 'src', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write( render_template('UiAutomation.java', { 'name': name, 'package_name': package_name }))
def update_result(self, context): for label in self.labels: device_file = self._get_device_outfile(label) host_relpath = os.path.join('perf', os.path.basename(device_file)) host_file = _f(os.path.join(context.output_directory, host_relpath)) self.device.pull_file(device_file, host_file) context.add_iteration_artifact(label, kind='raw', path=host_relpath) with open(host_file) as fh: in_results_section = False for line in fh: if 'Performance counter stats' in line: in_results_section = True fh.next() # skip the following blank line if in_results_section: if not line.strip(): # blank line in_results_section = False break else: line = line.split('#')[0] # comment match = PERF_COUNT_REGEX.search(line) if match: count = int(match.group(1)) metric = '{}_{}'.format(label, match.group(2)) context.result.add_metric(metric, count)
def get(self, resource, **kwargs): force = kwargs.get('force') remote_path = os.path.join(self.mount_point, self.relative_path, resource.path) local_path = _f(os.path.join(settings.dependencies_directory, '__remote', resource.owner.name, os.path.basename(resource.path))) if not os.path.exists(local_path) or force: if not os.path.exists(remote_path): return None self.logger.debug('Copying {} to {}'.format(remote_path, local_path)) shutil.copy(remote_path, local_path) return local_path
def _diff_sysfs_dirs(before, after, result): # pylint: disable=R0914 before_files = [] os.path.walk( before, lambda arg, dirname, names: arg.extend( [os.path.join(dirname, f) for f in names]), before_files) before_files = filter(os.path.isfile, before_files) files = [os.path.relpath(f, before) for f in before_files] after_files = [os.path.join(after, f) for f in files] diff_files = [os.path.join(result, f) for f in files] for bfile, afile, dfile in zip(before_files, after_files, diff_files): if not os.path.isfile(afile): logger.debug( 'sysfs_diff: {} does not exist or is not a file'.format(afile)) continue with open(bfile) as bfh, open(afile) as afh: # pylint: disable=C0321 with open(_f(dfile), 'w') as dfh: for i, (bline, aline) in enumerate(izip_longest(bfh, afh), 1): if aline is None: logger.debug('Lines missing from {}'.format(afile)) break bchunks = re.split(r'(\W+)', bline) achunks = re.split(r'(\W+)', aline) if len(bchunks) != len(achunks): logger.debug( 'Token length mismatch in {} on line {}'.format( bfile, i)) dfh.write('xxx ' + bline) continue if ((len([c for c in bchunks if c.strip()]) == len( [c for c in achunks if c.strip()]) == 2) and (bchunks[0] == achunks[0])): # if there are only two columns and the first column is the # same, assume it's a "header" column and do not diff it. dchunks = [bchunks[0]] + [ diff_tokens(b, a) for b, a in zip(bchunks[1:], achunks[1:]) ] else: dchunks = [ diff_tokens(b, a) for b, a in zip(bchunks, achunks) ] dfh.write(''.join(dchunks))
def download_asset(self, asset, owner_name): url = urljoin(self.url, owner_name, asset['path']) local_path = _f(os.path.join(settings.dependencies_directory, '__remote', owner_name, asset['path'].replace('/', os.sep))) if os.path.isfile(local_path) and not self.always_fetch: local_sha = sha256(local_path) if local_sha == asset['sha256']: self.logger.debug('Local SHA256 matches; not re-downloading') return local_path self.logger.debug('Downloading {}'.format(url)) response = self.geturl(url, stream=True) if response.status_code != httplib.OK: message = 'Could not download asset "{}"; recieved "{} {}"' self.logger.warning(message.format(url, response.status_code, response.reason)) return with open(local_path, 'wb') as wfh: for chunk in response.iter_content(chunk_size=self.chunk_size): wfh.write(chunk) return local_path
def create_uiauto_project(path, name, target='1'): sdk_path = get_sdk_path() android_path = os.path.join(sdk_path, 'tools', 'android') package_name = 'com.arm.wlauto.uiauto.' + name.lower() # ${ANDROID_HOME}/tools/android create uitest-project -n com.arm.wlauto.uiauto.linpack -t 1 -p ../test2 command = '{} create uitest-project --name {} --target {} --path {}'.format(android_path, package_name, target, path) check_output(command, shell=True) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: template = string.Template(UIAUTO_BUILD_SCRIPT) wfh.write(template.substitute({'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f(os.path.join(path, 'src', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write(render_template('UiAutomation.java', {'name': name, 'package_name': package_name}))
def _diff_sysfs_dirs(before, after, result): # pylint: disable=R0914 before_files = [] os.path.walk(before, lambda arg, dirname, names: arg.extend([os.path.join(dirname, f) for f in names]), before_files ) before_files = filter(os.path.isfile, before_files) files = [os.path.relpath(f, before) for f in before_files] after_files = [os.path.join(after, f) for f in files] diff_files = [os.path.join(result, f) for f in files] for bfile, afile, dfile in zip(before_files, after_files, diff_files): if not os.path.isfile(afile): logger.debug('sysfs_diff: {} does not exist or is not a file'.format(afile)) continue with open(bfile) as bfh, open(afile) as afh: # pylint: disable=C0321 with open(_f(dfile), 'w') as dfh: for i, (bline, aline) in enumerate(izip_longest(bfh, afh), 1): if aline is None: logger.debug('Lines missing from {}'.format(afile)) break bchunks = re.split(r'(\W+)', bline) achunks = re.split(r'(\W+)', aline) if len(bchunks) != len(achunks): logger.debug('Token length mismatch in {} on line {}'.format(bfile, i)) dfh.write('xxx ' + bline) continue if ((len([c for c in bchunks if c.strip()]) == len([c for c in achunks if c.strip()]) == 2) and (bchunks[0] == achunks[0])): # if there are only two columns and the first column is the # same, assume it's a "header" column and do not diff it. dchunks = [bchunks[0]] + [diff_tokens(b, a) for b, a in zip(bchunks[1:], achunks[1:])] else: dchunks = [diff_tokens(b, a) for b, a in zip(bchunks, achunks)] dfh.write(''.join(dchunks))
def create_uiauto_project(path, name): package_name = 'com.arm.wlauto.uiauto.' + name.lower() shutil.copytree(os.path.join(TEMPLATES_DIR, 'uiauto_template'), path) manifest_path = os.path.join(path, 'app', 'src', 'main') mainifest = os.path.join(_d(manifest_path), 'AndroidManifest.xml') with open(mainifest, 'w') as wfh: wfh.write( render_template('uiauto_AndroidManifest.xml', {'package_name': package_name})) build_gradle_path = os.path.join(path, 'app') build_gradle = os.path.join(_d(build_gradle_path), 'build.gradle') with open(build_gradle, 'w') as wfh: wfh.write( render_template('uiauto_build.gradle', {'package_name': package_name})) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: wfh.write( render_template('uiauto_build_script', {'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f( os.path.join(path, 'app', 'src', 'main', 'java', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write( render_template('UiAutomation.java', { 'name': name, 'package_name': package_name }))
def start(self, context): with open(_f(self.before_file), 'w') as wfh: wfh.write(self.device.execute('cat /proc/interrupts'))
def setup(self, context): self.capture_file = _f(os.path.join(context.output_directory, 'streamline', 'capture.apc')) self.report_file = _f(os.path.join(context.output_directory, 'streamline', 'streamline.csv'))
def update_result(self, context): # If workload execution failed, the after_file may not have been created. if os.path.isfile(self.after_file): _diff_interrupt_files(self.before_file, self.after_file, _f(self.diff_file))
def stop(self, context): with open(_f(self.after_file), 'w') as wfh: wfh.write(self.device.execute('cat /proc/interrupts'))
def setup(self, context): if self.loglevel: self.old_loglevel = self.device.get_sysfile_value(self.loglevel_file) self.device.set_sysfile_value(self.loglevel_file, self.loglevel, verify=False) self.before_file = _f(os.path.join(context.output_directory, 'dmesg', 'before')) self.after_file = _f(os.path.join(context.output_directory, 'dmesg', 'after'))