From e4569c41feb1e55f473bf26eb3989c619562fda7 Mon Sep 17 00:00:00 2001 From: Ammar ELWazir Date: Thu, 7 Apr 2022 15:12:47 +0000 Subject: [PATCH] SWDEV-295522: Fixing Performance Issue Removing DEBUG_TRACES and the unnecessary use of roctracer_op_string, made the MS app reporting 78 to 81 stable samples per second, depending on the type of the trace, while the main app without rocprof reports 100 to 106. More detailed numbers will be posted in the ticket. Change-Id: Ifbc529278cea54dd23e6086aa9b9ea2df952d5dd --- src/core/roctracer.cpp | 15 +++++++-------- src/util/logger.h | 2 +- test/tool/tracer_tool.cpp | 12 +++++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/core/roctracer.cpp b/src/core/roctracer.cpp index 61c1711c48..186a318b47 100644 --- a/src/core/roctracer.cpp +++ b/src/core/roctracer.cpp @@ -409,12 +409,12 @@ void* HIP_SyncApiDataCallback(uint32_t op_id, roctracer_record_t* record, const correlation_id_tls = 0; } - const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0); DEBUG_TRACE( "HIP_SyncApiDataCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) " "correlation_id(%lu) time_ns(%lu)\n", - name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()), - (data_ptr) ? data_ptr->correlation_id : 0, timer.timestamp_ns()); + roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0), phase, op_id, record, data, pool, + (int)(record_pair_stack->size()), (data_ptr) ? data_ptr->correlation_id : 0, + timer.timestamp_ns()); return ret; } @@ -503,12 +503,11 @@ void* HIP_SyncActivityCallback(uint32_t op_id, roctracer_record_t* record, correlation_id_tls = 0; } - const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0); DEBUG_TRACE( "HIP_SyncActivityCallback(\"%s\") phase(%d): op(%u) record(%p) data(%p) pool(%p) depth(%d) " "correlation_id(%lu) beg_ns(%lu) end_ns(%lu)\n", - name, phase, op_id, record, data, pool, (int)(record_pair_stack->size()), - (data_ptr) ? data_ptr->correlation_id : 0, timestamp_ns); + roctracer_op_string(ACTIVITY_DOMAIN_HIP_API, op_id, 0), phase, op_id, record, data, pool, + (int)(record_pair_stack->size()), (data_ptr) ? data_ptr->correlation_id : 0, timestamp_ns); return ret; } @@ -525,11 +524,11 @@ void HIP_AsyncActivityCallback(uint32_t op_id, void* record, void* arg) { if (record_ptr->correlation_id == 0) return; pool->Write(*record_ptr); - const char* name = roctracer_op_string(ACTIVITY_DOMAIN_HIP_OPS, record_ptr->op, record_ptr->kind); DEBUG_TRACE( "HIP_AsyncActivityCallback(\"%s\"): op(%u) kind(%u) record(%p) pool(%p) correlation_id(%d) " "beg_ns(%lu) end_ns(%lu)\n", - name, record_ptr->op, record_ptr->kind, record, pool, record_ptr->correlation_id, + roctracer_op_string(ACTIVITY_DOMAIN_HIP_OPS, record_ptr->op, record_ptr->kind), + record_ptr->op, record_ptr->kind, record, pool, record_ptr->correlation_id, record_ptr->begin_ns, record_ptr->end_ns); } diff --git a/src/util/logger.h b/src/util/logger.h index ed3709af88..4617709a45 100644 --- a/src/util/logger.h +++ b/src/util/logger.h @@ -209,7 +209,7 @@ inline static void DEBUG_TRACE(const char* fmt, ...) { va_end(valist); } #else -inline static void DEBUG_TRACE(const char* fmt, ...) {} +#define DEBUG_TRACE(...) #endif #endif // SRC_UTIL_LOGGER_H_ diff --git a/test/tool/tracer_tool.cpp b/test/tool/tracer_tool.cpp index 3a720f35c7..5dc147de1e 100644 --- a/test/tool/tracer_tool.cpp +++ b/test/tool/tracer_tool.cpp @@ -94,7 +94,7 @@ inline static void DEBUG_TRACE(const char* fmt, ...) { va_end(valist); } #else -inline static void DEBUG_TRACE(const char* fmt, ...) {} +#define DEBUG_TRACE(...) #endif typedef hsa_rt_utils::Timer::timestamp_t timestamp_t; @@ -466,12 +466,11 @@ void hip_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, entry->valid.store(roctracer::TRACE_ENTRY_COMPL, std::memory_order_release); } - const char* name = roctracer_op_string(domain, cid, 0); DEBUG_TRACE( "hip_api_callback(\"%s\") phase(%d): cid(%u) data(%p) entry(%p) name(\"%s\") " "correlation_id(%lu) timestamp(%lu)\n", - name, data->phase, cid, data, entry, (entry) ? entry->name : NULL, data->correlation_id, - timestamp); + roctracer_op_string(domain, cid, 0), data->phase, cid, data, entry, + (entry) ? entry->name : NULL, data->correlation_id, timestamp); } void mark_api_callback(uint32_t domain, uint32_t cid, const void* callback_data, void* arg) { @@ -512,12 +511,11 @@ void hip_api_flush_cb(hip_api_trace_entry_t* entry) { << entry->tid; oss << std::dec << rec_ss.str() << " " << str; - const char* name = roctracer_op_string(entry->domain, entry->cid, 0); DEBUG_TRACE( "hip_api_flush_cb(\"%s\"): domain(%u) cid(%u) entry(%p) name(\"%s\" correlation_id(%lu) " "beg(%lu) end(%lu))\n", - name, entry->domain, entry->cid, entry, entry->name, correlation_id, begin_timestamp, - end_timestamp); + roctracer_op_string(entry->domain, entry->cid, 0), entry->domain, entry->cid, entry, + entry->name, correlation_id, begin_timestamp, end_timestamp); if (domain == ACTIVITY_DOMAIN_HIP_API) { #if HIP_PROF_HIP_API_STRING