You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
To better inform which sounds (and how many instances) we should cache, this CL adds several stats to track cache misses and utilzation of cached sounds. The majority of the tracking logic is encapsulated in the MetaSoundOperatorCacheStatTracker which handles updating active counts for each cached operator and emitting csv events. This change also adds the ability to write all active metasounds to the csv which can be situationally useful. It is disabled by default due to the overhead/csv bloat. #rnx #rb phil.popp #tests local replays, pie, horde RR [CL 34887862 by tyler staples in ue5-main branch]
156 lines
3.8 KiB
C++
156 lines
3.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "MetasoundInstanceCounter.h"
|
|
|
|
namespace Metasound
|
|
{
|
|
FConcurrentInstanceCounterManager::FConcurrentInstanceCounterManager(const FString InCategoryName)
|
|
: CategoryName(InCategoryName)
|
|
{
|
|
}
|
|
|
|
void FConcurrentInstanceCounterManager::Increment(const FName& InstanceName)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
GetOrAddStats(InstanceName).Increment();
|
|
}
|
|
|
|
void FConcurrentInstanceCounterManager::Decrement(const FName& InstanceName)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
GetOrAddStats(InstanceName).Decrement();
|
|
}
|
|
|
|
int64 FConcurrentInstanceCounterManager::GetCountForName(const FName& InName)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
if (FStats* Stats = StatsMap.Find(InName))
|
|
{
|
|
return Stats->GetCount();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int64 FConcurrentInstanceCounterManager::GetPeakCountForName(const FName& InName)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
if (FStats* Stats = StatsMap.Find(InName))
|
|
{
|
|
return Stats->GetPeakCount();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void FConcurrentInstanceCounterManager::VisitStats(TFunctionRef<void(const FName&, int64)> Visitor)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
|
|
for (const TPair<FName, FStats>& Pair : StatsMap)
|
|
{
|
|
Visitor(Pair.Key, Pair.Value.GetCount());
|
|
}
|
|
}
|
|
|
|
#if COUNTERSTRACE_ENABLED
|
|
FConcurrentInstanceCounterManager::FStats::FStats(const FString& InName)
|
|
: TraceCounter(MakeUnique<FCountersTrace::FCounterInt>(TraceCounterNameType_Dynamic, *InName, TraceCounterDisplayHint_None))
|
|
{
|
|
}
|
|
#endif
|
|
|
|
void FConcurrentInstanceCounterManager::FStats::Increment()
|
|
{
|
|
ensure(TraceCounter);
|
|
TraceCounter->Increment();
|
|
PeakCount = FMath::Max(PeakCount, GetCount());
|
|
}
|
|
|
|
|
|
void FConcurrentInstanceCounterManager::FStats::Decrement()
|
|
{
|
|
ensure(TraceCounter);
|
|
TraceCounter->Decrement();
|
|
}
|
|
|
|
int64 FConcurrentInstanceCounterManager::FStats::GetCount() const
|
|
{
|
|
ensure(TraceCounter);
|
|
#if COUNTERSTRACE_ENABLED
|
|
return TraceCounter->Get();
|
|
#else
|
|
return TraceCounter->GetValue();
|
|
#endif
|
|
}
|
|
|
|
int64 FConcurrentInstanceCounterManager::FStats::GetPeakCount() const
|
|
{
|
|
return PeakCount;
|
|
}
|
|
|
|
FConcurrentInstanceCounterManager::FStats& FConcurrentInstanceCounterManager::GetOrAddStats(const FName& InstanceName)
|
|
{
|
|
FScopeLock Lock(&MapCritSec);
|
|
|
|
// avoid re-constructing the trace counter string unless it's new
|
|
if (StatsMap.Contains(InstanceName))
|
|
{
|
|
return StatsMap[InstanceName];
|
|
}
|
|
|
|
#if COUNTERSTRACE_ENABLED
|
|
return StatsMap.Emplace(InstanceName, FString::Printf(TEXT("%s - %s"), *CategoryName, *InstanceName.ToString()));
|
|
#else
|
|
return StatsMap.Add(InstanceName);
|
|
#endif
|
|
}
|
|
|
|
FConcurrentInstanceCounter::FConcurrentInstanceCounter(TSharedPtr<FConcurrentInstanceCounterManager> InCounterManager)
|
|
: ManagerPtr(InCounterManager)
|
|
{
|
|
check(ManagerPtr);
|
|
}
|
|
|
|
FConcurrentInstanceCounter::FConcurrentInstanceCounter(const FName& InName, TSharedPtr<FConcurrentInstanceCounterManager> InCounterManager)
|
|
: InstanceName(InName)
|
|
, ManagerPtr(InCounterManager)
|
|
{
|
|
check(ManagerPtr);
|
|
GetManagerChecked().Increment(InstanceName);
|
|
}
|
|
|
|
FConcurrentInstanceCounter::FConcurrentInstanceCounter(const FString& InName, TSharedPtr<FConcurrentInstanceCounterManager> InCounterManager)
|
|
: InstanceName(InName)
|
|
, ManagerPtr(InCounterManager)
|
|
{
|
|
GetManagerChecked().Increment(InstanceName);
|
|
}
|
|
|
|
// dtor
|
|
FConcurrentInstanceCounter::~FConcurrentInstanceCounter()
|
|
{
|
|
GetManagerChecked().Decrement(InstanceName);
|
|
}
|
|
|
|
void FConcurrentInstanceCounter::Init(const FName& InName)
|
|
{
|
|
InstanceName = InName;
|
|
GetManagerChecked().Increment(InstanceName);
|
|
}
|
|
|
|
void FConcurrentInstanceCounter::Init(const FString& InName)
|
|
{
|
|
InstanceName = FName(InName);
|
|
GetManagerChecked().Increment(InstanceName);
|
|
}
|
|
|
|
FConcurrentInstanceCounterManager& FConcurrentInstanceCounter::GetManagerChecked()
|
|
{
|
|
check(ManagerPtr);
|
|
return *ManagerPtr;
|
|
}
|
|
|
|
// static interface
|
|
} // namespace Metasound
|