Skip to content

Commit 3954ced

Browse files
yhuiYHa-canadasruizjin-amdjrmadsen
authored
[rocpd] Adding summary module to generate summaries from rocpd database + query submodule + rocpd command-line tools (#488)
* adding summary.py to generate tmp <category_region>_summary views * migrating CSV summary to SDK method of writing CSVs - Add domain_view to summary.py - omit the C++ code of writing CSV because it gets revered later anyway * Add summary subparser and write_sql_view_to_csv function * adding all <>_summary views generation to summary.py * add summary_per_rank feature * add --summary-per-rank * reconstruct generate_summary_view and create_domain_view -introduce by_rank * remove sqr and variance in summary views * use RocpdImportData instead of connection * two fixes on summary.py --modify the generate_summary_view function to return a tuple with view name and sql code add if_not_exits parameter to generete_summary_view * Refactor summary.py to allow output path and filename args, and apply time_window - clean up summary table column headers - only generate by-rank views if that param is specified * Add ProcessID to Hostname output and csv, so users can identify the system in the by-rank summaries * Summary.py, just add hostname to by-rank summaries, instead of creating mapping table * Summary - migrate csv writer to pandas, for more future flexibility * Adding a few simple tests for summary.py * Linting fixes * add region_categories to summary options - Automatically retrieve region categories from the database if argument is None * add backticks for view_names * fix tests after rebase * Made code review changes - fixed whitespace in CMakelists.txt - adding query.py module & subparser in __main__.py - refactor summary function to return query - used query.py to output csv - used query.py to also output summary to console - provided new command line options to select summary output to csv or console * Made fix to jinja template in query.py, as suggested by copilot * Consolidated output calls to query in export_view function based on feedback - refactored: helpers, query functions, create view functions - extended formats to include what query supports (md, html, pdf, json) - added json format to query, and changed orient=records - adding jinja2 and reportlab to requirements.txt * Add version_info for rocpd and roctx * Add rocpd commandline tool * Add executable permissions to source/bin/rocpd.py * Removed rocpd2query, and cleaned up --help examples --------- Co-authored-by: acanadas <acanadas@amd.com> Co-authored-by: Jin Tao <jintao12@amd.com> Co-authored-by: a-canadasruiz <Araceli.CanadasRuiz@amd.com> Co-authored-by: Jonathan R. Madsen <Jonathan.Madsen@amd.com>
1 parent 735b5c3 commit 3954ced

File tree

13 files changed

+1484
-281
lines changed

13 files changed

+1484
-281
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ cmake>=3.21.0
55
cmake-format
66
dataclasses
77
flake8
8+
jinja2
89
numpy
910
otf2
1011
pandas
1112
perfetto
1213
pycobertura
1314
pytest
1415
pyyaml
16+
reportlab

source/bin/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,39 @@ install(
2525
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ
2626
WORLD_EXECUTE
2727
COMPONENT tools)
28+
29+
# for each entry here there must be a ROCPD_BIN_<entry> list
30+
set(ROCPD_EXECUTABLES "all" "csv" "otf2" "pftrace" "summary")
31+
32+
# format is list: [<exe-name>, <python-module>, <extra-args-to-python-module>]
33+
set(ROCPD_BIN_all "rocpd" "rocpd" "")
34+
set(ROCPD_BIN_csv "rocpd2csv" "rocpd.csv" "")
35+
set(ROCPD_BIN_otf2 "rocpd2otf2" "rocpd.otf2" "")
36+
set(ROCPD_BIN_pftrace "rocpd2pftrace" "rocpd.pftrace" "")
37+
set(ROCPD_BIN_summary "rocpd2summary" "rocpd.summary" "")
38+
39+
foreach(_EXE IN LISTS ROCPD_EXECUTABLES)
40+
list(GET ROCPD_BIN_${_EXE} 0 ROCPD_EXE_NAME)
41+
list(GET ROCPD_BIN_${_EXE} 1 ROCPD_EXE_MODULE)
42+
list(GET ROCPD_BIN_${_EXE} 2 ROCPD_EXE_MODULE_ARGS)
43+
44+
if(NOT ROCPD_EXE_NAME
45+
OR NOT ROCPD_EXE_MODULE
46+
OR (NOT ROCPD_EXE_MODULE_ARGS AND NOT ROCPD_EXE_MODULE_ARGS STREQUAL ""))
47+
message(
48+
FATAL_ERROR "ROCPD_BIN_${_EXE} not properly defined: ${ROCPD_BIN_${_EXE}}")
49+
endif()
50+
51+
set(ROCPD_EXE_OUTPUT_FILE
52+
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/${ROCPD_EXE_NAME})
53+
54+
# Adding main rocpd
55+
configure_file(rocpd.py ${ROCPD_EXE_OUTPUT_FILE} @ONLY)
56+
57+
install(
58+
FILES ${ROCPD_EXE_OUTPUT_FILE}
59+
DESTINATION ${CMAKE_INSTALL_BINDIR}
60+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
61+
WORLD_READ WORLD_EXECUTE
62+
COMPONENT rocpd)
63+
endforeach()

source/bin/rocpd.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
import os
26+
import sys
27+
28+
"""
29+
Simple Python executable script for invoking `python3 -m @ROCPD_EXE_MODULE@`
30+
"""
31+
32+
33+
def main(argv=sys.argv[1:], environ=dict(os.environ)):
34+
"""
35+
Executes {sys.executable} -m @ROCPD_EXE_MODULE@ @ROCPD_EXE_MODULE_ARGS@
36+
"""
37+
38+
ROCPD_SUPPORTED_PYTHON_VERSIONS = [
39+
".".join(itr.split(".")[:2]) for itr in "@ROCPROFILER_PYTHON_VERSIONS@".split(";")
40+
]
41+
ROCPD_MODULE_ARGS = [f"{itr}" for itr in "@ROCPD_EXE_MODULE_ARGS@".split(" ") if itr]
42+
43+
this_dir = os.path.dirname(os.path.realpath(__file__))
44+
this_python_ver = f"{sys.version_info.major}.{sys.version_info.minor}"
45+
if this_python_ver not in ROCPD_SUPPORTED_PYTHON_VERSIONS:
46+
raise ImportError(
47+
"@ROCPD_EXE_NAME@ not supported for Python version {} (sys.executable='{}').\n@ROCPD_EXE_NAME@ supported python versions: {}".format(
48+
this_python_ver,
49+
sys.executable,
50+
", ".join(ROCPD_SUPPORTED_PYTHON_VERSIONS),
51+
)
52+
)
53+
54+
module_path = os.path.join(
55+
this_dir,
56+
"..",
57+
"@CMAKE_INSTALL_LIBDIR@",
58+
f"python{this_python_ver}",
59+
"site-packages",
60+
)
61+
62+
python_path = [module_path] + os.environ.get("PYTHONPATH", "").split(":")
63+
64+
# update PYTHONPATH environment variable
65+
environ["PYTHONPATH"] = ":".join(python_path)
66+
67+
args = [f"{sys.executable}", "-m", "@ROCPD_EXE_MODULE@"] + ROCPD_MODULE_ARGS + argv
68+
69+
# does not return
70+
os.execvpe(args[0], args, env=environ)
71+
72+
73+
if __name__ == "__main__":
74+
main()

source/lib/python/rocpd/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,24 @@
4646
"write_csv",
4747
"write_otf2",
4848
"RocpdImportData",
49+
"version_info",
4950
]
5051

52+
version_info = {
53+
"version": "@PROJECT_VERSION@",
54+
"major": int("@PROJECT_VERSION_MAJOR@"),
55+
"minor": int("@PROJECT_VERSION_MINOR@"),
56+
"patch": int("@PROJECT_VERSION_PATCH@"),
57+
"git_revision": "@ROCPROFILER_SDK_GIT_REVISION@",
58+
"library_arch": "@CMAKE_LIBRARY_ARCHITECTURE@",
59+
"system_name": "@CMAKE_SYSTEM_NAME@",
60+
"system_processor": "@CMAKE_SYSTEM_PROCESSOR@",
61+
"system_version": "@CMAKE_SYSTEM_VERSION@",
62+
"compiler_id": "@CMAKE_CXX_COMPILER_ID@",
63+
"compiler_version": "@CMAKE_CXX_COMPILER_VERSION@",
64+
"rocm_version": "@rocm_version_FULL_VERSION@",
65+
}
66+
5167

5268
def format_path(path, tag=os.path.basename(sys.executable)):
5369
return libpyrocpd.format_path(path, tag)

0 commit comments

Comments
 (0)