|
23 | 23 | #include "lib/rocprofiler-sdk/counters/device_counting.hpp" |
24 | 24 | #include "lib/common/environment.hpp" |
25 | 25 | #include "lib/common/logging.hpp" |
| 26 | +#include "lib/common/static_object.hpp" |
26 | 27 | #include "lib/common/utility.hpp" |
27 | 28 | #include "lib/rocprofiler-sdk/buffer.hpp" |
28 | 29 | #include "lib/rocprofiler-sdk/context/context.hpp" |
@@ -95,6 +96,15 @@ submitPacket(hsa_queue_t* queue, const void* packet) |
95 | 96 |
|
96 | 97 | namespace |
97 | 98 | { |
| 99 | +// Tracks which queues have had set_profiler_active_on_queue called. |
| 100 | +// Accessor function avoids static initialization order issues. |
| 101 | +std::unordered_set<hsa_queue_t*>& |
| 102 | +get_queues_init() |
| 103 | +{ |
| 104 | + static auto& _v = *common::static_object<std::unordered_set<hsa_queue_t*>>::construct(); |
| 105 | + return _v; |
| 106 | +} |
| 107 | + |
98 | 108 | // Returns true if device lock should be acquired at configuration time (OLD behavior). |
99 | 109 | // Returns false if device lock should be acquired at context start time (NEW behavior, default). |
100 | 110 | bool |
@@ -260,9 +270,8 @@ init_callback_data(rocprofiler::counters::agent_callback_data& callback_data, |
260 | 270 |
|
261 | 271 | // If we do not have a completion handle, this is our first time profiling this agent. |
262 | 272 | // Setup our shared data structures. |
263 | | - static std::unordered_set<hsa_queue_t*> queues_init; |
264 | | - if(queues_init.find(callback_data.queue) != queues_init.end()) return; |
265 | | - queues_init.insert(callback_data.queue); |
| 273 | + if(get_queues_init().find(callback_data.queue) != get_queues_init().end()) return; |
| 274 | + get_queues_init().insert(callback_data.queue); |
266 | 275 |
|
267 | 276 | // Set state of the queue to allow profiling (may not be needed since AQL |
268 | 277 | // may do this in the future). |
@@ -633,6 +642,7 @@ stop_agent_ctx(const context::context* ctx) |
633 | 642 | hsa::get_core_table()->hsa_signal_destroy_fn(callback_data.start_signal); |
634 | 643 | callback_data.start_signal.handle = 0; |
635 | 644 | } |
| 645 | + get_queues_init().erase(callback_data.queue); |
636 | 646 | callback_data.packet.reset(); |
637 | 647 | callback_data.queue = nullptr; |
638 | 648 | agent->destroy_device_counting_service_queue(); |
|
0 commit comments