FEventGraphData::FEventGraphData( const FEventGraphData& Source ) 
	: FrameStartIndex( Source.FrameStartIndex )
	, FrameEndIndex( Source.FrameEndIndex )
{
	RootEvent = Source.GetRoot()->DuplicateWithHierarchyPtr();
	RootEvent->SetRootAndThreadForAllChildren();
}
FEventGraphData::FEventGraphData( const FProfilerSession * const InProfilerSession, const uint32 InFrameIndex )
	: FrameStartIndex( InFrameIndex )
	, FrameEndIndex( InFrameIndex+1 )
{
	static FTotalTimeAndCount Current(0.0f, 0);
	PROFILER_SCOPE_LOG_TIME( TEXT( "FEventGraphData::FEventGraphData" ), &Current );

	Description = FString::Printf( TEXT("%s: %i"), *InProfilerSession->GetShortName(), InFrameIndex );

	// @TODO: Duplicate is not needed, remove it later.
	const IDataProviderRef& SessionDataProvider = InProfilerSession->GetDataProvider(); 
	const IDataProviderRef DataProvider = SessionDataProvider->Duplicate<FArrayDataProvider>( FrameStartIndex );

	const double FrameDurationMS = DataProvider->GetFrameTimeMS( 0 ); 
	const FProfilerSample& RootProfilerSample = DataProvider->GetCollection()[0];

	RootEvent = FEventGraphSample::CreateNamedEvent( FEventGraphConsts::RootEvent );

	PopulateHierarchy_Recurrent( InProfilerSession, RootEvent, RootProfilerSample, DataProvider );

	// Root sample contains FrameDurationMS
	const FProfilerStatMetaDataRef& MetaData = InProfilerSession->GetMetaData();
	RootEvent->_InclusiveTimeMS = MetaData->ConvertCyclesToMS( RootProfilerSample.GetDurationCycles() );
	RootEvent->_MaxInclusiveTimeMS = RootEvent->_MinInclusiveTimeMS = RootEvent->_AvgInclusiveTimeMS = RootEvent->_InclusiveTimeMS;
	RootEvent->_InclusiveTimePct = 100.0f;

	RootEvent->_MinNumCallsPerFrame = RootEvent->_MaxNumCallsPerFrame = RootEvent->_AvgNumCallsPerFrame = RootEvent->_NumCallsPerFrame;

	// Set root and thread event.
	RootEvent->SetRootAndThreadForAllChildren();
	// Fix all children. 
	const double MyNumFrames = 1.0;
	RootEvent->FixChildrenTimesAndCalcAveragesForAllChildren( MyNumFrames );
}
void FEventGraphData::Finalize( const uint32 InFrameStartIndex, const uint32 InFrameEndIndex )
{
	FrameStartIndex = InFrameStartIndex;
	FrameEndIndex = InFrameEndIndex;
	const double NumFrames = (double)GetNumFrames();

	// Set root and thread event.
	RootEvent->SetRootAndThreadForAllChildren();
	// Fix all children. 
	RootEvent->FixChildrenTimesAndCalcAveragesForAllChildren( NumFrames );
}