Skip to content

Commit 2d184c2

Browse files
committed
[SWDEV-561822] Add Duration column to rocpd kernel_trace CSV output
## Summary Added 'Duration' field to kernel trace CSV output from rocpd to address regression from legacy rocprof to rocprofv3. The Duration column provides the kernel execution time in nanoseconds, calculated as (End_Timestamp - Start_Timestamp). ## Changes - source/lib/output/csv.hpp: Added duration field to kernel dispatch CSV schema - source/lib/output/generateCSV.cpp: Implemented duration calculation and output - source/lib/python/rocpd/csv.py: Added Duration column to Python CSV generator - tests/rocprofv3/kernel-duration-ns/*: Added comprehensive test suite ## Testing - Verified Duration column exists in CSV output - Validated Duration = End_Timestamp - Start_Timestamp - Confirmed backward compatibility with existing CSV fields - All integration tests passing ## Addresses - SWDEV-561822: Request to add durations in --kernel-trace output - Restores functionality from legacy rocprof --stats output
1 parent 23ed2fa commit 2d184c2

File tree

7 files changed

+187
-176
lines changed

7 files changed

+187
-176
lines changed

projects/rocprofiler-sdk/source/lib/output/csv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ using list_derived_metrics_csv_encoder = csv_encoder<5>;
109109
using scratch_memory_encoder = csv_encoder<9>;
110110
using stats_csv_encoder = csv_encoder<8>;
111111
using pc_sampling_host_trap_csv_encoder = csv_encoder<6>;
112-
using kernel_trace_with_stream_csv_encoder = csv_encoder<23>;
112+
using kernel_trace_with_stream_csv_encoder = csv_encoder<22>;
113113
using memory_copy_with_stream_csv_encoder = csv_encoder<8>;
114114
using pc_sampling_stochastic_csv_encoder = csv_encoder<10>;
115115
} // namespace csv

projects/rocprofiler-sdk/source/lib/output/generateCSV.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,31 @@ generate_csv(const output_config&
260260

261261
if(cfg.stats && stats)
262262
write_stats(get_stats_output_file(cfg, domain_type::KERNEL_DISPATCH), stats.entries);
263-
auto ofs = tool::csv_output_file{
264-
cfg,
265-
domain_type::KERNEL_DISPATCH,
266-
tool::csv::kernel_trace_with_stream_csv_encoder{},
267-
{"Kind", "Agent_Id", "Queue_Id", "Stream_Id",
268-
"Thread_Id", "Dispatch_Id", "Kernel_Id", "Kernel_Name",
269-
"Correlation_Id", "Start_Timestamp", "End_Timestamp", "Duration_NS",
270-
"LDS_Block_Size", "Scratch_Size", "VGPR_Count", "Accum_VGPR_Count",
271-
"SGPR_Count", "Workgroup_Size_X", "Workgroup_Size_Y", "Workgroup_Size_Z",
272-
"Grid_Size_X", "Grid_Size_Y", "Grid_Size_Z"}};
263+
auto ofs = tool::csv_output_file{cfg,
264+
domain_type::KERNEL_DISPATCH,
265+
tool::csv::kernel_trace_with_stream_csv_encoder{},
266+
{"Kind",
267+
"Agent_Id",
268+
"Queue_Id",
269+
"Stream_Id",
270+
"Thread_Id",
271+
"Dispatch_Id",
272+
"Kernel_Id",
273+
"Kernel_Name",
274+
"Correlation_Id",
275+
"Start_Timestamp",
276+
"End_Timestamp",
277+
"LDS_Block_Size",
278+
"Scratch_Size",
279+
"VGPR_Count",
280+
"Accum_VGPR_Count",
281+
"SGPR_Count",
282+
"Workgroup_Size_X",
283+
"Workgroup_Size_Y",
284+
"Workgroup_Size_Z",
285+
"Grid_Size_X",
286+
"Grid_Size_Y",
287+
"Grid_Size_Z"}};
273288

274289
for(auto ditr : data)
275290
{
@@ -298,7 +313,6 @@ generate_csv(const output_config&
298313
record.correlation_id.internal,
299314
record.start_timestamp,
300315
record.end_timestamp,
301-
(record.end_timestamp - record.start_timestamp),
302316
lds_block_size_v,
303317
record.dispatch_info.private_segment_size,
304318
kernel_info->arch_vgpr_count,
@@ -1001,4 +1015,4 @@ generate_csv(const output_config& cfg,
10011015
}
10021016
}
10031017
} // namespace tool
1004-
} // namespace rocprofiler
1018+
} // namespace rocprofiler

