2021-09-02 16:45:15 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# include "DerivedDataInformation.h"
# include "SDerivedDataStatusBar.h"
# include "DerivedDataCacheUsageStats.h"
# include "DerivedDataCacheInterface.h"
# include "DerivedDataBackendInterface.h"
2021-10-12 21:21:22 -04:00
# include "Settings/EditorProjectSettings.h"
# include "Settings/EditorSettings.h"
2021-09-02 16:45:15 -04:00
# include "ToolMenus.h"
# define LOCTEXT_NAMESPACE "DerivedDataEditor"
2021-09-13 08:04:41 -04:00
double FDerivedDataInformation : : LastGetTime = 0 ;
double FDerivedDataInformation : : LastPutTime = 0 ;
bool FDerivedDataInformation : : bIsDownloading = false ;
bool FDerivedDataInformation : : bIsUploading = false ;
2021-10-12 21:21:22 -04:00
FText FDerivedDataInformation : : RemoteCacheWarningMessage ;
2021-09-13 08:04:41 -04:00
ERemoteCacheState FDerivedDataInformation : : RemoteCacheState = ERemoteCacheState : : Unavailable ;
2021-09-02 16:45:15 -04:00
double FDerivedDataInformation : : GetCacheActivitySizeBytes ( bool bGet , bool bLocal )
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TSharedRef < FDerivedDataCacheStatsNode > RootUsage = GetDerivedDataCache ( ) - > GatherUsageStats ( ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
TArray < TSharedRef < const FDerivedDataCacheStatsNode > > LeafUsageStats ;
RootUsage - > ForEachDescendant ( [ & LeafUsageStats ] ( TSharedRef < const FDerivedDataCacheStatsNode > Node ) {
if ( Node - > Children . Num ( ) = = 0 )
{
LeafUsageStats . Add ( Node ) ;
}
} ) ;
int64 TotalBytes = 0 ;
for ( int32 Index = 0 ; Index < LeafUsageStats . Num ( ) ; Index + + )
{
const FDerivedDataBackendInterface * Backend = LeafUsageStats [ Index ] - > GetBackendInterface ( ) ;
2021-10-12 21:21:22 -04:00
if ( Backend - > IsRemote ( ) = = bLocal )
2021-09-02 16:45:15 -04:00
continue ;
TSharedRef < FDerivedDataCacheStatsNode > Usage = Backend - > GatherUsageStats ( ) ;
for ( const auto & KVP : Usage - > Stats )
{
const FDerivedDataCacheUsageStats & Stats = KVP . Value ;
if ( bGet )
{
TotalBytes + = Stats . GetStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Hit , FCookStats : : CallStats : : EStatType : : Bytes ) ;
}
else
{
TotalBytes + = Stats . PutStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Hit , FCookStats : : CallStats : : EStatType : : Bytes ) ;
}
}
}
return TotalBytes ;
}
double FDerivedDataInformation : : GetCacheActivityTimeSeconds ( bool bGet , bool bLocal )
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TSharedRef < FDerivedDataCacheStatsNode > RootUsage = GetDerivedDataCache ( ) - > GatherUsageStats ( ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
TArray < TSharedRef < const FDerivedDataCacheStatsNode > > LeafUsageStats ;
RootUsage - > ForEachDescendant ( [ & LeafUsageStats ] ( TSharedRef < const FDerivedDataCacheStatsNode > Node ) {
if ( Node - > Children . Num ( ) = = 0 )
{
LeafUsageStats . Add ( Node ) ;
}
} ) ;
int64 TotalCycles = 0 ;
for ( int32 Index = 0 ; Index < LeafUsageStats . Num ( ) ; Index + + )
{
const FDerivedDataBackendInterface * Backend = LeafUsageStats [ Index ] - > GetBackendInterface ( ) ;
2021-10-12 21:21:22 -04:00
if ( Backend - > IsRemote ( ) = = bLocal )
2021-09-02 16:45:15 -04:00
continue ;
TSharedRef < FDerivedDataCacheStatsNode > Usage = Backend - > GatherUsageStats ( ) ;
for ( const auto & KVP : Usage - > Stats )
{
const FDerivedDataCacheUsageStats & Stats = KVP . Value ;
if ( bGet )
{
TotalCycles + =
( Stats . GetStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Hit , FCookStats : : CallStats : : EStatType : : Cycles ) +
Stats . GetStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Miss , FCookStats : : CallStats : : EStatType : : Cycles ) ) ;
TotalCycles + =
( Stats . PrefetchStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Hit , FCookStats : : CallStats : : EStatType : : Cycles ) +
Stats . PrefetchStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Miss , FCookStats : : CallStats : : EStatType : : Cycles ) ) ;
}
else
{
TotalCycles + =
( Stats . PutStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Hit , FCookStats : : CallStats : : EStatType : : Cycles ) +
Stats . PutStats . GetAccumulatedValueAnyThread ( FCookStats : : CallStats : : EHitOrMiss : : Miss , FCookStats : : CallStats : : EStatType : : Cycles ) ) ;
}
}
}
return ( double ) TotalCycles * FPlatformTime : : GetSecondsPerCycle ( ) ;
}
bool FDerivedDataInformation : : GetHasRemoteCache ( )
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TSharedRef < FDerivedDataCacheStatsNode > RootUsage = GetDerivedDataCache ( ) - > GatherUsageStats ( ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
TArray < TSharedRef < const FDerivedDataCacheStatsNode > > LeafUsageStats ;
RootUsage - > ForEachDescendant ( [ & LeafUsageStats ] ( TSharedRef < const FDerivedDataCacheStatsNode > Node ) {
if ( Node - > Children . Num ( ) = = 0 )
{
LeafUsageStats . Add ( Node ) ;
}
} ) ;
for ( int32 Index = 0 ; Index < LeafUsageStats . Num ( ) ; Index + + )
{
const FDerivedDataBackendInterface * Backend = LeafUsageStats [ Index ] - > GetBackendInterface ( ) ;
2021-10-12 21:21:22 -04:00
if ( Backend - > IsRemote ( ) )
2021-09-02 16:45:15 -04:00
return true ;
}
return false ;
}
2021-11-07 23:43:01 -05:00
bool FDerivedDataInformation : : GetHasZenCache ( )
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TSharedRef < FDerivedDataCacheStatsNode > RootUsage = GetDerivedDataCache ( ) - > GatherUsageStats ( ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
TArray < TSharedRef < const FDerivedDataCacheStatsNode > > LeafUsageStats ;
RootUsage - > ForEachDescendant ( [ & LeafUsageStats ] ( TSharedRef < const FDerivedDataCacheStatsNode > Node ) {
if ( Node - > Children . Num ( ) = = 0 )
{
LeafUsageStats . Add ( Node ) ;
}
} ) ;
for ( int32 Index = 0 ; Index < LeafUsageStats . Num ( ) ; Index + + )
{
const FDerivedDataBackendInterface * Backend = LeafUsageStats [ Index ] - > GetBackendInterface ( ) ;
if ( Backend - > GetDisplayName ( ) . Equals ( " Zen " ) )
return true ;
}
return false ;
}
bool FDerivedDataInformation : : GetHasHordeStorageCache ( )
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TSharedRef < FDerivedDataCacheStatsNode > RootUsage = GetDerivedDataCache ( ) - > GatherUsageStats ( ) ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
TArray < TSharedRef < const FDerivedDataCacheStatsNode > > LeafUsageStats ;
RootUsage - > ForEachDescendant ( [ & LeafUsageStats ] ( TSharedRef < const FDerivedDataCacheStatsNode > Node ) {
if ( Node - > Children . Num ( ) = = 0 )
{
LeafUsageStats . Add ( Node ) ;
}
} ) ;
for ( int32 Index = 0 ; Index < LeafUsageStats . Num ( ) ; Index + + )
{
const FDerivedDataBackendInterface * Backend = LeafUsageStats [ Index ] - > GetBackendInterface ( ) ;
if ( Backend - > GetDisplayName ( ) . Equals ( " Horde Storage " ) )
return true ;
}
return false ;
}
2021-09-13 08:04:41 -04:00
void FDerivedDataInformation : : UpdateRemoteCacheState ( )
{
RemoteCacheState = ERemoteCacheState : : Unavailable ;
if ( GetHasRemoteCache ( ) )
{
const double OldLastGetTime = LastGetTime ;
const double OldLastPutTime = LastPutTime ;
LastGetTime = FDerivedDataInformation : : GetCacheActivityTimeSeconds ( true , false ) ;
LastPutTime = FDerivedDataInformation : : GetCacheActivityTimeSeconds ( false , false ) ;
if ( OldLastGetTime ! = 0.0 & & OldLastPutTime ! = 0.0 )
{
bIsDownloading = OldLastGetTime ! = LastGetTime ;
bIsUploading = OldLastPutTime ! = LastPutTime ;
}
if ( bIsUploading | | bIsDownloading )
{
RemoteCacheState = ERemoteCacheState : : Busy ;
}
else
{
RemoteCacheState = ERemoteCacheState : : Idle ;
}
}
2021-10-12 21:21:22 -04:00
const UDDCProjectSettings * DDCProjectSettings = GetDefault < UDDCProjectSettings > ( ) ;
2021-10-25 20:05:28 -04:00
if ( DDCProjectSettings & & DDCProjectSettings - > EnableWarnings )
2021-10-12 21:21:22 -04:00
{
const UEditorSettings * EditorSettings = GetDefault < UEditorSettings > ( ) ;
2021-10-25 20:05:28 -04:00
if ( EditorSettings )
2021-10-12 21:21:22 -04:00
{
2021-11-07 23:43:01 -05:00
if ( DDCProjectSettings - > RecommendEveryoneUseHordeStorage & & GetHasHordeStorageCache ( ) = = false & & ( FCString : : Stricmp ( GetDerivedDataCache ( ) - > GetGraphName ( ) , TEXT ( " NoJupiter " ) ) ! = 0 ) )
2021-10-25 20:05:28 -04:00
{
RemoteCacheState = ERemoteCacheState : : Warning ;
2021-11-07 23:43:01 -05:00
RemoteCacheWarningMessage = FText ( LOCTEXT ( " HordeStorageWarning " , " It is recommended that you use a DDC graph that supports Horde Storage. Please check any -ddc commandline overrides. " ) ) ;
2021-10-25 20:05:28 -04:00
}
else if ( DDCProjectSettings - > RecommendEveryoneSetupAGlobalLocalDDCPath & & EditorSettings - > GlobalLocalDDCPath . Path . IsEmpty ( ) )
{
RemoteCacheState = ERemoteCacheState : : Warning ;
RemoteCacheWarningMessage = FText ( LOCTEXT ( " GlobalLocalDDCPathWarning " , " It is recommended that you set up a valid Global Local DDC Path " ) ) ;
}
2021-11-07 23:43:01 -05:00
else if ( DDCProjectSettings - > RecommendEveryoneSetupAGlobalSharedDDCPath & & EditorSettings - > GlobalSharedDDCPath . Path . IsEmpty ( ) )
{
RemoteCacheState = ERemoteCacheState : : Warning ;
RemoteCacheWarningMessage = FText ( LOCTEXT ( " GlobalLocalDDCPathWarning " , " It is recommended that you set up a valid Global Shared DDC Path " ) ) ;
}
2021-10-25 20:05:28 -04:00
else if ( DDCProjectSettings - > RecommendEveryoneEnableS3DDC & & EditorSettings - > bEnableS3DDC = = false )
{
RemoteCacheState = ERemoteCacheState : : Warning ;
RemoteCacheWarningMessage = FText ( LOCTEXT ( " AWSS3CacheEnabledWarning " , " It is recommended that you enable the AWS S3 Cache " ) ) ;
}
else if ( DDCProjectSettings - > RecommendEveryoneSetupAGlobalS3DDCPath & & EditorSettings - > GlobalS3DDCPath . Path . IsEmpty ( ) )
{
RemoteCacheState = ERemoteCacheState : : Warning ;
RemoteCacheWarningMessage = FText ( LOCTEXT ( " S3GloblaLocalPathdWarning " , " It is recommended that you set up a valid Global Local S3 DDC Path " ) ) ;
}
2021-10-12 21:21:22 -04:00
}
}
2021-09-13 08:04:41 -04:00
}
2021-09-16 06:12:33 -04:00
FText FDerivedDataInformation : : GetRemoteCacheStateAsText ( )
{
switch ( FDerivedDataInformation : : GetRemoteCacheState ( ) )
{
case ERemoteCacheState : : Idle :
{
2021-10-12 21:21:22 -04:00
return FText ( LOCTEXT ( " DDCStateIdle " , " Idle " ) ) ;
2021-09-16 06:12:33 -04:00
break ;
}
case ERemoteCacheState : : Busy :
{
2021-10-12 21:21:22 -04:00
return FText ( LOCTEXT ( " DDCStateBusy " , " Busy " ) ) ;
2021-09-16 06:12:33 -04:00
break ;
}
case ERemoteCacheState : : Unavailable :
{
2021-10-12 21:21:22 -04:00
return FText ( LOCTEXT ( " DDCStateUnavailable " , " Unavailable " ) ) ;
2021-09-16 06:12:33 -04:00
break ;
}
default :
case ERemoteCacheState : : Warning :
{
2021-10-12 21:21:22 -04:00
return FText ( LOCTEXT ( " DDCStateWarning " , " Warning " ) ) ;
2021-09-16 06:12:33 -04:00
break ;
}
}
}
2021-09-02 16:45:15 -04:00
# undef LOCTEXT_NAMESPACE