diff --git a/projects/roctracer/src/util/hsa_rsrc_factory.h b/projects/roctracer/src/util/hsa_rsrc_factory.h index c52715d4e6..466ccf1f95 100644 --- a/projects/roctracer/src/util/hsa_rsrc_factory.h +++ b/projects/roctracer/src/util/hsa_rsrc_factory.h @@ -199,7 +199,7 @@ class HsaTimer { } // Method for timespec/ns conversion - timestamp_t timespec_to_ns(const timespec& time) const { + static timestamp_t timespec_to_ns(const timespec& time) { return ((timestamp_t)time.tv_sec * 1000000000) + time.tv_nsec; } @@ -212,7 +212,7 @@ class HsaTimer { } // Return time in 'ns' - timestamp_t clocktime_ns(clockid_t clock_id) const { + static timestamp_t clocktime_ns(clockid_t clock_id) { timespec time; clock_gettime(clock_id, &time); return timespec_to_ns(time); @@ -221,7 +221,7 @@ class HsaTimer { // Return pair of correlated values of profiling timestamp and time with // correlation error for a given time ID and number of iterations void correlated_pair_ns(time_id_t time_id, uint32_t iters, - timestamp_t* timestamp_v, timestamp_t* time_v, timestamp_t* error_v) { + timestamp_t* timestamp_v, timestamp_t* time_v, timestamp_t* error_v) const { clockid_t clock_id = 0; switch (clock_id) { case TIME_ID_CLOCK_REALTIME: @@ -427,12 +427,18 @@ class HsaRsrcFactory { time_error_[time_id] = error_v; } - hsa_status_t GetTime(uint32_t time_id, uint64_t value, uint64_t* time) { + hsa_status_t GetTime(uint32_t time_id, timestamp_t value, uint64_t* time) { if (time_id >= HsaTimer::TIME_ID_NUMBER) return HSA_STATUS_ERROR; *time = value + time_shift_[time_id]; return HSA_STATUS_SUCCESS; } + hsa_status_t GetTimestamp(uint32_t time_id, uint64_t value, timestamp_t* timestamp) { + if (time_id >= HsaTimer::TIME_ID_NUMBER) return HSA_STATUS_ERROR; + *timestamp = value - time_shift_[time_id]; + return HSA_STATUS_SUCCESS; + } + private: // System agents iterating callback static hsa_status_t GetHsaAgentsCallback(hsa_agent_t agent, void* data); diff --git a/projects/roctracer/test/CMakeLists.txt b/projects/roctracer/test/CMakeLists.txt index 8cff137c25..03a8695f15 100644 --- a/projects/roctracer/test/CMakeLists.txt +++ b/projects/roctracer/test/CMakeLists.txt @@ -54,7 +54,7 @@ target_link_libraries ( ${TEST_LIB} ${ROCTRACER_TARGET} ${HSA_RUNTIME_LIB} c std ## Build HSA test execute_process ( COMMAND sh -xc "if [ ! -e ${TEST_DIR}/hsa ] ; then git clone https://github.com/ROCmSoftwarePlatform/hsa-class.git ${TEST_DIR}/hsa; fi" ) -execute_process ( COMMAND sh -xc "if [ -e ${TEST_DIR}/hsa ] ; then cd ${TEST_DIR}/hsa && git fetch origin && git checkout fff0102; fi" ) +execute_process ( COMMAND sh -xc "if [ -e ${TEST_DIR}/hsa ] ; then cd ${TEST_DIR}/hsa && git fetch origin && git checkout 777c308; fi" ) set ( TEST_DIR ${HSA_TEST_DIR} ) add_subdirectory ( ${TEST_DIR} ${PROJECT_BINARY_DIR}/test/hsa ) diff --git a/projects/roctracer/test/tool/tracer_tool.cpp b/projects/roctracer/test/tool/tracer_tool.cpp index ba1f117bf1..33b8210914 100644 --- a/projects/roctracer/test/tool/tracer_tool.cpp +++ b/projects/roctracer/test/tool/tracer_tool.cpp @@ -43,6 +43,8 @@ THE SOFTWARE. #include #include +#include "util/hsa_rsrc_factory.h" + #define PUBLIC_API __attribute__((visibility("default"))) #define CONSTRUCTOR_API __attribute__((constructor)) #define DESTRUCTOR_API __attribute__((destructor)) @@ -164,7 +166,7 @@ struct roctx_trace_entry_t { uint32_t valid; uint32_t type; uint32_t cid; - timestamp_t timestamp; + timestamp_t time; uint32_t pid; uint32_t tid; const char* message; @@ -181,12 +183,11 @@ static inline void roctx_callback_fun( uint32_t tid, const char* message) { - const timestamp_t timestamp = timer->timestamp_fn_ns(); roctx_trace_entry_t* entry = roctx_trace_buffer.GetEntry(); entry->valid = roctracer::TRACE_ENTRY_COMPL; entry->type = 0; entry->cid = cid; - entry->timestamp = timestamp; + entry->time = HsaTimer::clocktime_ns(HsaTimer::TIME_ID_CLOCK_MONOTONIC); entry->pid = GetPid(); entry->tid = tid; entry->message = (message != NULL) ? strdup(message) : NULL; @@ -215,8 +216,10 @@ void stop_callback() { roctracer::RocTxLoader::Instance().RangeStackIterate(roct // rocTX buffer flush function void roctx_flush_cb(roctx_trace_entry_t* entry) { + timestamp_t timestamp = 0; + HsaRsrcFactory::Instance().GetTimestamp(HsaTimer::TIME_ID_CLOCK_MONOTONIC, entry->time, ×tamp); std::ostringstream os; - os << entry->timestamp << " " << entry->pid << ":" << entry->tid << " " << entry->cid; + os << timestamp << " " << entry->pid << ":" << entry->tid << " " << entry->cid; if (entry->message != NULL) os << ":\"" << entry->message << "\""; else os << ":\"\""; fprintf(roctx_file_handle, "%s\n", os.str().c_str()); fflush(roctx_file_handle);