cfa16cbe2f
* adding perfetto-validation-script * Rename validation script * Update tests/validate_perfetto.py Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> * Update tests/validate_perfetto.py Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> * Update tests/validate_perfetto.py Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> * Update tests/validate_perfetto.py Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> * addressed the edits in the validation script * addressed the edits in the validation script * Perfetto validation script (#1) * Fixed mismatch message in validate-timemory-json * validate_perfetto.py -> validate-perfetto-proto.py * Add python-source-validate-perfetto - python-source-validate-perfetto uses validate-python-proto.py to validate perfetto output - renamed python-source-check test to python-source-validate timemory * Moved python-source-validate tests outside of cat command if block - these tests don't rely on OMNITRACE_CAT_COMMAND * CMake/CTest OMNITRACE_ADD_PYTHON_VALIDATION_TEST function - generalized function for performing validation test with validate-{timemory-json,perfetto-proto}.py scripts * Print perfetto validation * Install perfetto python package in workflows * cmake format * Python formatting * Python formatting CI * Install perfetto python package in workflows * Install dataclasses for perfetto in opensuse * Install dataclasses for perfetto in ubuntu - uninstalled dependency for perfetto in Python 3.6 Co-authored-by: Jonathan R. Madsen <jrmadsen@users.noreply.github.com> Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
70 行
2.2 KiB
Python
実行ファイル
70 行
2.2 KiB
Python
実行ファイル
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import json
|
|
import argparse
|
|
|
|
|
|
def validate_json(data, labels, counts, depths):
|
|
expected = []
|
|
for litr, citr, ditr in zip(labels, counts, depths):
|
|
entry = []
|
|
_label = litr
|
|
if ditr > 0:
|
|
_label = "{}|_{}".format(" " * (ditr - 1), litr)
|
|
entry = [_label, citr, ditr]
|
|
expected.append(entry)
|
|
|
|
for ditr, eitr in zip(data, expected):
|
|
_prefix = ditr["prefix"]
|
|
_depth = ditr["depth"]
|
|
_count = ditr["entry"]["laps"]
|
|
_idx = _prefix.find(">>>")
|
|
if _idx is not None:
|
|
_prefix = _prefix[(_idx + 4) :]
|
|
if _prefix != eitr[0]:
|
|
raise RuntimeError(f"Mismatched prefix: {_prefix} vs. {eitr[0]}")
|
|
if _count != eitr[1]:
|
|
raise RuntimeError(f"Mismatched count: {_count} vs. {eitr[1]}")
|
|
if _depth != eitr[2]:
|
|
raise RuntimeError(f"Mismatched depth: {_depth} vs. {eitr[2]}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("-m", "--metric", type=str, help="JSON metric", required=True)
|
|
parser.add_argument(
|
|
"-l", "--labels", nargs="+", type=str, help="Expected labels", default=[]
|
|
)
|
|
parser.add_argument(
|
|
"-c", "--counts", nargs="+", type=int, help="Expected counts", default=[]
|
|
)
|
|
parser.add_argument(
|
|
"-d", "--depths", nargs="+", type=int, help="Expected depths", default=[]
|
|
)
|
|
parser.add_argument("-i", "--input", type=str, help="Input file", required=True)
|
|
|
|
args = parser.parse_args()
|
|
|
|
if len(args.labels) != len(args.counts) or len(args.labels) != len(args.depths):
|
|
raise RuntimeError(
|
|
"The same number of labels, counts, and depths must be specified"
|
|
)
|
|
|
|
ret = 0
|
|
with open(args.input) as f:
|
|
data = json.load(f)
|
|
try:
|
|
validate_json(
|
|
data["timemory"][args.metric]["ranks"][0]["graph"],
|
|
args.labels,
|
|
args.counts,
|
|
args.depths,
|
|
)
|
|
except RuntimeError as e:
|
|
print(f"{e}")
|
|
ret = 1
|
|
if ret == 0:
|
|
print(f"{args.input} validated")
|
|
sys.exit(ret)
|