Profiler: Runtime region name support (#2924)

* Profiler: add support for runtime region names
* Profiler: fix group name collisions
* Profiler: use set of GroupRegionNames
* Profiler: add comments + named constant

Signed-off-by: Jacob Hilliard <jhlliar@amazon.com>
This commit is contained in:
Jacob Hilliard
2021-08-16 10:13:24 -07:00
committed by GitHub
parent 4f2d4d00ec
commit e2b4d8e502
3 changed files with 55 additions and 0 deletions
@@ -74,6 +74,20 @@ namespace AZ
{
}
AZStd::size_t CachedTimeRegion::GroupRegionName::Hash::operator()(const CachedTimeRegion::GroupRegionName& name) const
{
AZStd::size_t seed = 0;
AZStd::hash_combine(seed, name.m_groupName);
AZStd::hash_combine(seed, name.m_regionName);
return seed;
}
bool CachedTimeRegion::GroupRegionName::operator==(const GroupRegionName& other) const
{
return (m_groupName == other.m_groupName) && (m_regionName == other.m_regionName);
}
// --- CpuProfilerImpl ---
void CpuProfilerImpl::Init()
@@ -218,6 +232,19 @@ namespace AZ
return m_enabled;
}
const CachedTimeRegion::GroupRegionName& CpuProfilerImpl::InsertDynamicName(const char* groupName, const AZStd::string& regionName)
{
AZStd::scoped_lock lock(m_dynamicNameMutex);
AZ_Warning("CpuProfiler", m_regionNameStringPool.size() < MaxRegionStringPoolSize,
"Stored dynamic region names are accumulating. Consider removing a AZ_ATOM_PROFILE_DYNAMIC invocation.");
auto [regionNameItr, wasRegionInserted] = m_regionNameStringPool.insert(regionName);
CachedTimeRegion::GroupRegionName newGroupRegionName(groupName, regionNameItr->c_str());
auto [groupRegionNameItr, wasGroupRegionInserted] = m_dynamicGroupRegionNamePool.insert(newGroupRegionName);
return *groupRegionNameItr;
}
void CpuProfilerImpl::OnSystemTick()
{
if (!m_enabled)