Improve buffer flush error handling (#416)

* Update include/rocprofiler-sdk/fwd.h

- add ROCPROFILER_STATUS_ERROR_FINALIZED error code

* Update lib/rocprofiler-sdk/rocprofiler.cpp

- status string for ROCPROFILER_STATUS_ERROR_FINALIZED

* Update lib/rocprofiler-sdk/buffer.cpp

- return error code if buffer flush invoked after finalized
- fatal error if task group destroyed
- error message if task runs after finalized
- improve join of task group

* Update lib/rocprofiler-sdk/counters/tests/evaluate_ast_tests.cpp

- Update lambdas to return reference due to strange -Warray-bounds and -Wstringop-overflow warnings with g++ (Ubuntu 13.1.0-8ubuntu1~20.04.2) 13.1.0

[ROCm/rocprofiler-sdk commit: 3547a45c0c]
Esse commit está contido em:
Jonathan R. Madsen
2024-01-26 04:01:09 -06:00
commit de GitHub
commit 6c200ffbf4
4 arquivos alterados com 33 adições e 14 exclusões
@@ -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;
@@ -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;
@@ -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;
@@ -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 <size_t Idx, size_t... Tail>
const char*