[Misc] fix the agent_id field (#297)
* fix the agent_id field * Fix shebang --------- Co-authored-by: Jonathan R. Madsen <jonathanrmadsen@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
61307442f0
Коммит
35069a9d06
@@ -17,4 +17,4 @@ add_subdirectory(lib)
|
||||
add_subdirectory(libexec)
|
||||
add_subdirectory(bin)
|
||||
add_subdirectory(docs)
|
||||
add_subdirectory(scripts)
|
||||
add_subdirectory(share)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
add_subdirectory(rocprofiler-sdk)
|
||||
+56
-10
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
|
||||
@@ -20,7 +21,6 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import pandas as pd
|
||||
import argparse
|
||||
@@ -69,6 +69,10 @@ def write_to_file(df, args):
|
||||
directory, file_path = os.path.split(args.output)
|
||||
if directory:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
if not args.retain_agent_prefix:
|
||||
df["Agent_Id"] = df["Agent_Id"].apply(lambda x: x.split(" ")[-1])
|
||||
|
||||
df.to_csv(args.output, index=False)
|
||||
|
||||
|
||||
@@ -100,15 +104,6 @@ def main(args):
|
||||
if col not in columns:
|
||||
logging.debug(f"Unexpected column {col} found in rocprofv3 input file")
|
||||
|
||||
non_index_columns = [
|
||||
"Correlation_Id",
|
||||
"Start_Timestamp",
|
||||
"End_Timestamp",
|
||||
"Process_Id",
|
||||
"Thread_Id",
|
||||
"Kernel_Id",
|
||||
]
|
||||
|
||||
# Convert
|
||||
indexes = [
|
||||
"Dispatch_Id",
|
||||
@@ -136,7 +131,51 @@ def main(args):
|
||||
write_to_file(pivoted_data, args)
|
||||
|
||||
|
||||
def strtobool(val):
|
||||
"""Convert a string representation of truth to true or false.
|
||||
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
|
||||
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
|
||||
'val' is anything else.
|
||||
"""
|
||||
if isinstance(val, (list, tuple)):
|
||||
if len(val) > 1:
|
||||
val_type = type(val).__name__
|
||||
raise ValueError(f"invalid truth value {val} (type={val_type})")
|
||||
else:
|
||||
val = val[0]
|
||||
|
||||
if isinstance(val, bool):
|
||||
return val
|
||||
elif isinstance(val, str) and val.lower() in ("y", "yes", "t", "true", "on", "1"):
|
||||
return True
|
||||
elif isinstance(val, str) and val.lower() in ("n", "no", "f", "false", "off", "0"):
|
||||
return False
|
||||
else:
|
||||
val_type = type(val).__name__
|
||||
raise ValueError(f"invalid truth value {val} (type={val_type})")
|
||||
|
||||
|
||||
class booleanArgAction(argparse.Action):
|
||||
def __call__(self, parser, args, value, option_string=None):
|
||||
setattr(args, self.dest, strtobool(value))
|
||||
|
||||
|
||||
def add_parser_bool_argument(gparser, *args, **kwargs):
|
||||
gparser.add_argument(
|
||||
*args,
|
||||
**kwargs,
|
||||
action=booleanArgAction,
|
||||
nargs="?",
|
||||
const=True,
|
||||
type=str,
|
||||
required=False,
|
||||
metavar="BOOL",
|
||||
default=False,
|
||||
)
|
||||
|
||||
|
||||
def parse_args():
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
@@ -171,6 +210,13 @@ def parse_args():
|
||||
dest="loglevel",
|
||||
const=logging.INFO,
|
||||
)
|
||||
advanced_options = parser.add_argument_group("Advanced options")
|
||||
add_parser_bool_argument(
|
||||
advanced_options,
|
||||
"--retain-agent-prefix",
|
||||
help="retains the agent prefix",
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -51,26 +51,59 @@ set_tests_properties(
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" ENVIRONMENT "${cc-env-pmc}"
|
||||
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
|
||||
|
||||
add_test(
|
||||
NAME test-conversion-script-convert
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE}
|
||||
$<TARGET_FILE:rocprofiler-sdk::convert-counters-collection-format> --input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script --output
|
||||
${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script/converted.csv)
|
||||
set(convert_tests test-conversion-script-convert-no-agent-prefix
|
||||
test-conversion-script-convert-agent-prefix)
|
||||
|
||||
set_tests_properties(
|
||||
test-conversion-script-convert
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
|
||||
test-conversion-script-execute FAIL_REGULAR_EXPRESSION
|
||||
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
|
||||
set(validate_tests test-conversion-script-validate-no-agent-prefix
|
||||
test-conversion-script-validate-agent-prefix)
|
||||
|
||||
add_test(NAME test-conversion-script-validate
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --input
|
||||
${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script/converted.csv)
|
||||
set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script_no_agent_prefix
|
||||
${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script_agent_prefix)
|
||||
|
||||
set_tests_properties(
|
||||
test-conversion-script-validate
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
|
||||
test-conversion-script-convert FAIL_REGULAR_EXPRESSION
|
||||
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
|
||||
set(agent_index_flag false true)
|
||||
|
||||
list(LENGTH convert_tests convert_test_length)
|
||||
|
||||
foreach(i RANGE 0 ${convert_test_length})
|
||||
if(${i} EQUAL ${convert_test_length})
|
||||
break()
|
||||
endif()
|
||||
list(GET convert_tests ${i} test_name)
|
||||
list(GET output_dir ${i} output)
|
||||
list(GET agent_index_flag ${i} flag)
|
||||
list(GET validate_tests ${i} validate_test_name)
|
||||
if(${flag})
|
||||
add_test(
|
||||
NAME ${test_name}
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE}
|
||||
$<TARGET_FILE:rocprofiler-sdk::convert-counters-collection-format>
|
||||
--input ${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script --output
|
||||
${output} --retain-agent-prefix)
|
||||
|
||||
add_test(NAME ${validate_test_name}
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py
|
||||
--input ${output} --retain-agent-prefix true)
|
||||
else()
|
||||
add_test(
|
||||
NAME ${test_name}
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE}
|
||||
$<TARGET_FILE:rocprofiler-sdk::convert-counters-collection-format>
|
||||
--input ${CMAKE_CURRENT_BINARY_DIR}/out_conversion_script --output
|
||||
${output})
|
||||
|
||||
add_test(NAME ${validate_test_name}
|
||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py
|
||||
--input ${output} --retain-agent-prefix false)
|
||||
endif()
|
||||
set_tests_properties(
|
||||
${test_name}
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS
|
||||
test-conversion-script-execute FAIL_REGULAR_EXPRESSION
|
||||
"${ROCPROFILER_DEFAULT_FAIL_REGEX}")
|
||||
set_tests_properties(
|
||||
${validate_test_name}
|
||||
PROPERTIES TIMEOUT 45 LABELS "integration-tests" DEPENDS ${test_name}
|
||||
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")
|
||||
endforeach()
|
||||
|
||||
@@ -29,6 +29,9 @@ import pandas as pd
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--input", action="store", help="Path to csv file.")
|
||||
parser.addoption(
|
||||
"--retain-agent-prefix", action="store", help="retain agent prefix flag."
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -36,3 +39,8 @@ def input_data(request):
|
||||
filename = request.config.getoption("--input")
|
||||
with open(filename, "r") as inp:
|
||||
return pd.read_csv(inp)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def retain_agent_prefix_flag(request):
|
||||
return request.config.getoption("--retain-agent-prefix")
|
||||
|
||||
@@ -35,11 +35,16 @@ kernel_list = sorted(
|
||||
counters_list = ["SQ_WAVES", "GRBM_GUI_ACTIVE"]
|
||||
|
||||
|
||||
def test_validate_counter_collection_pmc1(input_data: pd.DataFrame):
|
||||
def test_validate_counter_collection_pmc1(
|
||||
input_data: pd.DataFrame, retain_agent_prefix_flag
|
||||
):
|
||||
df = input_data
|
||||
assert not df.empty
|
||||
df_agent_id = df["Agent_Id"].str.split(" ").str[-1]
|
||||
assert (df_agent_id.astype(int).values >= 0).all()
|
||||
if retain_agent_prefix_flag == "true":
|
||||
df_agent_id = df["Agent_Id"].str.split(" ").str[-1]
|
||||
assert (df_agent_id.astype(int).values >= 0).all()
|
||||
else:
|
||||
assert (df["Agent_Id"].astype(int).values > 0).all()
|
||||
assert (df["Queue_Id"].astype(int).values > 0).all()
|
||||
assert len(df["Kernel_Name"]) > 0
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user