Instrumentor

- 'Instrumentor' now tracks the sessionn's submit count
- 'Instrumentor::SubmitScopeProfileImpl' no longer uses a static variable
This commit is contained in:
Light 2021-07-14 00:16:10 +04:30
parent cd30d0bba1
commit 44b135f157
2 changed files with 10 additions and 8 deletions

View file

@ -11,6 +11,7 @@ namespace Light {
} }
Instrumentor::Instrumentor() Instrumentor::Instrumentor()
: m_CurrentSessionCount(0u)
{ {
// #todo: maintenance // #todo: maintenance
LT_ENGINE_ASSERT(!s_Context, "Instrumentor::Instrumentor: an instance of 'Instrumentor' already exists, do not construct this class!"); LT_ENGINE_ASSERT(!s_Context, "Instrumentor::Instrumentor: an instance of 'Instrumentor' already exists, do not construct this class!");
@ -25,6 +26,11 @@ namespace Light {
void Instrumentor::EndSessionImpl() void Instrumentor::EndSessionImpl()
{ {
if (m_CurrentSessionCount == 0u)
LT_ENGINE_WARN("Instrumentor::EndSessionImpl: 0 profiling for the ended session");
m_CurrentSessionCount = 0u;
m_OutputFileStream << "]}"; m_OutputFileStream << "]}";
m_OutputFileStream.flush(); m_OutputFileStream.flush();
m_OutputFileStream.close(); m_OutputFileStream.close();
@ -32,14 +38,9 @@ namespace Light {
void Instrumentor::SubmitScopeProfileImpl(const ScopeProfileResult& profileResult) void Instrumentor::SubmitScopeProfileImpl(const ScopeProfileResult& profileResult)
{ {
static bool test = true; if (m_CurrentSessionCount++ == 0u)
if (test)
{
test = false;
m_OutputFileStream << "{"; m_OutputFileStream << "{";
} else
else
m_OutputFileStream << ",{"; m_OutputFileStream << ",{";
m_OutputFileStream << "\"name\":\"" << profileResult.name << "\","; m_OutputFileStream << "\"name\":\"" << profileResult.name << "\",";

View file

@ -21,7 +21,8 @@ namespace Light {
static Instrumentor* s_Context; static Instrumentor* s_Context;
std::ofstream m_OutputFileStream; std::ofstream m_OutputFileStream;
bool m_FirstScopeProfile = true;
unsigned int m_CurrentSessionCount;
public: public:
static Instrumentor* Create(); static Instrumentor* Create();