-
-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced profiling instrumentation
- Loading branch information
Showing
10 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#include "config.h" | ||
#include <cstdio> | ||
#include <string> | ||
|
||
#ifdef WZ_PROFILING_NVTX | ||
#include <nvtx3/nvToolsExt.h> | ||
#endif | ||
|
||
#ifdef WZ_PROFILING_VTUNE | ||
#include <ittnotify.h> | ||
#endif | ||
|
||
#include "profiling.h" | ||
|
||
namespace profiling | ||
{ | ||
|
||
struct Domain::Internal | ||
{ | ||
#ifdef WZ_PROFILING_NVTX | ||
nvtxDomainHandle_t nvtxDomain = nullptr; | ||
#endif | ||
|
||
#ifdef WZ_PROFILING_VTUNE | ||
__itt_domain* ittDomain = nullptr; | ||
#endif | ||
std::string name; | ||
|
||
~Internal() | ||
{ | ||
#ifdef WZ_PROFILING_NVTX | ||
if (nvtxDomain) | ||
{ | ||
nvtxDomainDestroy(nvtxDomain); | ||
nvtxDomain = nullptr; | ||
} | ||
#endif | ||
} | ||
}; | ||
|
||
Domain::Domain(const char* name) | ||
{ | ||
m_internal = new Internal(); | ||
m_internal->name = name ? name : "Unnamed"; | ||
#ifdef WZ_PROFILING_NVTX | ||
m_internal->nvtxDomain = nvtxDomainCreateA(name); | ||
#endif | ||
|
||
#ifdef WZ_PROFILING_VTUNE | ||
m_internal->ittDomain = __itt_domain_create(name); | ||
#endif | ||
} | ||
|
||
Domain::~Domain() | ||
{ | ||
if (m_internal) | ||
{ | ||
delete m_internal; | ||
m_internal = nullptr; | ||
} | ||
} | ||
|
||
Domain wzRootDomain{"warzone2100"}; | ||
|
||
Scope::Scope(const Domain *domain, const char *name) | ||
:m_domain(domain) | ||
{ | ||
if (domain && name) | ||
{ | ||
#ifdef WZ_PROFILING_NVTX | ||
{ | ||
nvtxRangePushA(name); | ||
} | ||
#endif | ||
#ifdef WZ_PROFILING_VTUNE | ||
{ | ||
__itt_string_handle* task = __itt_string_handle_create(name); | ||
auto ittDomain = m_domain ? m_domain->getInternal()->ittDomain : nullptr; | ||
__itt_task_begin(ittDomain, __itt_null, __itt_null, task); | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
Scope::Scope(const Domain *domain, const char *object, const char *name) | ||
:m_domain(domain) | ||
{ | ||
if (m_domain && object && name) | ||
{ | ||
static char tmpBuffer[255]; | ||
std::snprintf(tmpBuffer, sizeof(tmpBuffer), "%s::%s", object, name); | ||
#ifdef WZ_PROFILING_NVTX | ||
{ | ||
nvtxRangePushA(tmpBuffer); | ||
} | ||
#endif | ||
#ifdef WZ_PROFILING_VTUNE | ||
{ | ||
__itt_string_handle* task = __itt_string_handle_create(tmpBuffer); | ||
auto ittDomain = m_domain ? m_domain->getInternal()->ittDomain : nullptr; | ||
__itt_task_begin(ittDomain, __itt_null, __itt_null, task); | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
Scope::~Scope() | ||
{ | ||
if (m_domain) { | ||
#ifdef WZ_PROFILING_NVTX | ||
nvtxRangePop(); | ||
#endif | ||
#ifdef WZ_PROFILING_VTUNE | ||
auto ittDomain = m_domain->getInternal()->ittDomain; | ||
__itt_task_end(ittDomain); | ||
#endif | ||
} | ||
} | ||
|
||
void mark(const Domain *domain, const char *mark) | ||
{ | ||
if (!domain || !mark) | ||
return; | ||
#ifdef WZ_PROFILING_NVTX | ||
{ | ||
nvtxEventAttributes_t eventAttrib = {}; | ||
eventAttrib.version = NVTX_VERSION; | ||
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; | ||
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; | ||
eventAttrib.message.ascii = mark; | ||
auto nvtxDomain = domain ? domain->getInternal()->nvtxDomain : nullptr; | ||
nvtxDomainMarkEx(nvtxDomain, &eventAttrib); | ||
} | ||
#endif | ||
#ifdef WZ_PROFILING_VTUNE | ||
auto string = __itt_string_handle_create(mark); | ||
auto ittDomain = domain ? domain->getInternal()->ittDomain : nullptr; | ||
__itt_marker(ittDomain, __itt_null, string, __itt_scope::__itt_scope_task); | ||
#endif | ||
} | ||
|
||
void mark(const Domain *domain, const char *object, const char *mark) | ||
{ | ||
if (!domain || !object || !mark) | ||
return; | ||
static char tmpBuffer[255]; | ||
std::snprintf(tmpBuffer, sizeof(tmpBuffer), "%s::%s", object, mark); | ||
|
||
#ifdef WZ_PROFILING_NVTX | ||
{ | ||
nvtxEventAttributes_t eventAttrib = {}; | ||
eventAttrib.version = NVTX_VERSION; | ||
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; | ||
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; | ||
eventAttrib.message.ascii = tmpBuffer; | ||
auto nvtxDomain = domain ? domain->getInternal()->nvtxDomain : nullptr; | ||
nvtxDomainMarkEx(nvtxDomain, &eventAttrib); | ||
} | ||
#endif | ||
#ifdef WZ_PROFILING_VTUNE | ||
{ | ||
auto string = __itt_string_handle_create(msg.c_str()); | ||
auto ittDomain = domain ? domain->getInternal()->ittDomain : nullptr; | ||
__itt_marker(ittDomain, __itt_null, string, __itt_scope::__itt_scope_task); | ||
} | ||
#endif | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef __INCLUDED_SRC_PROFILING_H__ | ||
#define __INCLUDED_SRC_PROFILING_H__ | ||
|
||
#include <ctime> | ||
#include <cstdint> | ||
|
||
namespace profiling { | ||
|
||
/// Application-level profiling domain. | ||
/// It is often created only once per application or per large component. | ||
class Domain | ||
{ | ||
public: | ||
struct Internal; | ||
|
||
explicit Domain(const char* name); | ||
~Domain(); | ||
|
||
const Internal* getInternal() const { | ||
return m_internal; | ||
} | ||
private: | ||
Internal* m_internal; | ||
// Some additional opaque data for implementation. | ||
void* m_domain = nullptr; | ||
}; | ||
|
||
/// Profiling scope. | ||
/// Instrumentation backend will create starting mark when the scope is entered | ||
/// and finishing mark when scope is left. | ||
class Scope | ||
{ | ||
public: | ||
Scope(const Domain* domain, const char* name); | ||
Scope(const Domain* domain, const char* object, const char* name); | ||
~Scope(); | ||
|
||
double elapsed() const; | ||
private: | ||
timespec m_prevTimeStamp; | ||
const Domain* m_domain = nullptr; | ||
uint64_t m_backendRangeId = 0; | ||
}; | ||
|
||
extern Domain wzRootDomain; | ||
} | ||
|
||
#define WZ_PROFILE_SCOPE(name) profiling::Scope mark_##name(&profiling::wzRootDomain, #name); | ||
#define WZ_PROFILE_SCOPE2(object, name) profiling::Scope mark_##name(&profiling::wzRootDomain, #object, #name); | ||
|
||
#endif // __INCLUDED_SRC_PROFILING_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters