예제 #1
0
void FProfilerManager::SessionManager_OnInstanceSelectionChanged()
{
	const ISessionInfoPtr& SelectedSession = SessionManager->GetSelectedSession();
	const bool SessionIsValid = SelectedSession.IsValid() && (SelectedSession->GetSessionOwner() == FPlatformProcess::UserName(true));

	if( ActiveSession != SelectedSession || FProfilerManager::GetSettings().bSingleInstanceMode )
	{
		ClearStatsAndInstances();

		if (SessionIsValid)
		{
			ActiveSession = SelectedSession;
			ProfilerClient->Subscribe( ActiveSession->GetSessionId() );
			ProfilerType = EProfilerSessionTypes::Live;
			SetViewMode( EProfilerViewMode::LineIndexBased );
		}
		else
		{
			ActiveSession = nullptr;
			ProfilerType = EProfilerSessionTypes::InvalidOrMax;
		}
	}

	if( ActiveSession.IsValid() )
	{
		// Track all selected session instances.
		SessionManager->GetSelectedInstances( SelectedSessionInstances );
		const int32 NumSelectedInstances = SelectedSessionInstances.Num();
		const int32 NumInstances = FMath::Min( NumSelectedInstances, FProfilerManager::GetSettings().bSingleInstanceMode ? 1 : NumSelectedInstances );

		for( int32 Index = 0; Index < NumInstances; ++Index )
		{
			const ISessionInstanceInfoPtr SessionInstanceInfo = SelectedSessionInstances[Index];
			const FGuid ProfilerInstanceID = SessionInstanceInfo->GetInstanceId();
			const bool bAlreadyAdded = ProfilerSessionInstances.Contains( ProfilerInstanceID );

			if( !bAlreadyAdded )
			{
				FProfilerSessionRef ProfilerSession = MakeShareable( new FProfilerSession( SessionInstanceInfo ) );
				ProfilerSession->SetOnAddThreadTime( FProfilerSession::FAddThreadTimeDelegate::CreateSP( this, &FProfilerManager::ProfilerSession_OnAddThreadTime ) );

				ProfilerSessionInstances.Add( ProfilerSession->GetInstanceID(), ProfilerSession );
				ProfilerClient->Track( ProfilerInstanceID );
				TSharedPtr<SProfilerWindow> ProfilerWindow = GetProfilerWindow();
				if (ProfilerWindow.IsValid())
				{
					ProfilerWindow->ManageEventGraphTab(ProfilerInstanceID, true, ProfilerSession->GetName());
				}
			}
		}
	}

	SessionInstancesUpdatedEvent.Broadcast();
}