diff --git a/src/common/itt/CMakeLists.txt b/src/common/itt/CMakeLists.txt index 28988815fc6..54be2bda78a 100644 --- a/src/common/itt/CMakeLists.txt +++ b/src/common/itt/CMakeLists.txt @@ -4,7 +4,7 @@ set(TARGET_NAME openvino_itt) -file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.hpp") +file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.hpp" "include/*.hpp") add_library(${TARGET_NAME} STATIC ${SOURCES}) diff --git a/src/common/itt/include/openvino/function_name.hpp b/src/common/itt/include/openvino/function_name.hpp index dfe640f84db..1d527521735 100644 --- a/src/common/itt/include/openvino/function_name.hpp +++ b/src/common/itt/include/openvino/function_name.hpp @@ -10,17 +10,17 @@ #pragma once #if defined(__GNUC__) || (defined(__ICC) && (__ICC >= 600)) - #define ITT_FUNCTION_NAME __PRETTY_FUNCTION__ +# define ITT_FUNCTION_NAME __PRETTY_FUNCTION__ #elif defined(__FUNCSIG__) - #define ITT_FUNCTION_NAME __FUNCSIG__ +# define ITT_FUNCTION_NAME __FUNCSIG__ #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) - #define ITT_FUNCTION_NAME __FUNCTION__ +# define ITT_FUNCTION_NAME __FUNCTION__ #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) - #define ITT_FUNCTION_NAME __func__ +# define ITT_FUNCTION_NAME __func__ #elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* VS2015 */ - #define ITT_FUNCTION_NAME __func__ +# define ITT_FUNCTION_NAME __func__ #elif defined(__cplusplus) && (__cplusplus >= 201103) - #define ITT_FUNCTION_NAME __func__ +# define ITT_FUNCTION_NAME __func__ #else - #error "Function name is N/A" +# error "Function name is N/A" #endif diff --git a/src/common/itt/include/openvino/itt.hpp b/src/common/itt/include/openvino/itt.hpp index 836ae307ac5..0680b6cbc1c 100644 --- a/src/common/itt/include/openvino/itt.hpp +++ b/src/common/itt/include/openvino/itt.hpp @@ -17,206 +17,192 @@ #include "openvino/util/pp.hpp" /** @ingroup ov_dev_profiling - * @brief openvino namespace - */ -namespace openvino -{ - namespace itt - { - /** - * @typedef domain_t - * @ingroup ov_dev_profiling - * @brief A domain type which enables tagging trace data for different modules or libraries in a program. - */ - typedef struct domain_ {} *domain_t; + * @brief openvino namespace + */ +namespace openvino { +namespace itt { +/** + * @typedef domain_t + * @ingroup ov_dev_profiling + * @brief A domain type which enables tagging trace data for different modules or libraries in a program. + */ +typedef struct domain_ { +} * domain_t; - /** - * @typedef handle_t - * @ingroup ov_dev_profiling - * @brief Annotation handle for section of code which would be named at runtime. - */ - typedef struct handle_ {} *handle_t; +/** + * @typedef handle_t + * @ingroup ov_dev_profiling + * @brief Annotation handle for section of code which would be named at runtime. + */ +typedef struct handle_ { +} * handle_t; - /** - * @cond - */ - namespace internal - { - domain_t domain(char const* name); - handle_t handle(char const* name); - void taskBegin(domain_t d, handle_t t); - void taskEnd(domain_t d); - void threadName(const char* name); +/** + * @cond + */ +namespace internal { +domain_t domain(char const* name); +handle_t handle(char const* name); +void taskBegin(domain_t d, handle_t t); +void taskEnd(domain_t d); +void threadName(const char* name); +} // namespace internal +/** + * @endcond + */ + +/** + * @fn void threadName(const char* name) + * @ingroup ov_dev_profiling + * @brief Set thread name using a char string. + * @param name [in] The thread name + */ +inline void threadName(const char* name) { + internal::threadName(name); +} + +inline void threadName(const std::string& name) { + internal::threadName(name.c_str()); +} + +inline handle_t handle(char const* name) { + return internal::handle(name); +} + +inline handle_t handle(const std::string& name) { + return internal::handle(name.c_str()); +} + +/** + * @fn handle_t handle(char const *name) + * @ingroup ov_dev_profiling + * @brief Create annotation handle with a given name. + * @details If template function is instantiated with a tag, the handle is created as a singleton. + * @param name [in] The annotation name + */ +template +handle_t handle(char const* name) { + static auto h = internal::handle(name); + return h; +} + +template +handle_t handle(const std::string& name) { + return handle(name.c_str()); +} + +template +handle_t handle(handle_t h) { + return h; +} + +/** + * @class ScopedTask + * @ingroup ov_dev_profiling + * @brief Used to annotate section of code which would be named at runtime + * @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro. + */ +template +struct ScopedTask { + /** + * @brief Construct ScopedTask with defined annotation handle + */ + ScopedTask(handle_t taskHandle) noexcept { + internal::taskBegin(domain(), taskHandle); + } + + /** + * @brief The ScopedTask destructor closes or ends the task scope + */ + ~ScopedTask() noexcept { + internal::taskEnd(domain()); + } + + ScopedTask(const ScopedTask&) = delete; + ScopedTask& operator=(const ScopedTask&) = delete; +}; + +/** + * @class TaskChain + * @ingroup ov_dev_profiling + * @brief Used to annotate a sequence of sections of code which would be named at runtime + * @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro. + */ +template +class TaskChain { + uint32_t _id = 1; + std::string _prefix; + bool _skipped{}; + + TaskChain(const TaskChain&) = delete; + TaskChain& operator=(const TaskChain&) = delete; + +public: + /** + * @brief Construct TaskChain with defined annotation handle + */ + TaskChain(handle_t taskHandle, std::string&& prefix) noexcept : _prefix(std::forward(prefix)) { + internal::taskBegin(domain(), taskHandle); + } + + /** + * @brief The TaskChain destructor closes or ends the task scope + */ + ~TaskChain() noexcept { + skip(); + } + + /** + * @brief Ends the previous task from the chain and starts a new one with the given annotation handle + */ + void next(handle_t taskHandle) { + if (_skipped) + _skipped = false; + else + internal::taskEnd(domain()); + internal::taskBegin(domain(), taskHandle); + ++_id; + } + + /* + * @brief Generating a task name using a sequence number. + */ + std::string taskName() const { + return _prefix + "_" + std::to_string(_id); + } + + /* + * @brief Generating a task name using a scope name. + */ + std::string taskNameOrHandle(const std::string& name) const { + return _prefix + "_" + name; + } + + /* + * @brief Returns a handle provided as argument. + */ + handle_t taskNameOrHandle(handle_t handle) const { + return handle; + } + + /* + * @brief Skips the remaining task scope. + */ + void skip() { + if (!_skipped) { + _skipped = true; + internal::taskEnd(domain()); } - /** - * @endcond - */ - - /** - * @fn void threadName(const char* name) - * @ingroup ov_dev_profiling - * @brief Set thread name using a char string. - * @param name [in] The thread name - */ - inline void threadName(const char* name) - { - internal::threadName(name); - } - - inline void threadName(const std::string &name) - { - internal::threadName(name.c_str()); - } - - inline handle_t handle(char const *name) - { - return internal::handle(name); - } - - inline handle_t handle(const std::string &name) - { - return internal::handle(name.c_str()); - } - - /** - * @fn handle_t handle(char const *name) - * @ingroup ov_dev_profiling - * @brief Create annotation handle with a given name. - * @details If template function is instantiated with a tag, the handle is created as a singleton. - * @param name [in] The annotation name - */ - template - handle_t handle(char const *name) - { - static auto h = internal::handle(name); - return h; - } - - template - handle_t handle(const std::string &name) - { - return handle(name.c_str()); - } - - template - handle_t handle(handle_t h) - { - return h; - } - - /** - * @class ScopedTask - * @ingroup ov_dev_profiling - * @brief Used to annotate section of code which would be named at runtime - * @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro. - */ - template - struct ScopedTask - { - /** - * @brief Construct ScopedTask with defined annotation handle - */ - ScopedTask(handle_t taskHandle) noexcept - { - internal::taskBegin(domain(), taskHandle); - } - - /** - * @brief The ScopedTask destructor closes or ends the task scope - */ - ~ScopedTask() noexcept { internal::taskEnd(domain()); } - - ScopedTask(const ScopedTask&) = delete; - ScopedTask& operator=(const ScopedTask&) = delete; - }; - - /** - * @class TaskChain - * @ingroup ov_dev_profiling - * @brief Used to annotate a sequence of sections of code which would be named at runtime - * @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro. - */ - template - class TaskChain - { - uint32_t _id = 1; - std::string _prefix; - bool _skipped {}; - - TaskChain(const TaskChain&) = delete; - TaskChain& operator=(const TaskChain&) = delete; - - public: - /** - * @brief Construct TaskChain with defined annotation handle - */ - TaskChain(handle_t taskHandle, std::string && prefix) noexcept - : _prefix(std::forward(prefix)) - { - internal::taskBegin(domain(), taskHandle); - } - - /** - * @brief The TaskChain destructor closes or ends the task scope - */ - ~TaskChain() noexcept { skip(); } - - /** - * @brief Ends the previous task from the chain and starts a new one with the given annotation handle - */ - void next(handle_t taskHandle) - { - if(_skipped) - _skipped = false; - else - internal::taskEnd(domain()); - internal::taskBegin(domain(), taskHandle); - ++_id; - } - - /* - * @brief Generating a task name using a sequence number. - */ - std::string taskName() const - { - return _prefix + "_" + std::to_string(_id); - } - - /* - * @brief Generating a task name using a scope name. - */ - std::string taskNameOrHandle(const std::string & name) const - { - return _prefix + "_" + name; - } - - /* - * @brief Returns a handle provided as argument. - */ - handle_t taskNameOrHandle(handle_t handle) const - { - return handle; - } - - /* - * @brief Skips the remaining task scope. - */ - void skip() - { - if(!_skipped) - { - _skipped = true; - internal::taskEnd(domain()); - } - } - }; + } +}; /** * @def OV_ITT_DOMAIN(domainName) * @ingroup ov_dev_profiling * @brief Declare domain with a given name. * @param domainName [in] Known at compile time name of module or library (the domain name). - * @param domainDisplayName [in] Domain name used as the ITT counter name and displayed in Intel VTune. Parameter is optional. + * @param domainDisplayName [in] Domain name used as the ITT counter name and displayed in Intel VTune. Parameter is + * optional. */ #define OV_ITT_DOMAIN(...) OV_PP_OVERLOAD(OV_ITT_DOMAIN, __VA_ARGS__) @@ -226,19 +212,17 @@ namespace openvino * @cond */ -#define OV_ITT_DOMAIN_1(domainName) \ -inline openvino::itt::domain_t domainName() noexcept \ -{ \ - static auto d = openvino::itt::internal::domain(#domainName); \ - return d; \ -} +#define OV_ITT_DOMAIN_1(domainName) \ + inline openvino::itt::domain_t domainName() noexcept { \ + static auto d = openvino::itt::internal::domain(#domainName); \ + return d; \ + } -#define OV_ITT_DOMAIN_2(domainName, domainDisplayName) \ -inline openvino::itt::domain_t domainName() noexcept \ -{ \ - static auto d = openvino::itt::internal::domain(domainDisplayName); \ - return d; \ -} +#define OV_ITT_DOMAIN_2(domainName, domainDisplayName) \ + inline openvino::itt::domain_t domainName() noexcept { \ + static auto d = openvino::itt::internal::domain(domainDisplayName); \ + return d; \ + } /** * @endcond @@ -253,7 +237,7 @@ inline openvino::itt::domain_t domainName() noexcept * @param domainName [in] Known at compile time name of module or library (the domain name). * @param handleOrTaskName [in] The annotation name or handle for section of code. Parameter is optional. */ -#define OV_ITT_SCOPE(group, ...) \ +#define OV_ITT_SCOPE(group, ...) \ OV_PP_EXPAND(OV_PP_CAT(OV_ITT_SCOPE_IMPL_, OV_PP_IS_ENABLED(OV_ITT_GROUP(group)))(__VA_ARGS__)) /** @@ -263,13 +247,13 @@ inline openvino::itt::domain_t domainName() noexcept #define OV_ITT_SCOPE_IMPL_0(...) #define OV_ITT_SCOPE_IMPL_1(...) OV_PP_OVERLOAD(OV_ITT_SCOPE, __VA_ARGS__) -#define OV_ITT_SCOPE_1(domain) \ - openvino::itt::ScopedTask OV_PP_CAT(ittScopedTask, __LINE__) \ - (openvino::itt::handle(ITT_FUNCTION_NAME)); +#define OV_ITT_SCOPE_1(domain) \ + openvino::itt::ScopedTask OV_PP_CAT(ittScopedTask, __LINE__)( \ + openvino::itt::handle(ITT_FUNCTION_NAME)); -#define OV_ITT_SCOPE_2(domain, taskOrTaskName) \ - openvino::itt::ScopedTask OV_PP_CAT(ittScopedTask, __LINE__) \ - (openvino::itt::handle(taskOrTaskName)); +#define OV_ITT_SCOPE_2(domain, taskOrTaskName) \ + openvino::itt::ScopedTask OV_PP_CAT(ittScopedTask, __LINE__)( \ + openvino::itt::handle(taskOrTaskName)); /** * @endcond @@ -297,7 +281,7 @@ inline openvino::itt::domain_t domainName() noexcept * @param prefix [in] The task chain name prefix. The task name starts with this prefix. Parameter is optional. * @param taskName [in] The annotation name for section of code. Parameter is optional. */ -#define OV_ITT_SCOPE_CHAIN(group, ...) \ +#define OV_ITT_SCOPE_CHAIN(group, ...) \ OV_PP_EXPAND(OV_PP_CAT(OV_ITT_SCOPE_CHAIN_IMPL_, OV_PP_IS_ENABLED(OV_ITT_GROUP(group)))(__VA_ARGS__)) /** @@ -307,23 +291,20 @@ inline openvino::itt::domain_t domainName() noexcept #define OV_ITT_SCOPE_CHAIN_IMPL_0(...) #define OV_ITT_SCOPE_CHAIN_IMPL_1(...) OV_PP_OVERLOAD(OV_ITT_SCOPE_CHAIN, __VA_ARGS__) -#define OV_ITT_SCOPE_CHAIN_2(chainId, domain) \ - openvino::itt::TaskChain chainId \ - (openvino::itt::handle \ - (std::string(ITT_FUNCTION_NAME) + "_1"), \ - ITT_FUNCTION_NAME); +#define OV_ITT_SCOPE_CHAIN_2(chainId, domain) \ + openvino::itt::TaskChain chainId( \ + openvino::itt::handle(std::string(ITT_FUNCTION_NAME) + "_1"), \ + ITT_FUNCTION_NAME); -#define OV_ITT_SCOPE_CHAIN_3(chainId, domain, prefix) \ - openvino::itt::TaskChain chainId \ - (openvino::itt::handle \ - (std::string(prefix) + "_1"), \ - prefix); +#define OV_ITT_SCOPE_CHAIN_3(chainId, domain, prefix) \ + openvino::itt::TaskChain chainId( \ + openvino::itt::handle(std::string(prefix) + "_1"), \ + prefix); -#define OV_ITT_SCOPE_CHAIN_4(chainId, domain, prefix, taskName) \ - openvino::itt::TaskChain chainId \ - (openvino::itt::handle \ - (std::string(prefix) + "_" + taskName), \ - prefix); +#define OV_ITT_SCOPE_CHAIN_4(chainId, domain, prefix, taskName) \ + openvino::itt::TaskChain chainId( \ + openvino::itt::handle(std::string(prefix) + "_" + taskName), \ + prefix); /** * @endcond @@ -338,7 +319,7 @@ inline openvino::itt::domain_t domainName() noexcept * @param chainId [in] The tasks chain identifier. * @param taskOrTaskName [in] The annotation name or handle for section of code. Parameter is optional. */ -#define OV_ITT_SCOPE_NEXT(group, ...) \ +#define OV_ITT_SCOPE_NEXT(group, ...) \ OV_PP_EXPAND(OV_PP_CAT(OV_ITT_SCOPE_NEXT_IMPL_, OV_PP_IS_ENABLED(OV_ITT_GROUP(group)))(__VA_ARGS__)) /** @@ -348,11 +329,11 @@ inline openvino::itt::domain_t domainName() noexcept #define OV_ITT_SCOPE_NEXT_IMPL_0(...) #define OV_ITT_SCOPE_NEXT_IMPL_1(...) OV_PP_OVERLOAD(OV_ITT_SCOPE_NEXT, __VA_ARGS__) -#define OV_ITT_SCOPE_NEXT_1(chainId) \ - chainId.next(openvino::itt::handle(chainId.taskName())); +#define OV_ITT_SCOPE_NEXT_1(chainId) \ + chainId.next(openvino::itt::handle(chainId.taskName())); -#define OV_ITT_SCOPE_NEXT_2(chainId, taskOrTaskName) \ - chainId.next(openvino::itt::handle(chainId.taskNameOrHandle(taskOrTaskName))); +#define OV_ITT_SCOPE_NEXT_2(chainId, taskOrTaskName) \ + chainId.next(openvino::itt::handle(chainId.taskNameOrHandle(taskOrTaskName))); /** * @endcond @@ -365,7 +346,7 @@ inline openvino::itt::domain_t domainName() noexcept * @param group [in] ITT counter group name used for enabling/disabling at compile time. * @param chainId [in] The tasks chain identifier. */ -#define OV_ITT_SCOPE_SKIP(group, chainId) \ +#define OV_ITT_SCOPE_SKIP(group, chainId) \ OV_PP_EXPAND(OV_PP_CAT(OV_ITT_SCOPE_SKIP_, OV_PP_IS_ENABLED(OV_ITT_GROUP(group)))(chainId)) /** @@ -410,5 +391,5 @@ inline openvino::itt::domain_t domainName() noexcept */ #define OV_ITT_TASK_SKIP(chainId) OV_ITT_SCOPE_SKIP(ALL, chainId); - } // namespace itt -} // namespace openvino +} // namespace itt +} // namespace openvino