projects/rocprofiler-sdk/source/lib/python/rocpd/csv.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def write_kernel_csv(importData, config) -> None:
235235
"stack_id AS Correlation_Id",
236236
"start AS Start_Timestamp",
237237
"end AS End_Timestamp",
238-
"(end - start) AS Duration_NS",
238+
"(end - start) AS Duration",
239239
"lds_size AS Lds_Block_Size",
240240
"scratch_size",
241241
"vgpr_count",
@@ -281,7 +281,7 @@ def write_memory_copy_csv(importData, config) -> None:
281281
stack_id AS Correlation_Id,
282282
start AS Start_Timestamp,
283283
end AS End_Timestamp,
284-
(end - start) AS Duration_NS
284+
(end - start) AS Duration
285285
FROM "memory_copies"
286286
ORDER BY
287287
guid ASC, start ASC, end DESC
@@ -312,7 +312,7 @@ def write_memory_allocation_csv(importData, config) -> None:
312312
stack_id AS Correlation_Id,
313313
start AS Start_Timestamp,
314314
end AS End_Timestamp,
315-
(end - start) AS Duration_NS
315+
(end - start) AS Duration
316316
FROM "memory_allocations"
317317
ORDER BY
318318
guid ASC, start ASC, end DESC
@@ -345,7 +345,7 @@ def write_counters_csv(importData, config) -> None:
345345
"value AS Counter_Value",
346346
"start AS Start_Timestamp",
347347
"end AS End_Timestamp",
348-
"(end - start) AS Duration_NS",
348+
"(end - start) AS Duration",
349349
]
350350

351351
aliased_headers = []
@@ -379,7 +379,7 @@ def write_scratch_memory_csv(importData, config) -> None:
379379
alloc_flags,
380380
start AS Start_Timestamp,
381381
end AS End_Timestamp,
382-
(end - start) AS Duration_NS
382+
(end - start) AS Duration
383383
FROM "scratch_memory"
384384
ORDER BY
385385
guid ASC, start ASC, end DESC
@@ -399,7 +399,7 @@ def write_region_csv(importData, config) -> None:
399399
stack_id AS Correlation_Id,
400400
start AS Start_Timestamp,
401401
end AS End_Timestamp,
402-
(end - start) AS Duration_NS
402+
(end - start) AS Duration
403403
FROM "regions"
404404
ORDER BY
405405
guid ASC, start ASC, end DESC
Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,69 @@
11
#
2-
# rocprofv3 tool tests for kernel duration ns
2+
# rocprofv3 tool tests for kernel duration
33
#
44
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
55

6-
project(
7-
rocprofiler-sdk-tests-rocprofv3-kernel-duration-ns
8-
LANGUAGES CXX
9-
VERSION 0.0.0)
6+
project(rocprofiler-sdk-tests-rocprofv3-kernel-trace-duration LANGUAGES CXX VERSION 0.0.0)
107

118
find_package(rocprofiler-sdk REQUIRED)
129
find_package(Python3 REQUIRED)
1310

1411
set(rocprofv3-env
1512
"${ROCPROFILER_MEMCHECK_PRELOAD_ENV}"
1613
"PYTHONPATH=${rocprofiler-sdk_LIB_DIR}/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages"
17-
)
14+
)
1815

1916
rocprofiler_configure_pytest_files(CONFIG pytest.ini COPY conftest.py validate.py)
2017

18+
# 1) Generate JSON (ground truth)
2119
add_test(
22-
NAME rocprofv3-test-kernel-duration-ns-execute
20+
NAME rocprofv3-test-kernel-trace-duration-json
2321
COMMAND
24-
$<TARGET_FILE:rocprofiler-sdk::rocprofv3> -d
25-
${CMAKE_CURRENT_BINARY_DIR}/kernel-duration-ns -o out --output-format csv
26-
--kernel-trace -- $<TARGET_FILE:simple-transpose>)
22+
$<TARGET_FILE:rocprofiler-sdk::rocprofv3>
23+
-d ${CMAKE_CURRENT_BINARY_DIR}/kernel-trace-duration
24+
-o out_json
25+
--output-format json
26+
--kernel-trace
27+
-- $<TARGET_FILE:simple-transpose>)
2728

2829
set_tests_properties(
29-
rocprofv3-test-kernel-duration-ns-execute
30-
PROPERTIES TIMEOUT
31-
120
32-
LABELS
33-
"integration-tests;kernel-duration-ns"
34-
ENVIRONMENT
35-
"${rocprofv3-env}"
36-
FAIL_REGULAR_EXPRESSION
37-
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
38-
FIXTURES_SETUP
39-
rocprofv3-test-kernel-duration-ns-run)
30+
rocprofv3-test-kernel-trace-duration-json
31+
PROPERTIES TIMEOUT 120
32+
LABELS "integration-tests;kernel-trace-duration"
33+
ENVIRONMENT "${rocprofv3-env}"
34+
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}"
35+
FIXTURES_SETUP rocprofv3-test-kernel-trace-duration-run)
4036

