Enable clang format for itt headers (#19326)

This commit is contained in:
Ilya Churaev 2023-08-23 15:13:59 +04:00 committed by GitHub
parent dcfb6bb042
commit bc868a8873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 223 additions and 242 deletions

View File

@ -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})

View File

@ -19,35 +19,34 @@
/** @ingroup ov_dev_profiling
* @brief openvino namespace
*/
namespace openvino
{
namespace itt
{
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 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 struct handle_ {
} * handle_t;
/**
* @cond
*/
namespace internal
{
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
*/
@ -58,23 +57,19 @@ namespace openvino
* @brief Set thread name using a char string.
* @param name [in] The thread name
*/
inline void threadName(const char* name)
{
inline void threadName(const char* name) {
internal::threadName(name);
}
inline void threadName(const std::string &name)
{
inline void threadName(const std::string& name) {
internal::threadName(name.c_str());
}
inline handle_t handle(char const *name)
{
inline handle_t handle(char const* name) {
return internal::handle(name);
}
inline handle_t handle(const std::string &name)
{
inline handle_t handle(const std::string& name) {
return internal::handle(name.c_str());
}
@ -86,21 +81,18 @@ namespace openvino
* @param name [in] The annotation name
*/
template <typename Tag>
handle_t handle(char const *name)
{
handle_t handle(char const* name) {
static auto h = internal::handle(name);
return h;
}
template <typename Tag>
handle_t handle(const std::string &name)
{
handle_t handle(const std::string& name) {
return handle<Tag>(name.c_str());
}
template <typename Tag>
handle_t handle(handle_t h)
{
handle_t handle(handle_t h) {
return h;
}
@ -111,20 +103,20 @@ namespace openvino
* @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro.
*/
template <domain_t (*domain)()>
struct ScopedTask
{
struct ScopedTask {
/**
* @brief Construct ScopedTask with defined annotation handle
*/
ScopedTask(handle_t taskHandle) noexcept
{
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() noexcept {
internal::taskEnd(domain());
}
ScopedTask(const ScopedTask&) = delete;
ScopedTask& operator=(const ScopedTask&) = delete;
@ -137,8 +129,7 @@ namespace openvino
* @tparam The @p domain parameter is domain type which shoud be defined with OV_ITT_DOMAIN() macro.
*/
template <domain_t (*domain)()>
class TaskChain
{
class TaskChain {
uint32_t _id = 1;
std::string _prefix;
bool _skipped{};
@ -150,22 +141,21 @@ namespace openvino
/**
* @brief Construct TaskChain with defined annotation handle
*/
TaskChain(handle_t taskHandle, std::string && prefix) noexcept
: _prefix(std::forward<std::string>(prefix))
{
TaskChain(handle_t taskHandle, std::string&& prefix) noexcept : _prefix(std::forward<std::string>(prefix)) {
internal::taskBegin(domain(), taskHandle);
}
/**
* @brief The TaskChain destructor closes or ends the task scope
*/
~TaskChain() noexcept { skip(); }
~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)
{
void next(handle_t taskHandle) {
if (_skipped)
_skipped = false;
else
@ -177,34 +167,29 @@ namespace openvino
/*
* @brief Generating a task name using a sequence number.
*/
std::string taskName() const
{
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
{
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
{
handle_t taskNameOrHandle(handle_t handle) const {
return handle;
}
/*
* @brief Skips the remaining task scope.
*/
void skip()
{
if(!_skipped)
{
void skip() {
if (!_skipped) {
_skipped = true;
internal::taskEnd(domain());
}
@ -216,7 +201,8 @@ namespace openvino
* @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__)
@ -227,15 +213,13 @@ namespace openvino
*/
#define OV_ITT_DOMAIN_1(domainName) \
inline openvino::itt::domain_t domainName() noexcept \
{ \
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 \
{ \
inline openvino::itt::domain_t domainName() noexcept { \
static auto d = openvino::itt::internal::domain(domainDisplayName); \
return d; \
}
@ -264,12 +248,12 @@ inline openvino::itt::domain_t domainName() noexcept
#define OV_ITT_SCOPE_IMPL_1(...) OV_PP_OVERLOAD(OV_ITT_SCOPE, __VA_ARGS__)
#define OV_ITT_SCOPE_1(domain) \
openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__) \
(openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(ITT_FUNCTION_NAME));
openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__)( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(ITT_FUNCTION_NAME));
#define OV_ITT_SCOPE_2(domain, taskOrTaskName) \
openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__) \
(openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(taskOrTaskName));
openvino::itt::ScopedTask<domain> OV_PP_CAT(ittScopedTask, __LINE__)( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(taskOrTaskName));
/**
* @endcond
@ -308,21 +292,18 @@ inline openvino::itt::domain_t domainName() noexcept
#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<domain> chainId \
(openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)> \
(std::string(ITT_FUNCTION_NAME) + "_1"), \
openvino::itt::TaskChain<domain> chainId( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(std::string(ITT_FUNCTION_NAME) + "_1"), \
ITT_FUNCTION_NAME);
#define OV_ITT_SCOPE_CHAIN_3(chainId, domain, prefix) \
openvino::itt::TaskChain<domain> chainId \
(openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)> \
(std::string(prefix) + "_1"), \
openvino::itt::TaskChain<domain> chainId( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(std::string(prefix) + "_1"), \
prefix);
#define OV_ITT_SCOPE_CHAIN_4(chainId, domain, prefix, taskName) \
openvino::itt::TaskChain<domain> chainId \
(openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)> \
(std::string(prefix) + "_" + taskName), \
openvino::itt::TaskChain<domain> chainId( \
openvino::itt::handle<struct OV_PP_CAT(Task, __LINE__)>(std::string(prefix) + "_" + taskName), \
prefix);
/**