From 62626826f2943549de73b560748138e799ca52f8 Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Thu, 27 Jun 2024 17:22:13 +0200 Subject: [PATCH] Add basic benchmarking standard support --- external/tracetooltests | 2 +- scripts/lava-capture.py | 45 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/external/tracetooltests b/external/tracetooltests index cbb85a3..3715c19 160000 --- a/external/tracetooltests +++ b/external/tracetooltests @@ -1 +1 @@ -Subproject commit cbb85a3c4e2b06ba36195e21a7991fcd73a65e8d +Subproject commit 3715c19991f946e5956356cf58888ad4a0aeebbc diff --git a/scripts/lava-capture.py b/scripts/lava-capture.py index 5499897..63ac677 100755 --- a/scripts/lava-capture.py +++ b/scripts/lava-capture.py @@ -7,6 +7,7 @@ import sys import argparse import subprocess +import json def args(): parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]), description='Trace a Vulkan application', allow_abbrev=False) @@ -20,9 +21,50 @@ def args(): parser.add_argument('--dedicated-image', dest='dedimg', action='store_true', help='Request dedicated memory allocation for images') parser.add_argument('--delayfence', dest='delayfence', metavar='', help='Delay successful fence waits the given number of times') parser.add_argument('--gpu', dest='gpu', metavar='', help='Use the specified GPU for tracing') + parser.add_argument('--automate', dest='automate', action='store_true', help='Try to automate the run as much as possible if app supports CBS') parser.add_argument('programAndArgs', metavar=' []', nargs=argparse.REMAINDER, help='Application to capture and any program arguments') return parser +# See https://github.com/ARM-software/tracetooltests/blob/main/doc/BenchmarkingStandard.md for details +def DetectCBS(args): + program = args.programAndArgs[0] + tail, base = os.path.split(program) + cap_file = None + if program.startswith('/usr/bin/'): + cap_file = '/usr/share/benchmarking/' + base + ".bench" + else: + cap_file = program + '.bench' + + if not cap_file or not os.path.exists(cap_file): + print('No capabilities file found') # TBD remove too spammy + return # No capabilities file + + if not os.path.isfile(cap_file) or not os.access(cap_file, os.R_OK): + print('Capabilities file %s is not a readable' % cap_file) + return + + if 'BENCHMARKING_ENABLE_JSON' in os.environ or 'BENCHMARKING_ENABLE_PATH' in os.environ: + print('Existing benchmarking environment found - not overwriting') + return + + cap_fp = open(cap_file, 'r') # should always load now + cap_data = json.load(cap_fp) + if not cap_data: + print('%s is not a valid JSON file' % cap_file) + return + + enable_file = {} + enable_file['target'] = base + if 'capabilities' in cap_data and args.automate: + if 'non_interactive' in cap_data['capabilities'] and cap_data['capabilities']['non_interactive'] == 'option': + enable_file['capabilities'] = { 'non_interactive': true } + if 'fixed_framerate' in cap_data['capabilities'] and cap_data['capabilities']['fixed_framerate'] == 'option': + enable_file['capabilities'] = { 'fixed_framerate': 0 } + if 'gpu_frame_deterministic' in cap_data['capabilities'] and cap_data['capabilities']['gpu_frame_deterministic'] == 'option': + enable_file['capabilities'] = { 'gpu_frame_deterministic': true } + + os.environ['BENCHMARKING_ENABLE_JSON'] = json.dumps(enable_file, sort_keys=True, separators=(',', ':')) + def PrintEnvVar(envVar): if envVar in os.environ: print((envVar, os.environ[envVar])) @@ -46,6 +88,8 @@ def PrintEnvVar(envVar): parser.print_help() sys.exit(0) + DetectCBS(args) + PrintEnvVar('LAVATUBE_DESTINATION') PrintEnvVar('LAVATUBE_DEBUG') PrintEnvVar('LAVATUBE_DEBUG_FILE') @@ -55,6 +99,7 @@ def PrintEnvVar(envVar): PrintEnvVar('LAVATUBE_DEDICATED_BUFFER') PrintEnvVar('LAVATUBE_DEDICATED_IMAGE') PrintEnvVar('LAVATUBE_DELAY_FENCE_SUCCESS_FRAMES') + PrintEnvVar('BENCHMARKING_ENABLE_JSON') if args.gdb: result = subprocess.run(['gdb', '-q', '-ex', 'run', '--args'] + args.programAndArgs)