Adding --collection-period feature in rocprofv3 to match v1/v2 parity (#9)

* Adding Trace Period feature to rocprofv3

* Adding feature documentation

* Update source/bin/rocprofv3.py

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fixing format

* Moving to Collection Period and changing the input params

* Format Fixes

* Fixing rebasing issues

* Removing atomic include from the tool

* Adding more options for units, optimizing the code

* Fixing rocprofv3.py

* Fixing time conv & adding time controlled app

* Fixing format

* Changing to shared memory testing methodology

* use of shmem use

* Fix include headers for transpose-time-controlled.cpp

* Format upload-image-to-github.py

* Removing shmem and using only env var to dump timestamps from the tool

* Tool Fixes + Test Config

* Adding Tests

* Fixing Review comments

* Update trace period implementation

* Update trace period tests

* check between start and stop timestamps

* Merge Fix

* Update validate.py

* Improve safety of rocprofiler_stop_context after finalization

* Pass context id to collection_period_cntrl by value

* Adding 20 us error margin

* Ensure log level for collection-period test is not more than warning

---------

Co-authored-by: Ammar ELWazir <aelwazir@amd.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
This commit is contained in:
Elwazir, Ammar
2024-12-05 20:17:24 -06:00
committed by GitHub
parent e7d45624d0
commit a579c70b71
15 changed files with 429 additions and 22 deletions
@@ -78,7 +78,6 @@ class OTF2Reader:
self.filename = filename if isinstance(filename, (list, tuple)) else [filename]
def read(self):
def _read_trace(trace_name):
trace = otf2.reader.Reader(trace_name)
# print(f"Read {len(trace.definitions.strings)} string definitions")
-1
View File
@@ -56,7 +56,6 @@ def test_perfetto_data(
def test_otf2_data(
otf2_data, json_data, categories=("hip", "hsa", "marker", "kernel", "memory_copy")
):
def get_operation_name(kind_id, op_id):
return json_data["rocprofiler-sdk-tool"]["strings"]["buffer_records"][kind_id][
"operations"
+1
View File
@@ -35,3 +35,4 @@ add_subdirectory(summary)
add_subdirectory(roctracer-roctx)
add_subdirectory(scratch-memory)
add_subdirectory(pc-sampling)
add_subdirectory(trace-period)
@@ -0,0 +1,67 @@
#
# rocprofv3 tool tests for collection period
#
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
project(
rocprofiler-tests-rocprofv3-collection-period
LANGUAGES CXX
VERSION 0.0.0)
find_package(rocprofiler-sdk REQUIRED)
string(REPLACE "LD_PRELOAD=" "ROCPROF_PRELOAD=" PRELOAD_ENV
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}")
set(collection-period-env "${PRELOAD_ENV}" ROCPROF_COLLECTION_PERIOD_TESTING=true)
rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY validate.py conftest.py)
##########################################################################################
#
# Command line input
#
##########################################################################################
add_test(
NAME rocprofv3-test-collection-period-execute
COMMAND
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> --runtime-trace --summary -d
${CMAKE_CURRENT_BINARY_DIR}/collection-period -o out --output-format csv json
pftrace otf2 --log-level warning --collection-period 0:1:1 1:1:2 0.5:0.5:0
--collection-period-unit sec -- $<TARGET_FILE:reproducible-runtime> 5000 4)
set_tests_properties(
rocprofv3-test-collection-period-execute
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT
"${collection-period-env}" FAIL_REGULAR_EXPRESSION
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
add_test(
NAME rocprofv3-test-collection-period-validate
COMMAND
${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --json-input
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.json --pftrace-input
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.pftrace --otf2-input
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.otf2
--collection-period-input
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_collection_periods.log)
set(VALIDATION_FILES
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.json
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_collection_periods.log
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.pftrace
${CMAKE_CURRENT_BINARY_DIR}/collection-period/out_results.otf2)
set_tests_properties(
rocprofv3-test-collection-period-validate
PROPERTIES TIMEOUT
45
LABELS
"integration-tests"
DEPENDS
"rocprofv3-test-collection-period-execute"
FAIL_REGULAR_EXPRESSION
"AssertionError"
ATTACHED_FILES_ON_FAIL
"${VALIDATION_FILES}")
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env python3
import pytest
import json
import os
from rocprofiler_sdk.pytest_utils.dotdict import dotdict
from rocprofiler_sdk.pytest_utils import collapse_dict_list
from rocprofiler_sdk.pytest_utils.perfetto_reader import PerfettoReader
from rocprofiler_sdk.pytest_utils.otf2_reader import OTF2Reader
def pytest_addoption(parser):
parser.addoption(
"--json-input",
action="store",
help="Path to JSON file.",
)
parser.addoption(
"--collection-period-input",
action="store",
help="Path to OUTPUT Timestamps file.",
)
parser.addoption(
"--pftrace-input",
action="store",
help="Path to Perfetto trace file.",
)
parser.addoption(
"--otf2-input",
action="store",
help="Path to OTF2 trace file.",
)
@pytest.fixture
def json_data(request):
filename = request.config.getoption("--json-input")
with open(filename, "r") as inp:
return dotdict(collapse_dict_list(json.load(inp)))
@pytest.fixture
def collection_period_data(request):
filename = request.config.getoption("--collection-period-input")
with open(filename, "r") as inp:
data = inp.read()
# Split the content by '--'
sections = [section.strip() for section in data.split("--") if section.strip()]
result = []
for section in sections:
section_data = {}
for line in section.splitlines():
label, start, stop = [itr.strip() for itr in line.split(":")]
section_data[label] = {"start": int(start), "stop": int(stop)}
if section_data:
result += [dotdict(section_data)]
return result
@pytest.fixture
def pftrace_data(request):
filename = request.config.getoption("--pftrace-input")
return PerfettoReader(filename).read()[0]
@pytest.fixture
def otf2_data(request):
filename = request.config.getoption("--otf2-input")
if not os.path.exists(filename):
raise FileExistsError(f"{filename} does not exist")
return OTF2Reader(filename).read()[0]
+5
View File
@@ -0,0 +1,5 @@
[pytest]
addopts = --durations=20 -rA -s -vv
testpaths = validate.py
pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages
+92
View File
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
import re
import sys
import pytest
import json
class TimeWindow(object):
def __init__(self, beg, end):
self.offset = beg
self.duration = end - beg
def in_region(self, val):
return val >= self.offset and val <= (self.offset + self.duration)
def __repr__(self):
return f"[{self.offset}:{self.offset+self.duration}]"
def check_traces(data, valid_regions, invalid_regions, corrid_records=None):
for record in data:
corr_id = record.correlation_id.internal
rval = (
corrid_records[corr_id]
if corrid_records is not None and corr_id in corrid_records
else record
)
valid = [itr for itr in valid_regions if itr.in_region(rval.start_timestamp)]
assert (
len(valid) == 1
), f"\nrval:\n\t{rval}\nrecord:\n\t{record}\nnot found in valid regions:\n{valid_regions}"
invalid = [itr for itr in invalid_regions if itr.in_region(rval.start_timestamp)]
assert (
len(invalid) == 0
), f"\nrval:\n\t{rval}\nrecord:\n\t{record}\nfound in invalid region(s):\n{invalid}"
def test_collection_period_trace(json_data, collection_period_data):
# Adding 20 us error margin to handle the time taken for the start/stop context to affect the collection
time_error_margin = 20 * 1e4
valid_regions = []
invalid_regions = []
for period in collection_period_data:
_start = None
_stop = None
if "start" in period.keys():
_start = period.start.start - time_error_margin
if "stop" in period.keys():
_stop = period.stop.stop + time_error_margin
if _start and _stop:
valid_regions.append(TimeWindow(_start, _stop))
elif "duration" in period.keys():
valid_regions.append(TimeWindow(period.duration.start, period.duration.stop))
elif _start and not _stop:
valid_regions.append(TimeWindow(_start, _start + 10e9)) # add 10 seconds
if "delay" in period.keys():
invalid_regions.append(TimeWindow(period.delay.start, period.delay.stop))
data = json_data["rocprofiler-sdk-tool"]
corrid_records = {}
for itr in ["hsa_api", "hip_api", "marker_api", "rccl_api"]:
grp = data.buffer_records[itr]
check_traces(grp, valid_regions, invalid_regions)
for record in grp:
corrid_records[record.correlation_id.external] = record
def test_perfetto_data(pftrace_data, json_data):
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
rocprofv3.test_perfetto_data(
pftrace_data, json_data, ("hip", "hsa", "marker", "kernel", "memory_copy")
)
def test_otf2_data(otf2_data, json_data):
import rocprofiler_sdk.tests.rocprofv3 as rocprofv3
rocprofv3.test_otf2_data(
otf2_data, json_data, ("hip", "hsa", "marker", "kernel", "memory_copy")
)
if __name__ == "__main__":
exit_code = pytest.main(["-x", __file__] + sys.argv[1:])
sys.exit(exit_code)