Deprecate profiler categories based on global enum

(to be supplanted by registered budgets in the future)

Signed-off-by: Jeremy Ong <jcong@amazon.com>
This commit is contained in:
Jeremy Ong
2021-08-17 12:10:57 -06:00
parent d15d40fec6
commit df9b4d4a2f
274 changed files with 1435 additions and 1965 deletions
+3 -4
View File
@@ -1244,19 +1244,18 @@ namespace UnitTest
int ChildFunction(int input)
{
AZ_PROFILE_TIMER("UnitTest", nullptr, NamedRegister);
AZ_PROFILE_FUNCTION(System);
int result = 5;
for (int i = 0; i < 10000; ++i)
{
result += i % (input + 3);
}
AZ_PROFILE_TIMER_END(NamedRegister);
return result;
}
int ChildFunction1(int input)
{
AZ_PROFILE_TIMER("UnitTest", "Child1");
AZ_PROFILE_SCOPE(System, "Child1");
int result = 5;
for (int i = 0; i < 10000; ++i)
{
@@ -1267,7 +1266,7 @@ namespace UnitTest
int Profile1(int numIterations)
{
AZ_PROFILE_TIMER("UnitTest", "Custom name");
AZ_PROFILE_SCOPE(System, "Custom name");
int result = 0;
for (int i = 0; i < numIterations; ++i)
{
-270
View File
@@ -171,276 +171,6 @@ namespace UnitTest
run();
}
class ProfilerTest
: public AllocatorsFixture
{
public:
int m_numRegistersReceived;
bool ReadRegisterCallback(const ProfilerRegister& reg, const AZStd::thread_id& id)
{
(void)reg;
(void)id;
switch (reg.m_type)
{
case ProfilerRegister::PRT_TIME:
{
AZ_TEST_ASSERT(reg.m_timeData.m_time > 0);
AZ_TEST_ASSERT(reg.m_timeData.m_calls > 0);
} break;
case ProfilerRegister::PRT_VALUE:
{
AZ_TEST_ASSERT(reg.m_userValues.m_value1 == 1 || reg.m_userValues.m_value1 == 2);
AZ_TEST_ASSERT(reg.m_userValues.m_value2 == 0 || reg.m_userValues.m_value2 == 2 || reg.m_userValues.m_value2 == 4);
AZ_TEST_ASSERT(reg.m_userValues.m_value3 == 0 || reg.m_userValues.m_value3 == 3 || reg.m_userValues.m_value3 == 6);
AZ_TEST_ASSERT(reg.m_userValues.m_value4 == 0 || reg.m_userValues.m_value4 == 4 || reg.m_userValues.m_value4 == 8);
AZ_TEST_ASSERT(reg.m_userValues.m_value5 == 0 || reg.m_userValues.m_value5 == 5 || reg.m_userValues.m_value5 == 10);
} break;
}
//AZ::u64 threadId = (AZ::u64)id.m_id;
//AZ_TracePrintf("Profiler","[%llu] '%s' '%s'(%d) %d Ms (Child calls: %d time: %d Ms) Parent: '%s'!\n",threadId,
// reg.m_name,reg.m_function,reg.m_line,reg.m_time.count(),reg.m_childrenCalls,reg.m_childrenTime.count(),reg.m_lastParent ? reg.m_lastParent->m_name : "No");
++m_numRegistersReceived;
return true;
}
int ChildFunction(int input)
{
AZ_PROFILE_TIMER("UnitTest");
auto start = AZStd::chrono::system_clock::now();
int result = 5;
for (int i = 0; i < 30000; ++i)
{
result += i % (input + 3);
}
auto end = AZStd::chrono::system_clock::now();
AZ_TEST_ASSERT(end >= start);
while (end <= start)
{
end = AZStd::chrono::system_clock::now();
}
return result;
}
int ChildFunction1(int input)
{
AZ_PROFILE_TIMER("UnitTest", "Child1");
auto start = AZStd::chrono::system_clock::now();
int result = 5;
for (int i = 0; i < 30000; ++i)
{
result += i % (input + 1);
}
auto end = AZStd::chrono::system_clock::now();
AZ_TEST_ASSERT(end >= start);
while (end <= start)
{
end = AZStd::chrono::system_clock::now();
}
return result;
}
int Profile1(int numIterations)
{
AZ_PROFILE_TIMER("UnitTest", "Custom name");
int result = 0;
for (int i = 0; i < numIterations; ++i)
{
result += ChildFunction(i);
}
result += ChildFunction1(numIterations / 3);
return result;
}
void UserValuesSet()
{
AZ_PROFILE_VALUE_SET("UnitTest", "UserValues1", 1);
AZ_PROFILE_VALUE_SET("UnitTest", "UserValues2", 1, 2);
AZ_PROFILE_VALUE_SET("UnitTest", "UserValues3", 1, 2, 3);
AZ::s64 v1 = 1, v2 = 2, v3 = 3, v4 = 4, v5 = 5;
AZ_PROFILE_VALUE_SET("UnitTest", "UserValues4", v1, v2, v3, v4);
AZ_PROFILE_VALUE_SET("UnitTest", "UserValues5", v1, v2, v3, v4, v5);
// test named register
AZ_PROFILE_VALUE_SET_NAMED("UnitTest", "UserValues5", userValues5, v1, v2, v3, v4, v5);
#if defined(AZ_PROFILER_MACRO_DISABLE)
(void)v1;
(void)v2;
(void)v3;
(void)v4;
(void)v5;
#else
AZ_TEST_ASSERT(userValues5 != nullptr);
#endif // !defined(AZ_PROFILER_MACRO_DISABLE)
}
void UserValuesAdd(int numAdditions)
{
for (int i = 0; i < numAdditions; ++i)
{
AZ_PROFILE_VALUE_ADD("UnitTest", "UserValues1", 1);
AZ_PROFILE_VALUE_ADD("UnitTest", "UserValues2", 1, 2);
AZ_PROFILE_VALUE_ADD("UnitTest", "UserValues3", 1, 2, 3);
AZ::s64 v1 = 1, v2 = 2, v3 = 3, v4 = 4, v5 = 5;
AZ_PROFILE_VALUE_ADD("UnitTest", "UserValues4", v1, v2, v3, v4);
AZ_PROFILE_VALUE_ADD("UnitTest", "UserValues5", v1, v2, v3, v4, v5);
// test named register
AZ_PROFILE_VALUE_ADD_NAMED("UnitTest", "UserValues5", userValues5, v1, v2, v3, v4, v5);
#if defined(AZ_PROFILER_MACRO_DISABLE)
(void)v1;
(void)v2;
(void)v3;
(void)v4;
(void)v5;
#else
AZ_TEST_ASSERT(userValues5 != nullptr);
#endif // !defined(AZ_PROFILER_MACRO_DISABLE)
}
}
void run()
{
AZ_TEST_ASSERT(!Profiler::IsReady());
Profiler::Create();
AZ_TEST_ASSERT(Profiler::IsReady());
Profiler::Destroy();
AZ_TEST_ASSERT(!Profiler::IsReady());
#if !defined(AZ_PROFILER_MACRO_DISABLE)
Profiler::Create();
//Profile1();
//Profiler::Instance().ReadRegisterValues(AZStd::bind(&ProfilerTest::ReadRegisterCallback,this,AZStd::placeholders::_1,AZStd::placeholders::_2));
//Profiler::Instance().ResetRegisters();
AZStd::thread_id removeThreadId;
AZStd::chrono::microseconds elapsed[2];
int numIterations = 10000;
for (int i = 0; i < 2; ++i)
{
// for the second run we should not record any data
if (i == 1)
{
Profiler::Instance().DeactivateSystem("UnitTest");
}
AZStd::chrono::system_clock::time_point start = AZStd::chrono::system_clock::now();
AZStd::thread t1(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t2(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t3(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t4(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t5(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t6(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t7(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
AZStd::thread t8(AZStd::bind(&ProfilerTest::Profile1, this, numIterations));
removeThreadId = t4.get_id();
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
t6.join();
t7.join();
t8.join();
elapsed[i] = AZStd::chrono::system_clock::now() - start;
//AZ_Printf("Profiler","Elapsed time %d\n",elapsed[i].count());
if (i == 0)
{
// just as test remove all associated data and registers.
Profiler::Instance().RemoveThreadData(removeThreadId);
}
m_numRegistersReceived = 0;
Profiler::Instance().ReadRegisterValues(AZStd::bind(&ProfilerTest::ReadRegisterCallback, this, AZStd::placeholders::_1, AZStd::placeholders::_2));
if (i == 0)
{
AZ_TEST_ASSERT(m_numRegistersReceived == 7 * 3); // 3 registers for each thread (8 threads - 1 we removed the data for 't4')
}
else
{
AZ_TEST_ASSERT(m_numRegistersReceived == 0);
}
}
Profiler::Destroy();
// Test user value registers
Profiler::Create();
for (int i = 0; i < 2; ++i)
{
// for the second run we should not record any data
if (i == 1)
{
Profiler::Instance().DeactivateSystem("UnitTest");
}
AZStd::thread t1(AZStd::bind(&ProfilerTest::UserValuesSet, this));
AZStd::thread t2(AZStd::bind(&ProfilerTest::UserValuesSet, this));
AZStd::thread t3(AZStd::bind(&ProfilerTest::UserValuesSet, this));
AZStd::thread t4(AZStd::bind(&ProfilerTest::UserValuesSet, this));
AZStd::thread t5(AZStd::bind(&ProfilerTest::UserValuesAdd, this, 2));
AZStd::thread t6(AZStd::bind(&ProfilerTest::UserValuesAdd, this, 2));
AZStd::thread t7(AZStd::bind(&ProfilerTest::UserValuesAdd, this, 2));
AZStd::thread t8(AZStd::bind(&ProfilerTest::UserValuesAdd, this, 2));
removeThreadId = t4.get_id();
t1.join();
t2.join();
t3.join();
t4.join();
t5.join();
t6.join();
t7.join();
t8.join();
if (i == 0)
{
// just as test remove all associated data and registers.
Profiler::Instance().RemoveThreadData(removeThreadId);
}
m_numRegistersReceived = 0;
Profiler::Instance().ReadRegisterValues(AZStd::bind(&ProfilerTest::ReadRegisterCallback, this, AZStd::placeholders::_1, AZStd::placeholders::_2));
if (i == 0)
{
AZ_TEST_ASSERT(m_numRegistersReceived == 7 * 6); // 6 registers for each thread (8 threads - 1 we removed the data for 't4' )
}
else
{
AZ_TEST_ASSERT(m_numRegistersReceived == 0);
}
}
Profiler::Destroy();
#endif
}
};
#if AZ_TRAIT_DISABLE_FAILED_PROFILER_TEST
TEST_F(ProfilerTest, DISABLED_Test)
#else
TEST_F(ProfilerTest, Test)
#endif // AZ_TRAIT_DISABLE_FAILED_PROFILER_TEST
{
run();
}
TEST(Time, Test)
{
AZStd::sys_time_t ticksPerSecond = AZStd::GetTimeTicksPerSecond();
@@ -317,7 +317,7 @@ namespace UnitTest
AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy();
AZ::Statistics::StatisticalProfilerProxy profilerProxy;
AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface<AZ::Statistics::StatisticalProfilerProxy>::Get();
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain);
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(Terrain);
const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance = "PerformanceResult";
const AZStd::string statNamePerformance("PerformanceResult");
@@ -328,15 +328,15 @@ namespace UnitTest
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr);
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdBlock, statNameBlock, "us") != nullptr);
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true);
proxy->ActivateProfiler(Terrain, true);
const int iter_count = 10;
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdPerformance)
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, statIdPerformance)
int counter = 0;
for (int i = 0; i < iter_count; i++)
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdBlock)
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, statIdBlock)
counter++;
}
}
@@ -348,7 +348,7 @@ namespace UnitTest
EXPECT_EQ(profiler.GetStatistic(statIdBlock)->GetNumSamples(), iter_count);
//Clean Up
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false);
proxy->ActivateProfiler(Terrain, false);
#undef CODE_PROFILER_PROXY_PUSH_TIME
@@ -362,12 +362,12 @@ namespace UnitTest
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread1("simple_thread1");
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread1_loop("simple_thread1_loop");
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread1);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread1);
static int counter = 0;
for (int i = 0; i < loop_cnt; i++)
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread1_loop);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread1_loop);
counter++;
}
}
@@ -377,12 +377,12 @@ namespace UnitTest
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread2("simple_thread2");
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread2_loop("simple_thread2_loop");
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread2);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread2);
static int counter = 0;
for (int i = 0; i < loop_cnt; i++)
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread2_loop);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread2_loop);
counter++;
}
}
@@ -392,12 +392,12 @@ namespace UnitTest
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread3("simple_thread3");
const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread3_loop("simple_thread3_loop");
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread3);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread3);
static int counter = 0;
for (int i = 0; i < loop_cnt; i++)
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread3_loop);
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, simple_thread3_loop);
}
}
@@ -408,7 +408,7 @@ namespace UnitTest
AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy();
AZ::Statistics::StatisticalProfilerProxy profilerProxy;
AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface<AZ::Statistics::StatisticalProfilerProxy>::Get();
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain);
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(Terrain);
const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1 = "simple_thread1";
const AZStd::string statNameThread1("simple_thread1");
@@ -432,7 +432,7 @@ namespace UnitTest
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3, statNameThread3, "us"));
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3Loop, statNameThread3Loop, "us"));
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true);
proxy->ActivateProfiler(Terrain, true);
//Let's kickoff the threads to see how much contention affects the profiler's performance.
const int iter_count = 10;
@@ -459,7 +459,7 @@ namespace UnitTest
EXPECT_EQ(profiler.GetStatistic(statIdThread3Loop)->GetNumSamples(), iter_count);
//Clean Up
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false);
proxy->ActivateProfiler(Terrain, false);
}
/** Trace message handler to track messages during tests
@@ -745,7 +745,7 @@ namespace UnitTest
AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy();
AZ::Statistics::StatisticalProfilerProxy profilerProxy;
AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface<AZ::Statistics::StatisticalProfilerProxy>::Get();
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain);
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(Terrain);
const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance = "PerformanceResult";
const AZStd::string statNamePerformance("PerformanceResult");
@@ -756,15 +756,15 @@ namespace UnitTest
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr);
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdBlock, statNameBlock, "us") != nullptr);
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true);
proxy->ActivateProfiler(Terrain, true);
const int iter_count = 1000000;
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdPerformance)
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, statIdPerformance)
int counter = 0;
for (int i = 0; i < iter_count; i++)
{
CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdBlock)
CODE_PROFILER_PROXY_PUSH_TIME(Terrain, statIdBlock)
counter++;
}
}
@@ -778,7 +778,7 @@ namespace UnitTest
profiler.LogAndResetStats("StatisticalProfilerProxy");
//Clean Up
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false);
proxy->ActivateProfiler(Terrain, false);
}
#undef CODE_PROFILER_PROXY_PUSH_TIME
@@ -788,7 +788,7 @@ namespace UnitTest
AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy();
AZ::Statistics::StatisticalProfilerProxy profilerProxy;
AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface<AZ::Statistics::StatisticalProfilerProxy>::Get();
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain);
AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(Terrain);
const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1 = "simple_thread1";
const AZStd::string statNameThread1("simple_thread1");
@@ -812,7 +812,7 @@ namespace UnitTest
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3, statNameThread3, "us"));
ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3Loop, statNameThread3Loop, "us"));
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true);
proxy->ActivateProfiler(Terrain, true);
//Let's kickoff the threads to see how much contention affects the profiler's performance.
const int iter_count = 1000000;
@@ -841,7 +841,7 @@ namespace UnitTest
profiler.LogAndResetStats("3_Threads_StatisticalProfilerProxy");
//Clean Up
proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false);
proxy->ActivateProfiler(Terrain, false);
}
}//namespace UnitTest
@@ -83,7 +83,7 @@ namespace UnitTest
int ChildFunction0(int numIterations, int sleepTimeMilliseconds)
{
AZ_PROFILE_TIMER("UnitTest", CHILD_TIMER_STAT0);
AZ_PROFILE_SCOPE(AzCore, CHILD_TIMER_STAT0);
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(sleepTimeMilliseconds));
int result = 5;
for (int i = 0; i < numIterations; ++i)
@@ -95,7 +95,7 @@ namespace UnitTest
int ChildFunction1(int numIterations, int sleepTimeMilliseconds)
{
AZ_PROFILE_TIMER("UnitTest", CHILD_TIMER_STAT1);
AZ_PROFILE_SCOPE(AzCore, CHILD_TIMER_STAT1);
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(sleepTimeMilliseconds));
int result = 5;
for (int i = 0; i < numIterations; ++i)
@@ -107,7 +107,7 @@ namespace UnitTest
int ParentFunction(int numIterations, int sleepTimeMilliseconds)
{
AZ_PROFILE_TIMER("UnitTest", PARENT_TIMER_STAT);
AZ_PROFILE_SCOPE(AzCore, PARENT_TIMER_STAT);
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(sleepTimeMilliseconds));
int result = 0;
result += ChildFunction0(numIterations, sleepTimeMilliseconds);
@@ -60,7 +60,6 @@ set(FILES
SerializeContextFixture.h
Slice.cpp
State.cpp
StatisticalProfiler.cpp
Statistics.cpp
StreamerTests.cpp
StringFunc.cpp