diff --git a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/fwd.h b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/fwd.h index 29975b24cc..ccb36a4d9b 100644 --- a/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/fwd.h +++ b/projects/rocprofiler-sdk/source/include/rocprofiler-sdk/fwd.h @@ -79,6 +79,7 @@ typedef enum // NOLINT(performance-enum-size) ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT, ///< Function invoked with one or more invalid ///< arguments ROCPROFILER_STATUS_ERROR_METRIC_NOT_VALID_FOR_AGENT, ///< Invalid metric supplied to agent. + ROCPROFILER_STATUS_ERROR_FINALIZED, ///< invalid because rocprofiler has been finalized ROCPROFILER_STATUS_LAST, } rocprofiler_status_t; diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/buffer.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/buffer.cpp index 7c41083060..68e6863925 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/buffer.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/buffer.cpp @@ -135,7 +135,14 @@ allocate_buffer() rocprofiler_status_t flush(rocprofiler_buffer_id_t buffer_id, bool wait) { - if(registration::get_fini_status() > 0) return ROCPROFILER_STATUS_SUCCESS; + if(registration::get_fini_status() > 0) + { + LOG(ERROR) << "ignoring rocprofiler buffer flush (handle=" << buffer_id.handle + << ") request after finalization"; + return ROCPROFILER_STATUS_ERROR_FINALIZED; + } + + if(registration::get_fini_status() < 0 && !wait) wait = true; auto offset = get_buffer_offset(); @@ -146,7 +153,11 @@ flush(rocprofiler_buffer_id_t buffer_id, bool wait) auto* task_group = internal_threading::get_task_group(rocprofiler_callback_thread_t{buff->task_group_id}); - if(wait && task_group) task_group->wait(); + LOG_IF(FATAL, !task_group) + << "buffer (" << buffer_id.handle + << ") flush request received after the task group for handling request was destroyed"; + + if(wait) task_group->wait(); // buffer is currently being flushed or destroyed if(buff->syncer.test_and_set()) @@ -162,6 +173,9 @@ flush(rocprofiler_buffer_id_t buffer_id, bool wait) auto idx = buff->buffer_idx++; auto _task = [buffer_id, idx, offset]() { + LOG_IF(ERROR, registration::get_fini_status() > 0) + << "executing buffer (" << buffer_id.handle << ") flush task finalization!"; + auto& buff_v = CHECK_NOTNULL(get_buffers())->at(buffer_id.handle - offset); auto& buff_internal_v = buff_v->get_internal_buffer(idx); @@ -197,14 +211,11 @@ flush(rocprofiler_buffer_id_t buffer_id, bool wait) buff_v->syncer.clear(); }; - if(task_group) + task_group->exec(_task); + if(wait) { - task_group->exec(_task); - if(wait) task_group->join(); - } - else - { - _task(); + while(task_group->size() > 0) + task_group->join(); } return ROCPROFILER_STATUS_SUCCESS; diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp index 799b464986..32c0e60fec 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/counters/tests/evaluate_ast_test.cpp @@ -591,7 +591,8 @@ TEST(evaluate_ast, counter_reduction_sum) return base_id; }; - auto sum_vec = [](auto& a) { + auto sum_vec = [](auto& a) -> auto& + { for(size_t i = 1; i < a.size(); i++) { a[0].counter_value += a[i].counter_value; @@ -671,7 +672,8 @@ TEST(evaluate_ast, counter_reduction_min) return base_id; }; - auto min_vec = [](auto& a) { + auto min_vec = [](auto& a) -> auto& + { a[0].counter_value = std::min_element(a.begin(), a.end(), [](const auto& b, const auto& c) { return b.counter_value < c.counter_value; })->counter_value; @@ -750,7 +752,8 @@ TEST(evaluate_ast, counter_reduction_max) return base_id; }; - auto max_vec = [](auto& a) { + auto max_vec = [](auto& a) -> auto& + { a[0].counter_value = std::max_element(a.begin(), a.end(), [](const auto& b, const auto& c) { return b.counter_value < c.counter_value; })->counter_value; @@ -829,7 +832,8 @@ TEST(evaluate_ast, counter_reduction_avg) return base_id; }; - auto avg_vec = [](auto& a) { + auto avg_vec = [](auto& a) -> auto& + { for(size_t i = 1; i < a.size(); i++) { a[0].counter_value += a[i].counter_value; @@ -910,7 +914,8 @@ TEST(evaluate_ast, evaluate_mixed_counters) return base_id; }; - auto sum_vec = [](auto& a) { + auto sum_vec = [](auto& a) -> auto& + { for(size_t i = 1; i < a.size(); i++) { a[0].counter_value += a[i].counter_value; diff --git a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocprofiler.cpp b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocprofiler.cpp index 4fffaa7dd2..585408403a 100644 --- a/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocprofiler.cpp +++ b/projects/rocprofiler-sdk/source/lib/rocprofiler-sdk/rocprofiler.cpp @@ -73,6 +73,8 @@ ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_INVALID_ARGUMENT, "Function invoked with one or more invalid arguments") ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_METRIC_NOT_VALID_FOR_AGENT, "Metric is not valid for the agent") +ROCPROFILER_STATUS_STRING(ROCPROFILER_STATUS_ERROR_FINALIZED, + "Invalid request because rocprofiler has finalized") template const char*