diff --git a/source/include/rocprofiler-sdk/context.h b/source/include/rocprofiler-sdk/context.h index a4b3a476d4..01de5cd99a 100644 --- a/source/include/rocprofiler-sdk/context.h +++ b/source/include/rocprofiler-sdk/context.h @@ -52,7 +52,7 @@ rocprofiler_create_context(rocprofiler_context_id_t* context_id) ROCPROFILER_NON /** * @brief Start context. * - * @param [in] context_id + * @param [in] context_id Identifier for context to be activated * @return ::rocprofiler_status_t */ rocprofiler_status_t ROCPROFILER_API @@ -61,18 +61,21 @@ rocprofiler_start_context(rocprofiler_context_id_t context_id); /** * @brief Stop context. * - * @param [in] context_id + * @param [in] context_id Identifier for context to be deactivated * @return ::rocprofiler_status_t */ rocprofiler_status_t ROCPROFILER_API rocprofiler_stop_context(rocprofiler_context_id_t context_id); /** - * @brief Query whether context is active. + * @brief Query whether context is currently active. * - * @param [in] context_id + * @param [in] context_id Context identifier for the query * @param [out] status If context is active, this will be a nonzero value * @return ::rocprofiler_status_t + * @retval ::ROCPROFILER_STATUS_SUCCESS The input context id identified a registered context + * @retval ::ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND The input context id did not identify a + * registered context */ rocprofiler_status_t ROCPROFILER_API rocprofiler_context_is_active(rocprofiler_context_id_t context_id, int* status) @@ -81,7 +84,7 @@ rocprofiler_context_is_active(rocprofiler_context_id_t context_id, int* status) /** * @brief Query whether the context is valid * - * @param [in] context_id + * @param [in] context_id Context identifier for the query * @param [out] status If context is invalid, this will be a nonzero value * @return ::rocprofiler_status_t */ diff --git a/source/lib/rocprofiler-sdk/context.cpp b/source/lib/rocprofiler-sdk/context.cpp index aad941f54e..63701a4f7f 100644 --- a/source/lib/rocprofiler-sdk/context.cpp +++ b/source/lib/rocprofiler-sdk/context.cpp @@ -78,13 +78,16 @@ rocprofiler_stop_context(rocprofiler_context_id_t context_id) rocprofiler_status_t rocprofiler_context_is_active(rocprofiler_context_id_t context_id, int* status) { + // make sure that status is zero (if not active) regardless of initial value *status = 0; - if(context_id.handle == rocprofiler_context_none.handle) + // return context not found if not registered + if(context_id.handle == rocprofiler_context_none.handle || + !rocprofiler::context::get_registered_context(context_id)) return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND; - auto ctxs = rocprofiler::context::context_array_t{}; - for(const auto* itr : rocprofiler::context::get_active_contexts(ctxs)) + // set status to 1 if found in active context array + for(const auto* itr : rocprofiler::context::get_active_contexts()) { if(itr && itr->context_idx == context_id.handle) { @@ -92,7 +95,9 @@ rocprofiler_context_is_active(rocprofiler_context_id_t context_id, int* status) return ROCPROFILER_STATUS_SUCCESS; } } - return ROCPROFILER_STATUS_ERROR_CONTEXT_NOT_FOUND; + + // context was not found in active array so status value is still zero + return ROCPROFILER_STATUS_SUCCESS; } rocprofiler_status_t