37+
# 2) Generate rocpd DB
4138
add_test(
42-
NAME rocprofv3-test-kernel-duration-ns-validation
43-
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py --csv-input
44-
${CMAKE_CURRENT_BINARY_DIR}/kernel-duration-ns/out_kernel_trace.csv)
39+
NAME rocprofv3-test-kernel-trace-duration-rocpd
40+
COMMAND
41+
$<TARGET_FILE:rocprofiler-sdk::rocprofv3>
42+
-d ${CMAKE_CURRENT_BINARY_DIR}/kernel-trace-duration
43+
-o out_rocpd
44+
--output-format rocpd
45+
--kernel-trace
46+
-- $<TARGET_FILE:simple-transpose>)
47+
48+
set_tests_properties(
49+
rocprofv3-test-kernel-trace-duration-rocpd
50+
PROPERTIES TIMEOUT 120
51+
LABELS "integration-tests;kernel-trace-duration"
52+
ENVIRONMENT "${rocprofv3-env}"
53+
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}"
54+
FIXTURES_REQUIRED rocprofv3-test-kernel-trace-duration-run)
55+
56+
# 3) Convert rocpd DB -> CSV and validate vs JSON
57+
add_test(
58+
NAME rocprofv3-test-kernel-trace-duration-validation
59+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/validate.py
60+
--json-input ${CMAKE_CURRENT_BINARY_DIR}/kernel-trace-duration/out_json_results.json
61+
--db-input ${CMAKE_CURRENT_BINARY_DIR}/kernel-trace-duration/out_rocpd_results.db)
4562

4663
set_tests_properties(
47-
rocprofv3-test-kernel-duration-ns-validation
48-
PROPERTIES TIMEOUT
49-
120
50-
LABELS
51-
"integration-tests;kernel-duration-ns"
52-
ENVIRONMENT
53-
"${rocprofv3-env}"
54-
DEPENDS
55-
"rocprofv3-test-kernel-duration-ns-execute"
56-
FAIL_REGULAR_EXPRESSION
57-
"${ROCPROFILER_DEFAULT_FAIL_REGEX}"
58-
FIXTURES_REQUIRED
59-
rocprofv3-test-kernel-duration-ns-run)
64+
rocprofv3-test-kernel-trace-duration-validation
65+
PROPERTIES TIMEOUT 120
66+
LABELS "integration-tests;kernel-trace-duration"
67+
ENVIRONMENT "${rocprofv3-env}"
68+
DEPENDS "rocprofv3-test-kernel-trace-duration-json;rocprofv3-test-kernel-trace-duration-rocpd"
69+
FAIL_REGULAR_EXPRESSION "${ROCPROFILER_DEFAULT_FAIL_REGEX}")

projects/rocprofiler-sdk/tests/rocprofv3/kernel-duration-ns/conftest.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,23 @@
2323
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2424
# THE SOFTWARE.
2525

26-
from pathlib import Path
27-
26+
import json
27+
import os
2828
import pytest
2929

30-
from validate import load_csv_data
31-
32-
3330
def pytest_addoption(parser):
34-
"""Register command-line options for this test module."""
35-
parser.addoption(
36-
"--csv-input",
37-
action="store",
38-
help="Path to kernel trace CSV file to validate.",
39-
)
31+
parser.addoption("--json-input", action="store", required=True, help="Input JSON")
32+
parser.addoption("--db-input", action="store", required=True, help="Input rocpd DB")
4033

34+
@pytest.fixture
35+
def json_data(request):
36+
path = request.config.getoption("--json-input")
37+
assert os.path.isfile(path), f"missing JSON input: {path}"
38+
with open(path, "r") as f:
39+
return json.load(f)
4140

4241
@pytest.fixture
43-
def csv_data(request):
44-
"""
45-
Return CSV data as a list of dictionaries.
46-
47-
This fixture follows the existing format used in other tests.
48-
All validation logic has been moved to validate.py.
49-
"""
50-
filename = request.config.getoption("--csv-input")
51-
if not filename:
52-
raise RuntimeError("--csv-input option is required for this test")
53-
54-
path = Path(filename)
55-
return load_csv_data(path)
42+
def db_path(request):
43+
path = request.config.getoption("--db-input")
44+
assert os.path.isfile(path), f"missing rocpd DB input: {path}"
45+
return path
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[pytest]
2-
addopts = --durations=20 -rA -s -vv
2+
addopts = --durations=20 -rA -s
33
testpaths = validate.py
44
pythonpath = @ROCPROFILER_SDK_TESTS_BINARY_DIR@/pytest-packages

0 commit comments

Comments
 (0)