tests: Replay profile frame times
[piglit.git] / framework / replay / programs / profile.py
blob2d5b6e289264aa388c8f6ae2ea10f2a4a376d8c3
1 # coding=utf-8
3 # Copyright © 2020 Valve Corporation.
4 # Copyright © 2021 Collabora Ltd.
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 # OTHER DEALINGS IN THE SOFTWARE.
24 # SPDX-License-Identifier: MIT
26 import argparse
28 from framework import exceptions
29 from framework.replay import frame_times
30 from framework.replay import options
31 from framework.programs import parsers as piglit_parsers
32 from . import parsers
34 __all__ = ['profile']
37 def _from_yaml(args):
38 options.OPTIONS.device_name = args.device_name
39 options.OPTIONS.download['force'] = args.force_download
40 options.OPTIONS.download['minio_host'] = args.download_minio_host
41 options.OPTIONS.download['minio_bucket'] = args.download_minio_bucket
42 options.OPTIONS.download['role_session_name'] = args.download_role_session_name
43 options.OPTIONS.download['jwt'] = args.download_jwt
44 options.OPTIONS.db_path = args.db_path
45 options.OPTIONS.results_path = args.output
47 return frame_times.from_yaml(args.yaml_file)
50 def _trace(args):
51 options.OPTIONS.device_name = args.device_name
52 options.OPTIONS.set_download_url(args.download_url)
53 options.OPTIONS.download['force'] = args.force_download
54 options.OPTIONS.download['minio_host'] = args.download_minio_host
55 options.OPTIONS.download['minio_bucket'] = args.download_minio_bucket
56 options.OPTIONS.download['role_session_name'] = args.download_role_session_name
57 options.OPTIONS.download['jwt'] = args.download_jwt
58 options.OPTIONS.db_path = args.db_path
59 options.OPTIONS.results_path = args.output
61 return frame_times.trace(args.file_path)
64 @exceptions.handler
65 def profile(input_):
66 """ Parser for replayer compare command """
67 unparsed = piglit_parsers.parse_config(input_)[1]
69 try:
70 # Set the parent of the config to add the -f/--config message
71 parser = argparse.ArgumentParser(parents=[piglit_parsers.CONFIG])
72 # The "required" keyword is only available since python >= 3.7
73 subparsers = parser.add_subparsers(dest='command', required=True)
74 except TypeError:
75 parser = argparse.ArgumentParser(parents=[piglit_parsers.CONFIG])
76 # Add a destination due to
77 # https://github.com/python/cpython/pull/3027#issuecomment-330910633
78 subparsers = parser.add_subparsers(dest='command')
80 parser_trace = subparsers.add_parser(
81 'trace',
82 parents=[parsers.DEVICE,
83 parsers.DOWNLOAD_URL,
84 parsers.DOWNLOAD_FORCE,
85 parsers.DOWNLOAD_MINIO_HOST,
86 parsers.DOWNLOAD_MINIO_BUCKET,
87 parsers.DOWNLOAD_ROLE_SESSION_NAME,
88 parsers.DOWNLOAD_JWT,
89 parsers.DB_PATH,
90 parsers.RESULTS_PATH],
91 help=('Profiles specific trace given a device.'))
92 parser_trace.add_argument(
93 'file_path',
94 help=('the relative path to the trace file inside the db path. '
95 'If not present and given that an URL has been provided '
96 'for its download, the relative path to the file in such URL.'))
97 parser_trace.set_defaults(func=_trace)
99 parser_yaml = subparsers.add_parser(
100 'yaml',
101 parents=[parsers.DEVICE,
102 parsers.YAML,
103 parsers.DOWNLOAD_FORCE,
104 parsers.DOWNLOAD_MINIO_HOST,
105 parsers.DOWNLOAD_MINIO_BUCKET,
106 parsers.DOWNLOAD_ROLE_SESSION_NAME,
107 parsers.DOWNLOAD_JWT,
108 parsers.DB_PATH,
109 parsers.RESULTS_PATH],
110 help=('Profiles from a traces description file listing traces.'))
111 parser_yaml.set_defaults(func=_from_yaml)
113 args = parser.parse_args(unparsed)
115 return args.func(args)