Files
UnrealEngineUWP/Engine/Source/Programs/UnrealFrontend/Private/Commands/StatsConvertCommand.cpp
Robert Manuszewski f9cdeb96cd 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

213 lines
6.0 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "UnrealFrontendPrivatePCH.h"
#include "StatsConvertCommand.h"
void FStatsConvertCommand::WriteString( FArchive& Writer, const ANSICHAR* Format, ... )
{
ANSICHAR Array[1024];
va_list ArgPtr;
va_start(ArgPtr,Format);
// Build the string
int32 Result = FCStringAnsi::GetVarArgs(Array,ARRAY_COUNT(Array),ARRAY_COUNT(Array)-1,Format,ArgPtr);
// Now write that to the file
Writer.Serialize((void*)Array,Result);
}
void FStatsConvertCommand::InternalRun()
{
#if STATS
// get the target file
FString TargetFile;
FParse::Value(FCommandLine::Get(), TEXT("-INFILE="), TargetFile);
FString OutFile;
FParse::Value(FCommandLine::Get(), TEXT("-OUTFILE="), OutFile);
FString StatListString;
FParse::Value(FCommandLine::Get(), TEXT("-STATLIST="), StatListString);
// get the list of stats
TArray<FString> StatArrayString;
if (StatListString.ParseIntoArray(StatArrayString, TEXT("+"), true) == 0)
{
StatArrayString.Add(TEXT("STAT_FrameTime"));
}
// convert to FNames for faster compare
for( const FString& It : StatArrayString )
{
StatList.Add(*It);
}
// open a csv file for write
TAutoPtr<FArchive> FileWriter( IFileManager::Get().CreateFileWriter( *OutFile ) );
if (!FileWriter)
{
UE_LOG( LogStats, Error, TEXT( "Could not open output file: %s" ), *OutFile );
return;
}
// @TODO yrx 2014-03-24 move to function
// attempt to read the data and convert to csv
const int64 Size = IFileManager::Get().FileSize( *TargetFile );
if( Size < 4 )
{
UE_LOG( LogStats, Error, TEXT( "Could not open input file: %s" ), *TargetFile );
return;
}
TAutoPtr<FArchive> FileReader( IFileManager::Get().CreateFileReader( *TargetFile ) );
if( !FileReader )
{
UE_LOG( LogStats, Error, TEXT( "Could not open input file: %s" ), *TargetFile );
return;
}
if( !Stream.ReadHeader( *FileReader ) )
{
UE_LOG( LogStats, Error, TEXT( "Could not open input file, bad magic: %s" ), *TargetFile );
return;
}
// This is not supported yet.
if (Stream.Header.bRawStatsFile)
{
UE_LOG( LogStats, Error, TEXT( "Could not open input file, not supported type (raw): %s" ), *TargetFile );
return;
}
const bool bIsFinalized = Stream.Header.IsFinalized();
if( bIsFinalized )
{
// Read metadata.
TArray<FStatMessage> MetadataMessages;
Stream.ReadFNamesAndMetadataMessages( *FileReader, MetadataMessages );
ThreadState.ProcessMetaDataOnly( MetadataMessages );
// Read frames offsets.
Stream.ReadFramesOffsets( *FileReader );
FileReader->Seek( Stream.FramesInfo[0].FrameFileOffset );
}
if( Stream.Header.HasCompressedData() )
{
UE_CLOG( !bIsFinalized, LogStats, Fatal, TEXT( "Compressed stats file has to be finalized" ) );
}
ReadAndConvertStatMessages( *FileReader, *FileWriter );
#endif // STATS
}
void FStatsConvertCommand::ReadAndConvertStatMessages( FArchive& Reader, FArchive& Writer )
{
// output the csv header
WriteString( Writer, "Frame,Name,Value\r\n" );
uint64 ReadMessages = 0;
TArray<FStatMessage> Messages;
// Buffer used to store the compressed and decompressed data.
TArray<uint8> SrcData;
TArray<uint8> DestData;
const bool bHasCompressedData = Stream.Header.HasCompressedData();
const bool bIsFinalized = Stream.Header.IsFinalized();
float DataLoadingProgress = 0.0f;
// Sanity checks.
check( bHasCompressedData );
while( Reader.Tell() < Reader.TotalSize() )
{
// Read the compressed data.
FCompressedStatsData UncompressedData( SrcData, DestData );
Reader << UncompressedData;
if( UncompressedData.HasReachedEndOfCompressedData() )
{
return;
}
FMemoryReader MemoryReader( DestData, true );
while( MemoryReader.Tell() < MemoryReader.TotalSize() )
{
// read the message
FStatMessage Message( Stream.ReadMessage( MemoryReader, bIsFinalized ) );
ReadMessages++;
if( ReadMessages % 32768 == 0 )
{
UE_LOG( LogStats, Log, TEXT( "StatsConvertCommand progress: %.1f%%" ), DataLoadingProgress );
}
if( Message.NameAndInfo.GetShortName() != TEXT( "Unknown FName" ) )
{
if( Message.NameAndInfo.GetField<EStatOperation>() == EStatOperation::AdvanceFrameEventGameThread && ReadMessages > 2 )
{
new (Messages) FStatMessage( Message );
ThreadState.AddMessages( Messages );
Messages.Reset();
CollectAndWriteStatsValues( Writer );
DataLoadingProgress = (double)Reader.Tell() / (double)Reader.TotalSize() * 100.0f;
}
new (Messages) FStatMessage( Message );
}
else
{
break;
}
}
}
}
void FStatsConvertCommand::CollectAndWriteStatsValues( FArchive& Writer )
{
// get the thread stats
TArray<FStatMessage> Stats;
ThreadState.GetInclusiveAggregateStackStats(ThreadState.CurrentGameFrame, Stats);
// The tick rate for different platforms will be different. We cannot use the Windows tick rate accurately here. We will pull it from the stats,
// but until we encounter one our best bet is to leave values as full ticks that can be analysed by hand.
double MillisecondsPerCycle = 1.0f;
for (int32 Index = 0; Index < Stats.Num(); ++Index)
{
FStatMessage const& Meta = Stats[Index];
//UE_LOG(LogTemp, Display, TEXT("Stat: %s"), *Meta.NameAndInfo.GetShortName().ToString());
if (Meta.NameAndInfo.GetShortName() == FStatConstants::NAME_SecondsPerCycle)
{
// SecondsPerCycle may vary over time, so we update it here
MillisecondsPerCycle = Meta.GetValue_double() * 1000.0f;
}
for (int32 Jndex = 0; Jndex < StatList.Num(); ++Jndex)
{
if (Meta.NameAndInfo.GetShortName() == StatList[Jndex])
{
double StatValue = 0.0f;
if (Meta.NameAndInfo.GetFlag(EStatMetaFlags::IsPackedCCAndDuration))
{
StatValue = MillisecondsPerCycle * FromPackedCallCountDuration_Duration(Meta.GetValue_int64());
}
else if (Meta.NameAndInfo.GetFlag(EStatMetaFlags::IsCycle))
{
StatValue = MillisecondsPerCycle * Meta.GetValue_int64();
}
else
{
StatValue = Meta.GetValue_int64();
}
// write out to the csv file
WriteString( Writer, "%d,%S,%f\r\n", ThreadState.CurrentGameFrame, *StatList[Jndex].ToString(), StatValue );
}
}
}
}