Skip to content

Commit 619a766

Browse files
[CPU] Avoid creating itt structs when not collected (#32778)
PR to the main branch: - #32764
1 parent a882ce0 commit 619a766

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/common/itt/include/openvino/itt.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct handle_ {
4141
* @cond
4242
*/
4343
namespace internal {
44+
bool is_initialized();
4445
domain_t domain(const char* name);
4546
handle_t handle(const char* name);
4647
void taskBegin(domain_t d, handle_t t);

src/common/itt/src/itt.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace internal {
2121

2222
static __itt_collection_state state = __itt_get_collection_state();
2323

24-
static inline bool is_initialized() {
24+
bool is_initialized() {
2525
return state == __itt_collection_init_successful;
2626
}
2727

@@ -110,6 +110,10 @@ void regionEnd(domain_t d) {
110110

111111
#else
112112

113+
bool is_initialized() {
114+
return false;
115+
}
116+
113117
domain_t domain(const char*) {
114118
return nullptr;
115119
}

src/plugins/intel_cpu/src/itt.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ namespace ov::intel_cpu::itt {
2929

3030
class ScopedOpExecTask {
3131
public:
32-
explicit ScopedOpExecTask(const char* name) noexcept : ScopedOpExecTask(openvino::itt::handle(name)) {}
33-
explicit ScopedOpExecTask(const std::string& name) noexcept : ScopedOpExecTask(name.c_str()) {}
34-
explicit ScopedOpExecTask(openvino::itt::handle_t handle) noexcept : m_handle(handle) {
35-
openvino::itt::internal::taskBegin(::ov::itt::domains::ov_op_exec(), m_handle);
32+
explicit ScopedOpExecTask(const char* name) noexcept {
33+
if (openvino::itt::internal::is_initialized()) {
34+
m_handle = openvino::itt::handle(name);
35+
openvino::itt::internal::taskBegin(::ov::itt::domains::ov_op_exec(), m_handle);
36+
}
3637
}
38+
explicit ScopedOpExecTask(const std::string& name) noexcept : ScopedOpExecTask(name.c_str()) {}
3739
~ScopedOpExecTask() noexcept {
38-
openvino::itt::internal::taskEnd(::ov::itt::domains::ov_op_exec());
40+
if (openvino::itt::internal::is_initialized()) {
41+
openvino::itt::internal::taskEnd(::ov::itt::domains::ov_op_exec());
42+
}
3943
}
4044

4145
ScopedOpExecTask(const ScopedOpExecTask&) = delete;

0 commit comments

Comments
 (0)