Commit 05c40dff authored by Alexandros Frantzis's avatar Alexandros Frantzis

scripts: Support dumping trace images by trace type

Add the --trace-types argument to to allow
dumping images only from a subset of the traces, based on their type.
Signed-off-by: Alexandros Frantzis's avatarAlexandros Frantzis <>
parent dbd339a5
......@@ -28,7 +28,8 @@ import sys
import subprocess
from pathlib import Path
from renderdoc_dump_images import renderdoc_dump_images
from traceutil import iter_trace_paths, trace_has_images
from traceutil import iter_trace_paths, trace_has_images, all_trace_type_names
from traceutil import trace_type_from_name, trace_type_from_filename, TraceType
def log(severity, msg):
print("[dump_images] %s: %s" % (severity, msg))
......@@ -61,16 +62,17 @@ def dump_with_renderdoc(trace, calls, device_name):
def dump_from_trace(trace, device_name):
log("Info", "Dumping trace %s" % trace)
calls = get_calls_num(trace, device_name)
if trace.endswith('.trace'):
trace_type = trace_type_from_filename(trace)
if trace_type == TraceType.APITRACE:
dump_with_apitrace(trace, calls, device_name)
elif trace.endswith('.rdc'):
elif trace_type == TraceType.RENDERDOC:
dump_with_renderdoc(trace, calls, device_name)
raise RuntimeError("Unknown tracefile extension")
def find_traces_with_reference_images(directory, device_name):
def find_traces_with_reference_images(directory, device_name, trace_types):
traces = []
for trace_path in iter_trace_paths(directory):
for trace_path in iter_trace_paths(directory, trace_types):
if trace_has_images(trace_path, str(Path("references") / device_name)):
log("Info", "Adding %s in list of traces to dump" % str(trace_path))
......@@ -83,12 +85,19 @@ def main():
parser.add_argument('tracepath', help="single trace or dir to walk recursively")
parser.add_argument('--device-name', required=True,
help="the name of the graphics device used to produce images")
parser.add_argument('--trace-types', required=False,
help="the types of traces to look for in recursive dir walks "
"(by default all types)")
args = parser.parse_args()
trace_types = [trace_type_from_name(t) for t in args.trace_types.split(",")]
traces = []
if os.path.isdir(args.tracepath):
traces.extend(find_traces_with_reference_images(args.tracepath, args.device_name))
elif os.path.isfile(args.tracepath):
......@@ -22,11 +22,44 @@
import os
from pathlib import Path
from enum import Enum, auto
def iter_trace_paths(directory):
class TraceType(Enum):
UNKNOWN = auto()
APITRACE = auto()
RENDERDOC = auto()
_trace_type_info_map = {
TraceType.APITRACE : ("apitrace", ".trace"),
TraceType.RENDERDOC : ("renderdoc", ".rdc")
def all_trace_type_names():
s = []
for t,(name, ext) in _trace_type_info_map.items():
if t != TraceType.UNKNOWN:
return s
def trace_type_from_name(tt_name):
for t,(name, ext) in _trace_type_info_map.items():
if tt_name == name:
return t
return TraceType.UNKNOWN
def trace_type_from_filename(trace_file):
for t,(name, ext) in _trace_type_info_map.items():
if trace_file.endswith(ext):
return t
return TraceType.UNKNOWN
def iter_trace_paths(directory, trace_types=[TraceType.APITRACE, TraceType.RENDERDOC]):
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".trace") or file.endswith(".rdc"):
trace_type = trace_type_from_filename(file)
if trace_type in trace_types:
yield Path(root) / file
def trace_has_images(trace_path, imagedir):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment