From 52fc6e86199c7a9975225423bb4aeff365873523 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Mon, 1 Apr 2024 22:29:22 +0000 Subject: [PATCH] PC Sampling: Convert timestamps to system time Convert timestamps inside samples to system time Change-Id: I5fad9a6887fa27c0ded9aa9b5f251cba2868f88f [ROCm/ROCR-Runtime commit: 49e56ce782dd5498d271effbdd2421c6492cfa80] --- .../runtime/hsa-runtime/pcs/pcs_runtime.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/pcs/pcs_runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/pcs/pcs_runtime.cpp index dd787d6ef5..8270a90fe6 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/pcs/pcs_runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/pcs/pcs_runtime.cpp @@ -187,6 +187,43 @@ hsa_status_t PcsRuntime::PcSamplingSession::HandleSampleData(uint8_t* buf1, size data_rdy.buf2 = buf2; data_rdy.buf2_sz = buf2_sz; + AMD::GpuAgent* gpuAgent = static_cast(agent); + + switch (csd.method) { + case HSA_VEN_AMD_PCS_METHOD_HOSTTRAP_V1: { + size_t buf_samples = buf1_sz / sizeof(perf_sample_hosttrap_v1_t); + perf_sample_hosttrap_v1_t* samples = reinterpret_cast(buf1); + while (buf_samples--) { + samples->timestamp = gpuAgent->TranslateTime(samples->timestamp); + samples++; + } + + buf_samples = buf2_sz / sizeof(perf_sample_hosttrap_v1_t); + samples = reinterpret_cast(buf2); + while (buf_samples--) { + samples->timestamp = gpuAgent->TranslateTime(samples->timestamp); + samples++; + } + } + break; + case HSA_VEN_AMD_PCS_METHOD_STOCHASTIC_V1: { + size_t buf_samples = buf1_sz / sizeof(perf_sample_snapshot_v1_t); + perf_sample_snapshot_v1_t* samples = reinterpret_cast(buf1); + while (buf_samples--) { + samples->timestamp = gpuAgent->TranslateTime(samples->timestamp); + samples++; + } + + buf_samples = buf2_sz / sizeof(perf_sample_snapshot_v1_t); + samples = reinterpret_cast(buf2); + while (buf_samples--) { + samples->timestamp = gpuAgent->TranslateTime(samples->timestamp); + samples++; + } + } + break; + } + csd.data_ready_callback(csd.client_callback_data, buf1_sz + buf2_sz, lost_sample_count, &PcSamplingDataCopyCallback, /* hsa_callback_data*/ this);