Files
UnrealEngineUWP/Engine/Source/Developer/Profiler/Private/ProfilerRawStatsForMemory.cpp

886 lines
28 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Sequencer to //UE4/Dev-Main (Source: //UE4/Dev-Sequencer @ 3178529) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3149443 on 2016/10/03 by Max.Preussner MediaAssets: Better parameter names for MediaPlayer BP functions Change 3149756 on 2016/10/03 by Max.Chen Sequence Recorder: Set some settings to be clamped at 0 (sequence length, recording delay, audio gain, audio input buffer size, nearby actor recording proximity) #jira UE-35233 Change 3149795 on 2016/10/03 by Max.Chen Curve Editor: Set tangent to user when flattening or straightening tangents only when the tangent mode is auto and the interp mode is cubic. #jira UE-36734 Change 3150378 on 2016/10/04 by Max.Preussner PS4Media: Made video buffer sizes for file and HLS sources configurable (UE-36807) #jira UE-36807 Change 3151414 on 2016/10/05 by Max.Chen Sequencer: Fix case where restoring the last view target was getting skipped. It should always restore if the camera object and the unlock if camera actor object is null. #jira UE-35285 Change 3152038 on 2016/10/05 by Max.Preussner UdpMessaging: Code & documentation modernization pass Change 3152471 on 2016/10/05 by Max.Chen Cine Camera: Don't enable/disable actor ticking based soley on actor tracking since actor ticking is needed for other purposes. Instead, always enable actor ticking and only update actor tracking on tick if necessary. This fixes a bug where the cine camera actor won't tick if you hook in event tick. #jira UE-36625 Change 3152692 on 2016/10/05 by Max.Preussner Messaging: API code & documentation modernization pass Mostly removed shared pointer/ref typedefs as they prevent forward declarations and increase include complexity. Change 3153824 on 2016/10/06 by Max.Preussner Messaging: Renamed IConnectionBasedMessagingModule to ITcpMessagingModule and moved it into TcpMessaging I recommend that we refactor this API. The dependency should be reversed, i.e. instead of AndroidDeviceDiscovery depending on the TcpMessaging plug-in module, the Engine should provide a central registry that device discovery modules can notify, and that message transport plug-ins can register with and listen to OnConnectionAdded/Removed events etc. That way it supports an arbitrary number of transport plug-ins, and the Engine is not coupled to any of them. This functionality is not necessarily related to messaging, and the Messaging API is transport agnostic anyway. I'll think about this some more. Change 3153826 on 2016/10/06 by Max.Preussner Messaging: Removed remaining typedefs in IMessageTracer to enable forward declaration and reduce include dependencies Change 3153857 on 2016/10/06 by Max.Chen Sequencer: Set snap time to dragged key on by default. Change 3153980 on 2016/10/06 by Max.Preussner SessionServices: Removed typedefs; code and documentation modernization pass Change 3154313 on 2016/10/06 by Max.Chen Sequencer: Set the paste keys time to the current time, rather than the mouse time. Change 3154332 on 2016/10/06 by Max.Chen Sequencer: Remove click to rename shot functionality in the shot thumbnail. Added rename shot to the shot context menu. Change 3154377 on 2016/10/07 by Max.Chen Sequencer: Add ability to step to beginning and ends of sections/shots using the hotkeys: , and . Change 3154788 on 2016/10/07 by Max.Chen Sequencer: Fix offsets that created when moving multiple sections. The offsets were being created because section bounds were being generated for all sections except for the current section. Instead, they should be computed for all sections except for any that aren't being moved. #jira UE-29152 Change 3159274 on 2016/10/11 by Max.Preussner Core: Documentation fixes Change 3159275 on 2016/10/11 by Max.Preussner UdpMessaging: Added missing header Change 3160746 on 2016/10/12 by Max.Preussner MediaAssets: Added BP functions to query width, height, and aspect ratio of UMediaTexture instances #jira UE-37241 Change 3160975 on 2016/10/12 by Max.Preussner PS4Media: Better logging for SetRate failures Change 3160995 on 2016/10/12 by Max.Preussner MediaPlayerEditor: Fixed Media player selection is ignored if media specifies player overrides (UE-37248) #jira UE-37248 Change 3161066 on 2016/10/12 by Max.Preussner PS4Media: Enforcing minimum 8 byte alignment for media allocations Change 3161069 on 2016/10/12 by Max.Preussner PS4Media: Fixed log spam when setting play rate to current rate Change 3162567 on 2016/10/13 by Max.Preussner PS4Media: Made track switching code more readable Change 3163447 on 2016/10/14 by Max.Preussner PS4Media: Fixed array out of bounds assertions Change 3163772 on 2016/10/14 by Max.Preussner MfMedia: Fixed a number of timing related issues Change 3163980 on 2016/10/15 by Max.Chen Sequencer: Remove folder name numeric padding so that the naming convention is similar to creating objects in the level. Change 3164581 on 2016/10/17 by Andrew.Rodham Sequencer: Ensure global pre-animated state is restored in reverse order Change 3164582 on 2016/10/17 by Andrew.Rodham Sequencer: Ensure pre animated state is restored for all actor components before saving default state Change 3164583 on 2016/10/17 by Andrew.Rodham Sequencer: Re-enabled support for pre and post roll Change 3165464 on 2016/10/17 by Max.Chen Sequencer: Default number frame handles to 0 so that there's no change in behavior when rendering out a master sequence of shots. Handle frames need to enabled explicitly by the user. Copy from Release-4.14 #jira UE-37416 Change 3165483 on 2016/10/17 by Max.Chen Sequencer: Enable restore state for attach section completion Change 3165771 on 2016/10/18 by Andrew.Rodham Sequencer: Force evaluate when rendering thumbnails #jira UE-37321 Change 3166057 on 2016/10/18 by Andrew.Rodham Sequencer: Only set defaults for tracks that have no keys, and where the requested default has changed #jira UE-37285 Change 3166218 on 2016/10/18 by Max.Preussner MediaPlayerEditor: Failure opening media, even though it opened successfully (UE-37470) #jira UE-37470 Change 3166247 on 2016/10/18 by Max.Preussner WmfMedia: Showing progress bar while media is being resolved Change 3166289 on 2016/10/18 by Max.Preussner MfMedia: Showing progress bar while media is being resolved Change 3166993 on 2016/10/18 by Max.Preussner MfMedia: Fixed info string not reset on media close. Change 3166999 on 2016/10/19 by Max.Preussner Media: Fixed NV12 and NV21 support Change 3167008 on 2016/10/19 by Max.Preussner Media: Removed vertical NV12 alignment Change 3167029 on 2016/10/19 by Max.Preussner WmfMedia: Temp fix for RGB32 encoded AVIs rendering upside-down and too bright (UE-37505) #jira UE-37505 Change 3168593 on 2016/10/19 by Max.Chen Sequencer: Change paste at time to local time, so that the paste happens in the local time of the sequence rather than the global time if pasting in a shot level sequence. Change 3168626 on 2016/10/19 by Max.Chen Sequencer: Clamp to view bounds should snap to frame if frame snapping is on. Change 3168627 on 2016/10/19 by Max.Chen Sequencer: Initialize working and view range to be 10% larger than playback range. Change 3168760 on 2016/10/20 by Max.Preussner Media: Revamped media texture buffer management to support padded frames Added support for Windows bitmap buffers. Fixed a number of format, conversion and/or looping issues in WmfMedia and MfMedia. Not all shaders have been updated yet. Change 3169640 on 2016/10/20 by Max.Chen Sequencer: Add current camera to FLevelSequencePlayerSnapshot. Adjust DefaultBurnIn to include a few more parameters like focal length and focus distance. #jira UE-37407 Change 3170677 on 2016/10/21 by Max.Chen Movie Scene Capture: Add toggle to override engine scalability settings to cinematic scalability. #jira UE-36560 Change 3170710 on 2016/10/21 by Max.Preussner Media: Optimized handling of RGB input Change 3170712 on 2016/10/21 by Max.Preussner Media: Fixed NV21 conversion shader scaling Change 3170923 on 2016/10/21 by Max.Preussner UBT: Copied XboxOne project generator fix from Fortnite CL# 3170868 Change 3171494 on 2016/10/23 by Max.Chen Sequencer: Fix fbx export from master sequence not finding bound objects. #jira UE-35752 Change 3171506 on 2016/10/23 by Max.Chen Sequencer: Draw where in and out points of the shot section are, just like subsequences do. Change to only draw the green starting line if StartOffset is negative. #jira UE-35473 Change 3171743 on 2016/10/24 by Andrew.Rodham Editor: Added support for detail customizations on root structs - Also added the ability to add external struct data onto a detail category builder, and property type customization. Change 3171752 on 2016/10/24 by Andrew.Rodham Sequencer: Fixed spawnable ownership - Spawnables are no longer destroyed when the cursor leaves the master playback range. - Spawnable ownership now operates as it previously did before the evaluation rework. - bIgnoreOwnershipInEditor has been removed since its existence was a work around for when we didn't evaluate sub sequences from the master sequence. - FMovieSceneSequenceID is now a struct so that it can be used in array properties - Meta data now exists for each segment of an evaluation field. Currently this only includes the sub sequence IDs that exist at that time, but it may be expanded to include all evaluation entities (tracks + sections) in future so we don't have to calculate that at runtime. Change 3171756 on 2016/10/24 by Andrew.Rodham Sequencer: Added ability to trigger events with parameters - It's now possible to supply an event payload on event track keys which are to be passed to a given event. The structure must match the signature of the event, or a warning will be emitted. - Added a templated TGenericKeyArea, TKeyFrameManipulator and TCurveInterface that allow to generic manipulation of keyframe section data. In time we will port the other key areas over to this representation. - This new architecture affords the common manipulation of time-based keyframes in a value-agnostic manner. Change 3172935 on 2016/10/24 by Max.Preussner MediaPlayerEditor: Fixed MediaPlayer asset not being dirtied when creating media sound wave or texture for it Change 3173947 on 2016/10/25 by Max.Preussner SlateRemote: Disabled plug-in, but enabled server by default Change 3174510 on 2016/10/26 by Max.Chen Sequencer: Fix slomo track crash #jira UE-37802 Change 3174698 on 2016/10/26 by Andrew.Rodham UMG: Fixed objects bound to a panel slot animating their slot's content instead of the slot itself #jira UE-37775 Change 3174780 on 2016/10/26 by Max.Preussner MediaAssets: Accepting decoder defined buffer dimensions for RGB buffers Change 3174789 on 2016/10/26 by Max.Preussner MediaPlayerEditor: Showing desired player name instead of current player name if no media loaded Change 3174817 on 2016/10/26 by Max.Preussner WmfMedia: Added support for Motion JPEG (MJPG) Change 3174825 on 2016/10/26 by Max.Preussner WmfMedia: Added support for non-RGB32 uncompressed formats Change 3174834 on 2016/10/26 by Max.Preussner MediaPlayerAssets: Allow pausing while buffering media Change 3174886 on 2016/10/26 by Andrew.Rodham Core: Fixed range test that was testing incorrect behavior Change 3174889 on 2016/10/26 by Andrew.Rodham Sequencer: Fixed AssignActor behavior - Also ensure that cached object state is invalidated when playback context changes #jira UE-37798 Change 3174905 on 2016/10/26 by Andrew.Rodham Sequencer: Changed assert when failing to create an audio component to a log message - Audio no longer plays when GEngine->UseSound() is false #jira UE-37772 Change 3174980 on 2016/10/26 by Andrew.Rodham Sequencer: Remove warning when event endpoint could not be found for a given context #jira UE-37824 Change 3175001 on 2016/10/26 by Andrew.Rodham Sequencer: Evaluate sequence with EMovieScenePlaybackStatus::Jumping on Pause. - Also protect Pause() against reentrancy when being called from an event Change 3175012 on 2016/10/26 by Max.Chen Sequence Recorder: Fixes an empty working and view range after recording. On StopRecording() update playback range after nullifying the current sequence so that the playback range isn't empty. Added SetViewRange and SetWorkingRange. #jira UE-34191 Change 3177760 on 2016/10/28 by Max.Chen Sequence Recorder: Don't update the current sequence name if it's already set. This fixes a bug where if you pass in a sequence name to record to, it gets reset to the name in the sequence recorder settings. #jira UE-37808 Change 3178529 on 2016/10/28 by Max.Chen Matinee to Level Sequence: Added interface to extend the matinee to level sequence converter #jira UE-37328 #2864 [CL 3178562 by Max Chen in Main branch]
2016-10-28 15:04:38 -04:00
#include "ProfilerRawStatsForMemory.h"
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "Stats/StatsMisc.h"
#include "ProfilingDebugging/DiagnosticTable.h"
/*-----------------------------------------------------------------------------
Sort helpers
-----------------------------------------------------------------------------*/
/** Sorts allocations by size. */
struct FAllocationInfoSequenceTagLess
{
FORCEINLINE bool operator()( const FAllocationInfo& A, const FAllocationInfo& B ) const
{
return A.SequenceTag < B.SequenceTag;
}
};
/** Sorts allocations by size. */
struct FAllocationInfoSizeGreater
{
FORCEINLINE bool operator()( const FAllocationInfo& A, const FAllocationInfo& B ) const
{
return B.Size < A.Size;
}
};
/** Sorts combined allocations by size. */
struct FCombinedAllocationInfoSizeGreater
{
FORCEINLINE bool operator()( const FCombinedAllocationInfo& A, const FCombinedAllocationInfo& B ) const
{
return B.Size < A.Size;
}
};
/** Sorts node allocations by size. */
struct FNodeAllocationInfoSizeGreater
{
FORCEINLINE bool operator()( const FNodeAllocationInfo& A, const FNodeAllocationInfo& B ) const
{
return B.Size < A.Size;
}
};
/*-----------------------------------------------------------------------------
Callstack decoding/encoding
-----------------------------------------------------------------------------*/
/** Helper struct used to manipulate stats based callstacks. */
struct FStatsCallstack
{
/** Separator. */
static const TCHAR* CallstackSeparator;
/** Encodes decoded callstack a string, to be like '45+656+6565'. */
static FString Encode( const TArray<FName>& Callstack )
{
FString Result;
for (const auto& Name : Callstack)
{
Result += TTypeToString<int32>::ToString( (int32)Name.GetComparisonIndex() );
Result += CallstackSeparator;
}
return Result;
}
/** Decodes encoded callstack to an array of FNames. */
static void DecodeToNames( const FName& EncodedCallstack, TArray<FName>& out_DecodedCallstack )
{
TArray<FString> DecodedCallstack;
DecodeToStrings( EncodedCallstack, DecodedCallstack );
// Convert back to FNames
for (const auto& It : DecodedCallstack)
{
NAME_INDEX NameIndex = 0;
TTypeFromString<NAME_INDEX>::FromString( NameIndex, *It );
const FName LongName = FName( NameIndex, NameIndex, 0 );
out_DecodedCallstack.Add( LongName );
}
}
/** Converts the encoded callstack into human readable callstack. */
static FString GetHumanReadable( const FName& EncodedCallstack )
{
TArray<FName> DecodedCallstack;
DecodeToNames( EncodedCallstack, DecodedCallstack );
const FString Result = GetHumanReadable( DecodedCallstack );
return Result;
}
/** Converts the encoded callstack into human readable callstack. */
static FString GetHumanReadable( const TArray<FName>& DecodedCallstack )
{
FString Result;
const int32 NumEntries = DecodedCallstack.Num();
//for (int32 Index = DecodedCallstack.Num() - 1; Index >= 0; --Index)
for (int32 Index = 0; Index < NumEntries; ++Index)
{
const FName LongName = DecodedCallstack[Index];
const FString ShortName = FStatNameAndInfo::GetShortNameFrom( LongName ).ToString();
//const FString Group = FStatNameAndInfo::GetGroupNameFrom( LongName ).ToString();
FString Desc = FStatNameAndInfo::GetDescriptionFrom( LongName );
Desc.Trim();
if (Desc.Len() == 0)
{
Result += ShortName;
}
else
{
Result += Desc;
}
if (Index != NumEntries - 1)
{
Result += TEXT( " -> " );
}
}
Result.ReplaceInline( TEXT( "STAT_" ), TEXT( "" ), ESearchCase::CaseSensitive );
return Result;
}
protected:
/** Decodes encoded callstack to an array of strings. Where each string is the index of the FName. */
static void DecodeToStrings( const FName& EncodedCallstack, TArray<FString>& out_DecodedCallstack )
{
EncodedCallstack.ToString().ParseIntoArray( out_DecodedCallstack, CallstackSeparator, true );
}
};
const TCHAR* FStatsCallstack::CallstackSeparator = TEXT( "+" );
/*-----------------------------------------------------------------------------
Allocation info
-----------------------------------------------------------------------------*/
FAllocationInfo::FAllocationInfo( uint64 InOldPtr, uint64 InPtr, int64 InSize, const TArray<FName>& InCallstack, uint32 InSequenceTag, EMemoryOperation InOp, bool bInHasBrokenCallstack )
: OldPtr( InOldPtr )
, Ptr( InPtr )
, Size( InSize )
, EncodedCallstack( *FStatsCallstack::Encode( InCallstack ) )
, SequenceTag( InSequenceTag )
, Op( InOp )
, bHasBrokenCallstack( bInHasBrokenCallstack )
{
}
FAllocationInfo::FAllocationInfo( const FAllocationInfo& Other )
: OldPtr( Other.OldPtr )
, Ptr( Other.Ptr )
, Size( Other.Size )
, EncodedCallstack( Other.EncodedCallstack )
, SequenceTag( Other.SequenceTag )
, Op( Other.Op )
, bHasBrokenCallstack( Other.bHasBrokenCallstack )
{
}
/*-----------------------------------------------------------------------------
FNodeAllocationInfo
-----------------------------------------------------------------------------*/
void FNodeAllocationInfo::SortBySize()
{
ChildNodes.ValueSort( FNodeAllocationInfoSizeGreater() );
for (auto& It : ChildNodes)
{
It.Value->SortBySize();
}
}
void FNodeAllocationInfo::PrepareCallstackData( const TArray<FName>& InDecodedCallstack )
{
DecodedCallstack = InDecodedCallstack;
EncodedCallstack = *FStatsCallstack::Encode( DecodedCallstack );
HumanReadableCallstack = FStatsCallstack::GetHumanReadable( DecodedCallstack );
}
/*-----------------------------------------------------------------------------
FRawStatsMemoryProfiler
-----------------------------------------------------------------------------*/
FRawStatsMemoryProfiler::FRawStatsMemoryProfiler( const TCHAR* InFilename )
: FStatsReadFile( InFilename, true )
, NumDuplicatedMemoryOperations( 0 )
, NumMemoryOperations( 0 )
, LastSequenceTagForNamedMarker( 0 )
{}
void FRawStatsMemoryProfiler::PreProcessStats()
{
Super::PreProcessStats();
// Begin marker.
Snapshots.Add( TPairInitializer<uint32, FName>( LastSequenceTagForNamedMarker, TEXT( "BeginSnapshot" ) ) );
}
void FRawStatsMemoryProfiler::PostProcessStats()
{
Super::PostProcessStats();
const double StartTime = FPlatformTime::Seconds();
if (!IsProcessingStopped())
{
SortSequenceAllocations();
// End marker.
Snapshots.Add( TPairInitializer<uint32, FName>( TNumericLimits<uint32>::Max(), TEXT( "EndSnapshot" ) ) );
// Copy snapshots.
SnapshotsToBeProcessed = Snapshots;
UE_LOG( LogStats, Log, TEXT( "NumMemoryOperations: %i" ), NumMemoryOperations );
UE_LOG( LogStats, Log, TEXT( "SequenceAllocationNum: %i" ), SequenceAllocationArray.Num() );
GenerateAllocationMap();
DumpDebugAllocations();
}
if (!IsProcessingStopped())
{
StageProgress.Set( 100 );
const double TotalTime = FPlatformTime::Seconds() - StartTime;
UE_LOG( LogStats, Log, TEXT( "Post-Processing took %.2f sec(s)" ), TotalTime );
}
else
{
UE_LOG( LogStats, Warning, TEXT( "Post-Processing stopped, abandoning" ) );
}
}
void FRawStatsMemoryProfiler::DumpDebugAllocations()
{
#if UE_BUILD_DEBUG
// Dump problematic allocations
DuplicatedAllocMap.ValueSort( FAllocationInfoSizeGreater() );
uint64 TotalDuplicatedMemory = 0;
for (const auto& It : DuplicatedAllocMap)
{
const FAllocationInfo& Alloc = It.Value;
TotalDuplicatedMemory += Alloc.Size;
}
UE_LOG( LogStats, Warning, TEXT( "Dumping duplicated alloc map" ) );
UE_LOG( LogStats, Warning, TEXT( "TotalDuplicatedMemory: %llu bytes (%.2f MB)" ), TotalDuplicatedMemory, TotalDuplicatedMemory / 1024.0f / 1024.0f );
const float MaxPctDisplayed = 0.9f;
uint64 DisplayedSoFar = 0;
for (const auto& It : DuplicatedAllocMap)
{
const FAllocationInfo& Alloc = It.Value;
const FString& AllocCallstack = It.Key;
UE_LOG( LogStats, Log, TEXT( "%lli (%.2f MB) %s" ), Alloc.Size, Alloc.Size / 1024.0f / 1024.0f, *AllocCallstack );
DisplayedSoFar += Alloc.Size;
const float CurrentPct = (float)DisplayedSoFar / (float)TotalDuplicatedMemory;
if (CurrentPct > MaxPctDisplayed)
{
break;
}
}
#endif // UE_BUILD_DEBUG
}
void FRawStatsMemoryProfiler::FreeDebugInformation()
{
DuplicatedAllocMap.Empty();
ZeroAllocMap.Empty();
}
void FRawStatsMemoryProfiler::GenerateAllocationMap()
{
/** Map of currently alive allocations. Ptr to AllocationInfo. */
TMap<uint64, FAllocationInfo> AllocationMap;
// Initialize the begin snapshot.
auto BeginSnapshot = SnapshotsToBeProcessed[0];
SnapshotsToBeProcessed.RemoveAt( 0 );
PrepareSnapshot( BeginSnapshot.Value, AllocationMap );
auto CurrentSnapshot = SnapshotsToBeProcessed[0];
UE_LOG( LogStats, Log, TEXT( "Generating memory operations map" ) );
const int32 NumSequenceAllocations = SequenceAllocationArray.Num();
const int32 OnePercent = FMath::Max( NumSequenceAllocations / 100, 1024 );
for (int32 AllocationIndex = 0; AllocationIndex < NumSequenceAllocations; AllocationIndex++)
{
if (AllocationIndex % OnePercent == 0)
{
UpdateGenerateMemoryMapProgress( AllocationIndex );
if (IsProcessingStopped())
{
break;
}
}
const FAllocationInfo& Alloc = SequenceAllocationArray[AllocationIndex];
// Check named marker/snapshots
if (Alloc.SequenceTag > CurrentSnapshot.Key)
{
SnapshotsToBeProcessed.RemoveAt( 0 );
PrepareSnapshot( CurrentSnapshot.Value, AllocationMap );
CurrentSnapshot = SnapshotsToBeProcessed[0];
}
if (Alloc.Op == EMemoryOperation::Alloc)
{
ProcessAlloc( Alloc, AllocationMap );
}
else if (Alloc.Op == EMemoryOperation::Realloc)
{
// Previous Alloc or Realloc
if (Alloc.OldPtr != 0)
{
ProcessFree( Alloc, AllocationMap, true );
}
#if UE_BUILD_DEBUG
if (Alloc.OldPtr == 0 && Alloc.Size == 0)
{
const FString ReallocCallstack = FStatsCallstack::GetHumanReadable( Alloc.EncodedCallstack );
UE_LOG( LogStats, VeryVerbose, TEXT( "ReallocZero: %s %i %i/%i [%i]" ), *ReallocCallstack, Alloc.Size, Alloc.OldPtr, Alloc.Ptr, Alloc.SequenceTag );
}
#endif // UE_BUILD_DEBUG
if (Alloc.Ptr != 0)
{
ProcessAlloc( Alloc, AllocationMap );
}
}
else if (Alloc.Op == EMemoryOperation::Free)
{
ProcessFree( Alloc, AllocationMap, false );
}
}
auto EndSnapshot = SnapshotsToBeProcessed[0];
SnapshotsToBeProcessed.RemoveAt( 0 );
PrepareSnapshot( EndSnapshot.Value, AllocationMap );
// We don't need the allocation map. Each snapshot has its own copy.
AllocationMap.Empty();
SnapshotNamesArray = SnapshotNamesSet.Array();
UE_LOG( LogStats, Verbose, TEXT( "NumDuplicatedMemoryOperations: %i" ), NumDuplicatedMemoryOperations );
UE_LOG( LogStats, Verbose, TEXT( "NumZeroAllocs: %i" ), NumZeroAllocs );
}
void FRawStatsMemoryProfiler::ProcessAlloc( const FAllocationInfo& AllocInfo, TMap<uint64, FAllocationInfo>& AllocationMap )
{
if( AllocInfo.Size == 0 )
{
NumZeroAllocs++;
ZeroAllocMap.Add( FStatsCallstack::GetHumanReadable( AllocInfo.EncodedCallstack ), AllocInfo );
}
const FAllocationInfo* Found = AllocationMap.Find( AllocInfo.Ptr );
if (!Found)
{
AllocationMap.Add( AllocInfo.Ptr, AllocInfo );
}
else
{
NumDuplicatedMemoryOperations++;
#if UE_BUILD_DEBUG
const FString FoundCallstack = FStatsCallstack::GetHumanReadable( Found->EncodedCallstack );
const FString AllocCallstack = FStatsCallstack::GetHumanReadable( AllocInfo.EncodedCallstack );
UE_LOG( LogStats, VeryVerbose, TEXT( "DuplicatedAlloc" ) );
UE_LOG( LogStats, VeryVerbose, TEXT( "FoundCallstack: %s [%s]" ), *FoundCallstack, Found->Op==EMemoryOperation::Alloc ? TEXT("Alloc") : TEXT("Realloc") );
UE_LOG( LogStats, VeryVerbose, TEXT( "AllocCallstack: %s [%s]" ), *AllocCallstack, AllocInfo.Op==EMemoryOperation::Alloc ? TEXT("Alloc") : TEXT("Realloc") );
UE_LOG( LogStats, VeryVerbose, TEXT( "Size: %i/%i Ptr: %llu/%llu Tag: %i/%i" ), Found->Size, AllocInfo.Size, Found->Ptr, AllocInfo.Ptr, Found->SequenceTag, AllocInfo.SequenceTag );
// Store the old pointer.
DuplicatedAllocMap.Add( FoundCallstack, *Found );
#endif // UE_BUILD_DEBUG
// Replace pointer.
AllocationMap.Add( AllocInfo.Ptr, AllocInfo );
}
}
void FRawStatsMemoryProfiler::ProcessFree( const FAllocationInfo& FreeInfo, TMap<uint64, FAllocationInfo>& AllocationMap, const bool bReallocFree )
{
// bReallocFree is not needed here, but it's easier to read the code.
const uint64 PtrToBeFreed = bReallocFree ? FreeInfo.OldPtr : FreeInfo.Ptr;
const FAllocationInfo* Found = AllocationMap.Find( PtrToBeFreed );
if (Found)
{
const bool bIsValid = FreeInfo.SequenceTag > Found->SequenceTag;
if (!bIsValid)
{
UE_LOG( LogStats, Warning, TEXT( "InvalidFree Ptr: %llu, Seq: %i/%i" ), PtrToBeFreed, FreeInfo.SequenceTag, Found->SequenceTag );
}
AllocationMap.Remove( PtrToBeFreed );
}
else
{
#if UE_BUILD_DEBUG
const FString FWACallstack = FStatsCallstack::GetHumanReadable( FreeInfo.EncodedCallstack );
UE_LOG( LogStats, VeryVerbose, TEXT( "FreeWithoutAlloc: %s, %llu" ), *FWACallstack, PtrToBeFreed );
#endif // UE_BUILD_DEBUG
}
}
void FRawStatsMemoryProfiler::UpdateGenerateMemoryMapProgress( const int32 AllocationIndex )
{
const double CurrentSeconds = FPlatformTime::Seconds();
if (CurrentSeconds > LastUpdateTime + NumSecondsBetweenUpdates)
{
const int32 PercentagePos = int32( 100.0*AllocationIndex / SequenceAllocationArray.Num() );
StageProgress.Set( PercentagePos );
UE_LOG( LogStats, Verbose, TEXT( "Processing allocations %3i%% (%10i/%10i)" ), PercentagePos, AllocationIndex, SequenceAllocationArray.Num() );
LastUpdateTime = CurrentSeconds;
}
// Abandon support.
if (bShouldStopProcessing == true)
{
SetProcessingStage( EStatsProcessingStage::SPS_Stopped );
}
}
void FRawStatsMemoryProfiler::ProcessSpecialMessageMarkerOperation( const FStatMessage& Message, const FStackState& StackState )
{
const FName RawName = Message.NameAndInfo.GetRawName();
Copying //UE4/Dev-Core to //UE4/Main ========================== MAJOR FEATURES + CHANGES ========================== Change 2717513 on 2015/10/06 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1 GC and WeakObjectPtr performance optimizations. - Moved some of the EObjectFlags to EInternalObjectFlags and merged them with FUObjectArray - Moved WeakObjectPtr serial numbersto FUObjectArray - Added pre-allocated UObject array Change 2716517 on 2015/10/05 by Robert.Manuszewski@Robert_Manuszewski_EGUK_M1 Make SavePackage thread safe UObject-wise so that StaticFindObject etc can't run in parallel when packages are being saved. Change 2721142 on 2015/10/08 by Mikolaj.Sieluzycki@Dev-Core_D0920 UHT will now use makefiles to speed up iterative runs. Change 2726320 on 2015/10/13 by Jaroslaw.Palczynski@jaroslaw.palczynski_D1732_2963 Hot-reload performance optimizations: 1. Got rid of redundant touched BPs optimization (which was necessary before major HR fixes submitted earlier). 2. Parallelized search for old CDOs referencers. Change 2759032 on 2015/11/09 by Graeme.Thornton@GThornton_DesktopMaster Dependency preloading improvements - Asset registry dependencies now resolve asset redirectors - Rearrange runtime loading to put dependency preloads within BeginLoad/EndLoad for the source package Change 2754342 on 2015/11/04 by Robert.Manuszewski@Robert_Manuszewski_Stream1 Allow UnfocusedVolumeMultiplier to be set programmatically Change 2764008 on 2015/11/12 by Robert.Manuszewski@Robert_Manuszewski_Stream1 When cooking, don't add imports that are outers of objects excluded from the current cook target. Change 2755562 on 2015/11/05 by Steve.Robb@Dev-Core Inline storage for TFunction. Fix for delegate inline storage on Win64. Some build fixes. Visualizer fixes for new TFunction format. Change 2735084 on 2015/10/20 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec CrashReporter Web - Search by Platform Added initial support for streams (GetBranchesAsListItems, CopyToJira) Change 2762387 on 2015/11/11 by Steve.Robb@Dev-Core Unnecessary allocation removed when loading empty files in FFileHelper::LoadFileToString. Change 2762632 on 2015/11/11 by Steve.Robb@Dev-Core Some TSet function optimisations: Avoiding unnecessary hashing of function arguments if the container is empty (rather than the hash being empty, which is not necessarily equivalent). Taking local copies of HashSize during iterations. Change 2762936 on 2015/11/11 by Steve.Robb@Dev-Core BulkData zero byte allocations are now handled by an RAII object which owns the memory. Change 2765758 on 2015/11/13 by Steve.Robb@Dev-Core FName::operator== and != optimised to be a single comparison. Change 2757195 on 2015/11/06 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec PR #1305: Improvements in CrashReporter for Symbol Server usage (Contributed by bozaro) Change 2760778 on 2015/11/10 by Jaroslaw.Surowiec@Stream.1.JarekSurowiec PR #1725: Fixed typos in ProfilerCommon.h; Added comments (Contributed by BGR360) Also fixed starting condition. Change 2739804 on 2015/10/23 by Robert.Manuszewski@Robert_Manuszewski_Stream1 PR #1470: [UObjectGlobals] Do not overwrite instanced subobjects with ones from CDO (Contributed by slonopotamus) Change 2744733 on 2015/10/28 by Steve.Robb@Dev-Core PR #1540 - Specifying a different Saved folder at launch through a command line parameter Integrated and optimized. #lockdown Nick.Penwarden [CL 2772222 by Robert Manuszewski in Main branch]
2015-11-18 16:20:49 -05:00
if (RawName == FStatConstants::RAW_NamedMarker)
{
const FName NamedMarker = Message.GetValue_FName();
Snapshots.Add( TPairInitializer<uint32, FName>( LastSequenceTagForNamedMarker, NamedMarker ) );
}
}
void FRawStatsMemoryProfiler::ProcessMemoryOperation( EMemoryOperation MemOp, uint64 Ptr, uint64 NewPtr, int64 Size, uint32 SequenceTag, const FStackState& StackState )
{
if (MemOp == EMemoryOperation::Alloc)
{
NumMemoryOperations++;
// Add a new allocation.
SequenceAllocationArray.Add(
FAllocationInfo(
0,
Ptr,
Size,
StackState.Stack,
SequenceTag,
EMemoryOperation::Alloc,
StackState.bIsBrokenCallstack
) );
LastSequenceTagForNamedMarker = SequenceTag;
}
else if (MemOp == EMemoryOperation::Realloc)
{
NumMemoryOperations++;
const uint64 OldPtr = Ptr;
// Add a new realloc.
SequenceAllocationArray.Add(
FAllocationInfo(
OldPtr,
NewPtr,
Size,
StackState.Stack,
SequenceTag,
EMemoryOperation::Realloc,
StackState.bIsBrokenCallstack
) );
LastSequenceTagForNamedMarker = SequenceTag;
}
else if (MemOp == EMemoryOperation::Free)
{
NumMemoryOperations++;
// Add a new free.
SequenceAllocationArray.Add(
FAllocationInfo(
0,
Ptr,
0,
StackState.Stack,
SequenceTag,
EMemoryOperation::Free,
StackState.bIsBrokenCallstack
) );
}
}
void FRawStatsMemoryProfiler::SortSequenceAllocations()
{
FScopeLogTime SLT( TEXT( "SortSequenceAllocations" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
// Sort all memory operation by the sequence tag, iterate through all operation and generate memory usage.
SequenceAllocationArray.Sort( FAllocationInfoSequenceTagLess() );
// Abandon support.
if (bShouldStopProcessing == true)
{
SetProcessingStage( EStatsProcessingStage::SPS_Stopped );
}
}
void FRawStatsMemoryProfiler::GenerateScopedTreeAllocations( const TMap<FName, FCombinedAllocationInfo>& ScopedAllocations, FNodeAllocationInfo& out_Root )
{
FScopeLogTime SLT( TEXT( "GenerateScopedTreeAllocations" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
// Decode all scoped allocations, generate tree for allocations and combine them.
for (const auto& It : ScopedAllocations)
{
const FName& EncodedCallstack = It.Key;
const FCombinedAllocationInfo& CombinedAllocation = It.Value;
// Decode callstack.
TArray<FName> DecodedCallstack;
FStatsCallstack::DecodeToNames( EncodedCallstack, DecodedCallstack );
const int32 AllocationLenght = DecodedCallstack.Num();
check( DecodedCallstack.Num() > 0 );
FNodeAllocationInfo* CurrentNode = &out_Root;
// Accumulate with thread root node.
CurrentNode->Accumulate( CombinedAllocation );
// Iterate through the callstack and prepare all nodes if needed, and accumulate memory.
TArray<FName> CurrentCallstack;
const int32 NumEntries = DecodedCallstack.Num();
for (int32 Idx1 = 0; Idx1 < NumEntries; ++Idx1)
{
const FName NodeName = DecodedCallstack[Idx1];
CurrentCallstack.Add( NodeName );
FNodeAllocationInfo* Node = nullptr;
const bool bContainsNode = CurrentNode->ChildNodes.Contains( NodeName );
if (!bContainsNode)
{
Node = new FNodeAllocationInfo;
Node->Depth = Idx1;
Node->PrepareCallstackData( CurrentCallstack );
CurrentNode->ChildNodes.Add( NodeName, Node );
}
else
{
Node = CurrentNode->ChildNodes.FindChecked( NodeName );
}
// Accumulate memory usage and num allocations for all nodes in the callstack.
Node->Accumulate( CombinedAllocation );
// Move to the next node.
Node->Parent = CurrentNode;
CurrentNode = Node;
}
}
out_Root.SortBySize();
}
void FRawStatsMemoryProfiler::ProcessAndDumpUObjectAllocations( const FName SnapshotName )
{
if (!SnapshotsWithAllocationMap.Contains(SnapshotName))
{
UE_LOG( LogStats, Warning, TEXT( "Snapshot not found: %s" ), *SnapshotName.ToString() );
return;
}
const TMap<uint64, FAllocationInfo>& AllocationMap = SnapshotsWithAllocationMap.FindChecked( SnapshotName );
FScopeLogTime SLT( TEXT( "ProcessingUObjectAllocations" ), nullptr, FScopeLogTime::ScopeLog_Seconds );
UE_LOG( LogStats, Warning, TEXT( "Processing UObject allocations" ) );
const FString ReportName = FString::Printf( TEXT( "%s-Memory-UObject" ), *GetPlatformName() );
FDiagnosticTableViewer MemoryReport( *FDiagnosticTableViewer::GetUniqueTemporaryFilePath( *ReportName ), true );
// Write a row of headings for the table's columns.
MemoryReport.AddColumn( TEXT( "Size (bytes)" ) );
MemoryReport.AddColumn( TEXT( "Size (MB)" ) );
MemoryReport.AddColumn( TEXT( "Count" ) );
MemoryReport.AddColumn( TEXT( "UObject class" ) );
MemoryReport.CycleRow();
TMap<FName, FCombinedAllocationInfo> UObjectAllocations;
// To minimize number of calls to expensive DecodeCallstack.
TMap<FName, FName> UObjectCallstackToClassMapping;
uint64 NumAllocations = 0;
uint64 TotalAllocatedMemory = 0;
for (const auto& It : AllocationMap)
{
const FAllocationInfo& Alloc = It.Value;
FName UObjectClass = UObjectCallstackToClassMapping.FindRef( Alloc.EncodedCallstack );
if (UObjectClass == NAME_None)
{
TArray<FName> DecodedCallstack;
FStatsCallstack::DecodeToNames( Alloc.EncodedCallstack, DecodedCallstack );
for (int32 Index = DecodedCallstack.Num() - 1; Index >= 0; --Index)
{
const FName LongName = DecodedCallstack[Index];
const bool bValid = UObjectRawNames.Contains( LongName );
if (bValid)
{
const FString ObjectName = FStatNameAndInfo::GetShortNameFrom( LongName ).GetPlainNameString();
UObjectClass = *ObjectName.Left( ObjectName.Find( TEXT( "//" ) ) );;
UObjectCallstackToClassMapping.Add( Alloc.EncodedCallstack, UObjectClass );
break;
}
}
}
if (UObjectClass != NAME_None)
{
FCombinedAllocationInfo& CombinedAllocation = UObjectAllocations.FindOrAdd( UObjectClass );
CombinedAllocation += Alloc;
TotalAllocatedMemory += Alloc.Size;
NumAllocations++;
}
}
// Dump memory to the log.
UObjectAllocations.ValueSort( FCombinedAllocationInfoSizeGreater() );
const float MaxPctDisplayed = 0.90f;
int32 CurrentIndex = 0;
uint64 DisplayedSoFar = 0;
UE_LOG( LogStats, VeryVerbose, TEXT( "Index, Size (Size MB), Count, UObject class" ) );
for (const auto& It : UObjectAllocations)
{
const FCombinedAllocationInfo& CombinedAllocation = It.Value;
const FName& UObjectClass = It.Key;
UE_LOG( LogStats, VeryVerbose, TEXT( "%2i, %llu (%.2f MB), %llu, %s" ),
CurrentIndex,
CombinedAllocation.Size,
CombinedAllocation.Size / 1024.0f / 1024.0f,
CombinedAllocation.Count,
*UObjectClass.GetPlainNameString() );
// Dump stats
MemoryReport.AddColumn( TEXT( "%llu" ), CombinedAllocation.Size );
MemoryReport.AddColumn( TEXT( "%.2f MB" ), CombinedAllocation.Size / 1024.0f / 1024.0f );
MemoryReport.AddColumn( TEXT( "%llu" ), CombinedAllocation.Count );
MemoryReport.AddColumn( *UObjectClass.GetPlainNameString() );
MemoryReport.CycleRow();
CurrentIndex++;
DisplayedSoFar += CombinedAllocation.Size;
const float CurrentPct = (float)DisplayedSoFar / (float)TotalAllocatedMemory;
if (CurrentPct > MaxPctDisplayed)
{
break;
}
}
UE_LOG( LogStats, VeryVerbose, TEXT( "Allocated memory: %llu bytes (%.2f MB)" ), TotalAllocatedMemory, TotalAllocatedMemory / 1024.0f / 1024.0f );
// Add a total row.
MemoryReport.CycleRow();
MemoryReport.CycleRow();
MemoryReport.CycleRow();
MemoryReport.AddColumn( TEXT( "%llu" ), TotalAllocatedMemory );
MemoryReport.AddColumn( TEXT( "%.2f MB" ), TotalAllocatedMemory / 1024.0f / 1024.0f );
MemoryReport.AddColumn( TEXT( "%llu" ), NumAllocations );
MemoryReport.AddColumn( TEXT( "TOTAL" ) );
MemoryReport.CycleRow();
}
void FRawStatsMemoryProfiler::DumpScopedAllocations( const TCHAR* Name, const TMap<FString, FCombinedAllocationInfo>& CombinedAllocations )
{
if (CombinedAllocations.Num() == 0)
{
UE_LOG( LogStats, Warning, TEXT( "No scoped allocations: %s" ), Name );
return;
}
FScopeLogTime SLT( TEXT( "ProcessingScopedAllocations" ), nullptr, FScopeLogTime::ScopeLog_Seconds );
UE_LOG( LogStats, Warning, TEXT( "Dumping scoped allocations: %s" ), Name );
const FString ReportName = FString::Printf( TEXT( "%s-Memory-Scoped-%s" ), *GetPlatformName(), Name );
FDiagnosticTableViewer MemoryReport( *FDiagnosticTableViewer::GetUniqueTemporaryFilePath( *ReportName ), true );
// Write a row of headings for the table's columns.
MemoryReport.AddColumn( TEXT( "Size (bytes)" ) );
MemoryReport.AddColumn( TEXT( "Size (MB)" ) );
MemoryReport.AddColumn( TEXT( "Count" ) );
MemoryReport.AddColumn( TEXT( "Callstack" ) );
MemoryReport.CycleRow();
FCombinedAllocationInfo Total;
const float MaxPctDisplayed = 0.90f;
int32 CurrentIndex = 0;
UE_LOG( LogStats, VeryVerbose, TEXT( "Index, Size (Size MB), Count, Stat desc" ) );
for (const auto& It : CombinedAllocations)
{
const FCombinedAllocationInfo& CombinedAllocation = It.Value;
//const FName& EncodedCallstack = It.Key;
const FString AllocCallstack = It.Key;// GetCallstack( EncodedCallstack );
UE_LOG( LogStats, VeryVerbose, TEXT( "%2i, %llu (%.2f MB), %llu, %s" ),
CurrentIndex,
CombinedAllocation.Size,
CombinedAllocation.Size / 1024.0f / 1024.0f,
CombinedAllocation.Count,
*AllocCallstack );
// Dump stats
MemoryReport.AddColumn( TEXT( "%llu" ), CombinedAllocation.Size );
MemoryReport.AddColumn( TEXT( "%.2f MB" ), CombinedAllocation.Size / 1024.0f / 1024.0f );
MemoryReport.AddColumn( TEXT( "%llu" ), CombinedAllocation.Count );
MemoryReport.AddColumn( *AllocCallstack );
MemoryReport.CycleRow();
CurrentIndex++;
Total += CombinedAllocation;
}
UE_LOG( LogStats, VeryVerbose, TEXT( "Allocated memory: %llu bytes (%.2f MB)" ), Total.Size, Total.SizeMB );
// Add a total row.
MemoryReport.CycleRow();
MemoryReport.CycleRow();
MemoryReport.CycleRow();
MemoryReport.AddColumn( TEXT( "%llu" ), Total.Size );
MemoryReport.AddColumn( TEXT( "%.2f MB" ), Total.SizeMB );
MemoryReport.AddColumn( TEXT( "%llu" ), Total.Count );
MemoryReport.AddColumn( TEXT( "TOTAL" ) );
MemoryReport.CycleRow();
}
void FRawStatsMemoryProfiler::GenerateScopedAllocations( const TMap<uint64, FAllocationInfo>& InAllocationMap, TMap<FName, FCombinedAllocationInfo>& out_CombinedAllocations, uint64& TotalAllocatedMemory, uint64& NumAllocations )
{
FScopeLogTime SLT( TEXT( "GenerateScopedAllocations" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
for (const auto& It : InAllocationMap)
{
const FAllocationInfo& Alloc = It.Value;
FCombinedAllocationInfo& CombinedAllocation = out_CombinedAllocations.FindOrAdd( Alloc.EncodedCallstack );
CombinedAllocation += Alloc;
TotalAllocatedMemory += Alloc.Size;
NumAllocations++;
}
// Sort by size.
out_CombinedAllocations.ValueSort( FCombinedAllocationInfoSizeGreater() );
}
void FRawStatsMemoryProfiler::PrepareSnapshot( const FName SnapshotName, const TMap<uint64, FAllocationInfo>& InAllocationMap )
{
FScopeLogTime SLT( TEXT( "PrepareSnapshot" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
// Make sure the snapshot name is unique.
FName UniqueSnapshotName = SnapshotName;
while (SnapshotNamesSet.Contains( UniqueSnapshotName ))
{
UniqueSnapshotName = FName( UniqueSnapshotName, UniqueSnapshotName.GetNumber() + 1 );
}
SnapshotNamesSet.Add( UniqueSnapshotName );
SnapshotsWithAllocationMap.Add( UniqueSnapshotName, InAllocationMap );
TMap<FName, FCombinedAllocationInfo> SnapshotCombinedAllocations;
uint64 TotalAllocatedMemory = 0;
uint64 NumAllocations = 0;
GenerateScopedAllocations( InAllocationMap, SnapshotCombinedAllocations, TotalAllocatedMemory, NumAllocations );
SnapshotsWithScopedAllocations.Add( UniqueSnapshotName, SnapshotCombinedAllocations );
// Decode callstacks.
// Replace encoded callstacks with human readable name. For easier debugging.
TMap<FString, FCombinedAllocationInfo> SnapshotDecodedCombinedAllocations;
for (auto& It : SnapshotCombinedAllocations)
{
const FString HumanReadableCallstack = FStatsCallstack::GetHumanReadable( It.Key );
SnapshotDecodedCombinedAllocations.Add( HumanReadableCallstack, It.Value );
}
SnapshotsWithDecodedScopedAllocations.Add( UniqueSnapshotName, SnapshotDecodedCombinedAllocations );
UE_LOG( LogStats, Warning, TEXT( "PrepareSnapshot: %s Alloc: %i Scoped: %i Total: %.2f MB" ), *UniqueSnapshotName.ToString(), InAllocationMap.Num(), SnapshotCombinedAllocations.Num(), TotalAllocatedMemory / 1024.0f / 1024.0f );
}
void FRawStatsMemoryProfiler::CompareSnapshots( const FName BeginSnaphotName, const FName EndSnaphotName, TMap<FName, FCombinedAllocationInfo>& out_Result )
{
FScopeLogTime SLT( TEXT( "CompareSnapshots" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
const auto BeginSnaphotPtr = SnapshotsWithScopedAllocations.Find( BeginSnaphotName );
const auto EndSnapshotPtr = SnapshotsWithScopedAllocations.Find( EndSnaphotName );
if (BeginSnaphotPtr && EndSnapshotPtr)
{
// Process data.
TMap<FName, FCombinedAllocationInfo> BeginSnaphot = *BeginSnaphotPtr;
TMap<FName, FCombinedAllocationInfo> EndSnaphot = *EndSnapshotPtr;
TMap<FName, FCombinedAllocationInfo> Result;
for (const auto& It : EndSnaphot)
{
const FName Callstack = It.Key;
const FCombinedAllocationInfo EndCombinedAlloc = It.Value;
const FCombinedAllocationInfo* BeginCombinedAllocPtr = BeginSnaphot.Find( Callstack );
if (BeginCombinedAllocPtr)
{
FCombinedAllocationInfo CombinedAllocation;
CombinedAllocation += EndCombinedAlloc;
CombinedAllocation -= *BeginCombinedAllocPtr;
if (CombinedAllocation.IsAlive())
{
out_Result.Add( Callstack, CombinedAllocation );
}
}
else
{
out_Result.Add( Callstack, EndCombinedAlloc );
}
}
// Sort by size.
out_Result.ValueSort( FCombinedAllocationInfoSizeGreater() );
}
}
void FRawStatsMemoryProfiler::CompareSnapshotsHumanReadable( const FName BeginSnaphotName, const FName EndSnaphotName, TMap<FString, FCombinedAllocationInfo>& out_Result )
{
FScopeLogTime SLT( TEXT( "CompareSnapshotsHumanReadable" ), nullptr, FScopeLogTime::ScopeLog_Milliseconds );
const auto BeginSnaphotPtr = SnapshotsWithDecodedScopedAllocations.Find( BeginSnaphotName );
const auto EndSnapshotPtr = SnapshotsWithDecodedScopedAllocations.Find( EndSnaphotName );
if (BeginSnaphotPtr && EndSnapshotPtr)
{
// Process data.
TMap<FString, FCombinedAllocationInfo> BeginSnaphot = *BeginSnaphotPtr;
TMap<FString, FCombinedAllocationInfo> EndSnaphot = *EndSnapshotPtr;
for (const auto& It : EndSnaphot)
{
const FString& Callstack = It.Key;
const FCombinedAllocationInfo EndCombinedAlloc = It.Value;
const FCombinedAllocationInfo* BeginCombinedAllocPtr = BeginSnaphot.Find( Callstack );
if (BeginCombinedAllocPtr)
{
FCombinedAllocationInfo CombinedAllocation;
CombinedAllocation += EndCombinedAlloc;
CombinedAllocation -= *BeginCombinedAllocPtr;
if (CombinedAllocation.IsAlive())
{
out_Result.Add( Callstack, CombinedAllocation );
}
}
else
{
out_Result.Add( Callstack, EndCombinedAlloc );
}
}
// Sort by size.
out_Result.ValueSort( FCombinedAllocationInfoSizeGreater() );
}
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
}