adding perfetto-validation-script (#66)
* 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>
This commit is contained in:
committad av
GitHub
förälder
be7b03e76f
incheckning
cfa16cbe2f
+63
-13
@@ -964,24 +964,74 @@ foreach(_VERSION ${OMNITRACE_PYTHON_VERSIONS})
|
||||
PASS_REGEX "\\\[inefficient\\\]\\\[builtin.py:14\\\]"
|
||||
DEPENDS python-builtin-${_VERSION}
|
||||
ENVIRONMENT "${_python_environment}")
|
||||
|
||||
omnitrace_add_python_test(
|
||||
NAME python-source-check
|
||||
COMMAND
|
||||
${_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/validate-timemory-json.py
|
||||
-l run fib fib fib fib fib inefficient _sum -c 5 5 10 20 30 10 5 5 -d 0 1
|
||||
2 3 4 5 1 2 -m trip_count -i
|
||||
PYTHON_VERSION ${_VERSION}
|
||||
FILE omnitrace-tests-output/python-source/${_VERSION}/trip_count.json
|
||||
DEPENDS python-source-${_VERSION}
|
||||
PASS_REGEX
|
||||
"omnitrace-tests-output/python-source/${_VERSION}/trip_count.json validated"
|
||||
ENVIRONMENT "${_python_environment}")
|
||||
else()
|
||||
omnitrace_message(
|
||||
WARNING
|
||||
"Neither 'cat' nor 'cmake -E cat' are available. Python source checks are disabled"
|
||||
)
|
||||
endif()
|
||||
|
||||
function(OMNITRACE_ADD_PYTHON_VALIDATION_TEST)
|
||||
cmake_parse_arguments(TEST "" "NAME;TIMEMORY_METRIC;TIMEMORY_FILE;PERFETTO_FILE"
|
||||
"ARGS" ${ARGN})
|
||||
|
||||
omnitrace_add_python_test(
|
||||
NAME ${TEST_NAME}-validate-timemory
|
||||
COMMAND
|
||||
${_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/validate-timemory-json.py
|
||||
-m ${TEST_TIMEMORY_METRIC} ${TEST_ARGS} -i
|
||||
PYTHON_VERSION ${_VERSION}
|
||||
FILE omnitrace-tests-output/${TEST_NAME}/${_VERSION}/${TEST_TIMEMORY_FILE}
|
||||
DEPENDS ${TEST_NAME}-${_VERSION}
|
||||
PASS_REGEX
|
||||
"omnitrace-tests-output/${TEST_NAME}/${_VERSION}/${TEST_TIMEMORY_FILE} validated"
|
||||
ENVIRONMENT "${_python_environment}")
|
||||
|
||||
omnitrace_add_python_test(
|
||||
NAME ${TEST_NAME}-validate-perfetto
|
||||
COMMAND
|
||||
${_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/validate-perfetto-proto.py
|
||||
${TEST_ARGS} -p -i
|
||||
PYTHON_VERSION ${_VERSION}
|
||||
FILE omnitrace-tests-output/${TEST_NAME}/${_VERSION}/${TEST_PERFETTO_FILE}
|
||||
DEPENDS ${TEST_NAME}-${_VERSION}
|
||||
PASS_REGEX
|
||||
"omnitrace-tests-output/${TEST_NAME}/${_VERSION}/${TEST_PERFETTO_FILE} validated"
|
||||
ENVIRONMENT "${_python_environment}")
|
||||
endfunction()
|
||||
|
||||
omnitrace_add_python_validation_test(
|
||||
NAME python-source
|
||||
TIMEMORY_METRIC "trip_count"
|
||||
TIMEMORY_FILE "trip_count.json"
|
||||
PERFETTO_FILE "perfetto-trace.proto"
|
||||
ARGS -l
|
||||
run
|
||||
fib
|
||||
fib
|
||||
fib
|
||||
fib
|
||||
fib
|
||||
inefficient
|
||||
_sum
|
||||
-c
|
||||
5
|
||||
5
|
||||
10
|
||||
20
|
||||
30
|
||||
10
|
||||
5
|
||||
5
|
||||
-d
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
1
|
||||
2)
|
||||
|
||||
math(EXPR _INDEX "${_INDEX} + 1")
|
||||
endforeach()
|
||||
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import argparse
|
||||
from perfetto.trace_processor import TraceProcessor
|
||||
|
||||
|
||||
def validate_perfetto(data, labels, counts, depths):
|
||||
expected = []
|
||||
for litr, citr, ditr in zip(labels, counts, depths):
|
||||
entry = []
|
||||
_label = litr
|
||||
if ditr > 0:
|
||||
_label = "{}".format(litr)
|
||||
entry = [_label, citr, ditr]
|
||||
expected.append(entry)
|
||||
|
||||
for ditr, eitr in zip(data, expected):
|
||||
_label = ditr["label"]
|
||||
_count = ditr["count"]
|
||||
_depth = ditr["depth"]
|
||||
|
||||
if _label != eitr[0]:
|
||||
raise RuntimeError(f"Mismatched prefix: {_label} 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(
|
||||
"-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(
|
||||
"-p", "--print", action="store_true", help="Print the processed perfetto data"
|
||||
)
|
||||
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"
|
||||
)
|
||||
|
||||
tp = TraceProcessor(trace=(args.input))
|
||||
pdata = {}
|
||||
# get data from perfetto
|
||||
qr_it = tp.query("SELECT name, depth FROM slice")
|
||||
# loop over data rows from perfetto
|
||||
for row in qr_it:
|
||||
if row.name not in pdata:
|
||||
pdata[row.name] = {}
|
||||
if row.depth not in pdata[row.name]:
|
||||
pdata[row.name][row.depth] = 0
|
||||
# accumulate the call-count per name and per depth
|
||||
pdata[row.name][row.depth] += 1
|
||||
|
||||
perfetto_data = []
|
||||
for name, itr in pdata.items():
|
||||
for depth, count in itr.items():
|
||||
_e = {}
|
||||
_e["label"] = name
|
||||
_e["count"] = count
|
||||
_e["depth"] = depth
|
||||
perfetto_data.append(_e)
|
||||
|
||||
# demo display of data
|
||||
if args.print:
|
||||
for itr in perfetto_data:
|
||||
n = 0 if itr["depth"] < 2 else itr["depth"] - 1
|
||||
lbl = "{}{}{}".format(
|
||||
" " * n, "|_" if itr["depth"] > 0 else "", itr["label"]
|
||||
)
|
||||
print("| {:40} | {:6} | {:6} |".format(lbl, itr["count"], itr["depth"]))
|
||||
|
||||
ret = 0
|
||||
try:
|
||||
validate_perfetto(
|
||||
perfetto_data,
|
||||
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)
|
||||
@@ -25,7 +25,7 @@ def validate_json(data, labels, counts, depths):
|
||||
if _prefix != eitr[0]:
|
||||
raise RuntimeError(f"Mismatched prefix: {_prefix} vs. {eitr[0]}")
|
||||
if _count != eitr[1]:
|
||||
raise RuntimeError(f"Mismatched depth: {_depth} vs. {eitr[2]}")
|
||||
raise RuntimeError(f"Mismatched count: {_count} vs. {eitr[1]}")
|
||||
if _depth != eitr[2]:
|
||||
raise RuntimeError(f"Mismatched depth: {_depth} vs. {eitr[2]}")
|
||||
|
||||
|
||||
Referens i nytt ärende
Block a user