Files
UnrealEngineUWP/Engine/Source/Developer/TaskGraph/Private/SEventsTree.cpp
Ben Marsh 3e80336791 Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3092544)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3079316 on 2016/08/05 by Ben.Marsh

	Better PCH selection in ShaderFormatOpenGL and MetalShaderFormat - make sure Core is the first included header.

Change 3080579 on 2016/08/08 by Ben.Marsh

	Slate: Move DEBUG_TAB_MANAGEMENT into SDockingTabStack.h to remove circular include dependency with DockingPrivate.h.

Change 3080587 on 2016/08/08 by Ben.Marsh

	StandaloneRenderer: Move platform includes into a separate header so we can make individual headers self-contained, without having a circular dependency on StandaloneRendererPrivate.h.

Change 3080789 on 2016/08/08 by Ben.Marsh

	Move BuildGraph tasks for chunking, posting builds, labeling builds, and merging manifests into the MCP project. While we do provide public interfaces for this functionality, we don't currently expect anyone outside Epic to be using them.

Change 3080815 on 2016/08/08 by Ben.Marsh

	BuildGraph: Add a -GenerateDocs option, which writes out an HTML file constructed from C# XML documentation containing all the task information.

Change 3081374 on 2016/08/08 by Ben.Marsh

	UBT: Invalidate the makefile if any UHT headers are deleted. Should fix issue where files are moved from one module to another, and the original module no longer contains any generated headers. Its include path needs to be removed from the compile environment.

Change 3083152 on 2016/08/09 by Ben.Marsh

	PR #2667: Add Intel C++ Compiler support to Windows build (Contributed by JeffRous)

Change 3084039 on 2016/08/10 by Ben.Marsh

	BuildGraph: Add additional markup for parameter attributes. Also improve some documation.

Change 3084240 on 2016/08/10 by Ben.Marsh

	Plugins: Allow plugins in the project folder to replace plugins in the engine folder with the same name. Prohibit multiple plugins with the same name at other times.

Change 3084337 on 2016/08/10 by Ben.Marsh

	UBT: Specify the -precompile option when generating project files for a target, so we include all valid modules for intellisense.

Change 3085594 on 2016/08/11 by Ben.Marsh

	Change modules which reference a public header for their PCH to use a private PCH instead, even if it just includes the public header for now.

Change 3085999 on 2016/08/11 by Ben.Marsh

	Add some missing #pragma once directives.

Change 3086146 on 2016/08/11 by Ben.Marsh

	Core: Move prototype and linkage specifier for ConsoleCommandLibrary_* functions into header matching cpp file.

Change 3086172 on 2016/08/11 by Ben.Marsh

	Fixup some C-style header guards to use #pragma once instead.

Change 3087289 on 2016/08/12 by Ben.Marsh

	Split out UPackage and UMetaData into their own headers (they're already implemented in separate CPP files)

Change 3087310 on 2016/08/12 by Ben.Marsh

	Move method stubs for FNullSlateSoundDevice into a CPP file, since they're exported from the SlateCore module.

Change 3087341 on 2016/08/12 by Ben.Marsh

	UdpMessaging: Move PCH before #if PLATFORM_DESKTOP; it will only be defined if the definition is included.

Change 3087457 on 2016/08/12 by Ben.Marsh

	Core: Reorganize the FTransform and FMatrix headers: Transform.h now includes TransformNonVectorized.h or TransformVectorized.h as appropriate, and UnrealMatrix.h is now Matrix.inl (and included from Matrix.h).

Change 3088407 on 2016/08/13 by Ben.Marsh

	Replace use of Windows SIZE_T define with the regular C++ size_t.

Change 3088416 on 2016/08/13 by Ben.Marsh

	Include a header from all .generated.cpp files (GeneratedCppIncludes.h) which includes all the basic types required to compile them, rather than assuming that the module PCH will include everything.

	Also include the real declarations of noexport classes in Object.h (now renamed to NoExportTypes.h for clarity) when the CPP macro is defined, so the .generated.deps.h file will automatically have the correct definitions for them at compile time rather than relying on them being in the private PCH.

	Finally, rename UObject.h to Object.h for consistency with the naming convention for all other UObject classes. UObject.h still exists for now, but outputs a deprecated message if included.

Change 3088544 on 2016/08/14 by Ben.Marsh

	Core: Move the definition of the TEXT() macro into Platform.h, to avoid having to include OS headers to get it.

Change 3088552 on 2016/08/14 by Ben.Marsh

	Fix compile errors for some modules that don't already include CoreUObject.h.

Change 3088925 on 2016/08/15 by Ben.Marsh

	Remove circular include dependencies from VulkanRHI.

Change 3088926 on 2016/08/15 by Ben.Marsh

	Remove duplicate definition for WITH_FIXED_AREA_ENTERING_COST from EngineDefines.h - always uses the definition from DetourNavMeshQuery.h instead.

Change 3088930 on 2016/08/15 by Ben.Marsh

	Remove circular include dependency from PhysX.

Change 3088935 on 2016/08/15 by Ben.Marsh

	OnlineSubsystemUtils: Move CPP files out of public header directory.

Change 3088965 on 2016/08/15 by Ben.Marsh

	Add private PCH to Landscape, MoviePlayer, TaskGraph, XAudio2 and RealtimeProfiler modules.

Change 3088966 on 2016/08/15 by Ben.Marsh

	Engine: Move CPP files out of public header directories.

Change 3089520 on 2016/08/15 by Ben.Marsh

	BuildGraph: Change documentation command to output markdown.

Change 3090299 on 2016/08/16 by Ben.Marsh

	D3D12RHI: Move around some implementations to fix circular header dependencies which are masked by delayed template instantiation.

Change 3090303 on 2016/08/16 by Ben.Marsh

	Engine: Add a template specialization for TPointerIsConvertibleFromTo<AActor, const volatile UObject> to fix dependency on complete AActor definition for static assert in TWeakPointer<AActor>, which only appears if including Level.h without Actor.h. Delayed template instantiation usually masks this issue.

Change 3091861 on 2016/08/17 by Ben.Marsh

	Remove circular header dependencies, and fix ambiguous include paths in OSVR.

Change 3092068 on 2016/08/17 by Ben.Marsh

	Moving VulkanDynamicRHI into its own header.

Change 3093133 on 2016/08/18 by Ben.Marsh

	EC: Include additional context lines for Clang errors.

Change 3093147 on 2016/08/18 by Ben.Marsh

	UBT: Add an error message when attempting to do a single-file compile with the wrong target selected.

Change 3093228 on 2016/08/18 by Ben.Marsh

	Remove redundant setting for remote server name from XML config, and set it to a valid machine in the engine config.

[CL 3093264 by Ben Marsh in Main branch]
2016-08-18 10:28:43 -04:00

672 lines
21 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "TaskGraphPrivatePCH.h"
#include "SlateBasics.h"
#include "TaskGraphInterfaces.h"
#include "VisualizerEvents.h"
#include "SEventsTree.h"
#include "SSearchBox.h"
#define LOCTEXT_NAMESPACE "SEventsTree"
FName SEventsTree::NAME_NameColumn = FName(*NSLOCTEXT("TaskGraph", "ColumnName", "Name").ToString());
FName SEventsTree::NAME_DurationColumn = FName( *NSLOCTEXT("TaskGraph", "ColumnDuration", "Duration").ToString() );
void SEventItem::Construct( const FArguments& InArgs, const TSharedRef<STableViewBase>& InOwnerTableView )
{
EventName = InArgs._EventName;
EventDuration = InArgs._EventDuration;
SMultiColumnTableRow< TSharedPtr< FVisualizerEvent > >::Construct( FSuperRowType::FArguments(), InOwnerTableView );
}
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
TSharedRef< SWidget > SEventItem::GenerateWidgetForColumn( const FName& ColumnName )
{
if( ColumnName == SEventsTree::NAME_NameColumn )
{
return
SNew(SHorizontalBox)
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew( SExpanderArrow, SharedThis(this) )
]
+SHorizontalBox::Slot()
.AutoWidth()
[
SNew( STextBlock )
.Text( FText::FromString(EventName) )
];
}
else if( ColumnName == SEventsTree::NAME_DurationColumn )
{
return SNew( STextBlock )
.Text( this, &SEventItem::GetDurationText );
}
else
{
return
SNew( STextBlock )
. Text(FText::Format( LOCTEXT("UnsupportedColumnFmt", "Unsupported Column: {0}"), FText::FromName(ColumnName) ) );
}
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SEventsTree::Construct( const FArguments& InArgs )
{
DurationUnits = EVisualizerTimeUnits::Milliseconds;
ViewMode = EVisualizerViewMode::Hierarchical;
bSuppressSelectionChangedEvent = false;
OnEventSelectionChangedDelegate = InArgs._OnEventSelectionChanged;
ProfileData = InArgs._ProfileData.Get();
// Duration column drop down menu
const bool bInShouldCloseWindowAfterMenuSelection = true;
FMenuBuilder MenuBuilder( bInShouldCloseWindowAfterMenuSelection, NULL );
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetDurationUnits, EVisualizerTimeUnits::Microseconds ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckDurationUnits, EVisualizerTimeUnits::Microseconds ) );
MenuBuilder.AddMenuEntry( LOCTEXT("Microseconds", "Microseconds"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetDurationUnits, EVisualizerTimeUnits::Milliseconds ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckDurationUnits, EVisualizerTimeUnits::Milliseconds ) );
MenuBuilder.AddMenuEntry( LOCTEXT("Milliseconds", "Milliseconds"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetDurationUnits, EVisualizerTimeUnits::Seconds ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckDurationUnits, EVisualizerTimeUnits::Seconds ) );
MenuBuilder.AddMenuEntry( LOCTEXT("Seconds", "Seconds"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
// Name column drop down menu
FMenuBuilder NameMenuBuilder( bInShouldCloseWindowAfterMenuSelection, NULL );
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetViewMode, EVisualizerViewMode::Hierarchical ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckViewMode, EVisualizerViewMode::Hierarchical ) );
NameMenuBuilder.AddMenuEntry( LOCTEXT("Hierarchical", "Hierarchical"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetViewMode, EVisualizerViewMode::Flat ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckViewMode, EVisualizerViewMode::Flat ) );
NameMenuBuilder.AddMenuEntry( LOCTEXT("Flat", "Flat"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetViewMode, EVisualizerViewMode::Coalesced ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckViewMode, EVisualizerViewMode::Coalesced ) );
NameMenuBuilder.AddMenuEntry( LOCTEXT("Coalesced", "Coalesced"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
{
FUIAction Action( FExecuteAction::CreateSP( this, &SEventsTree::SetViewMode, EVisualizerViewMode::FlatCoalesced ),
FCanExecuteAction(),
FIsActionChecked::CreateSP( this, &SEventsTree::CheckViewMode, EVisualizerViewMode::FlatCoalesced ) );
NameMenuBuilder.AddMenuEntry( LOCTEXT("FlatCoalesced", "Flat Coalesced"), FText(), FSlateIcon(), Action, NAME_None, EUserInterfaceActionType::Check );
}
this->ChildSlot
[
SNew( SVerticalBox )
+SVerticalBox::Slot().AutoHeight().Padding( 1.0f, 0.0f, 1.0f, 2.0f )
[
SNew( SSearchBox )
.ToolTipText( NSLOCTEXT("TaskGraph", "FilterSearchHint", "Type here to search events.") )
.OnTextChanged( this, &SEventsTree::OnFilterTextChanged )
.OnTextCommitted( this, &SEventsTree::OnFilterTextCommitted )
]
+SVerticalBox::Slot().Padding( 2 ).FillHeight( 1 ).VAlign( VAlign_Fill )
[
SNew( SHorizontalBox )
+SHorizontalBox::Slot().Padding( 2 ).FillWidth( 1 ).HAlign( HAlign_Fill )
[
// List of all events for the selected thread
SAssignNew( EventsListView, STreeView< TSharedPtr< FVisualizerEvent > > )
// List view items are this tall
.ItemHeight( 12 )
// Tell the list view where to get its source data
.TreeItemsSource( &SelectedEventsView )
// When the list view needs to generate a widget for some data item, use this method
.OnGenerateRow( this, &SEventsTree::OnGenerateWidgetForEventsList )
// Given some DataItem, this is how we find out if it has any children and what they are.
.OnGetChildren( this, &SEventsTree::OnGetChildrenForEventsList )
// Selection mode
.SelectionMode( ESelectionMode::Single )
// Selection callback
.OnSelectionChanged( this, &SEventsTree::OnEventSelectionChanged )
.HeaderRow
(
SNew( SHeaderRow )
+ SHeaderRow::Column( NAME_NameColumn )
.DefaultLabel( NSLOCTEXT("TaskGraph", "ColumnName", "Name") )
.SortMode( TAttribute< EColumnSortMode::Type >::Create( TAttribute< EColumnSortMode::Type >::FGetter::CreateSP( this, &SEventsTree::GetColumnSortMode, NAME_NameColumn ) ) )
.OnSort( FOnSortModeChanged::CreateSP( this, &SEventsTree::OnColumnSortModeChanged ) )
.FillWidth( 1.0f )
.MenuContent()
[
NameMenuBuilder.MakeWidget()
]
+ SHeaderRow::Column( NAME_DurationColumn )
.DefaultLabel( this, &SEventsTree::GetDurationColumnTitle )
.SortMode( TAttribute< EColumnSortMode::Type >::Create( TAttribute< EColumnSortMode::Type >::FGetter::CreateSP( this, &SEventsTree::GetColumnSortMode, NAME_DurationColumn ) ) )
.OnSort( FOnSortModeChanged::CreateSP( this, &SEventsTree::OnColumnSortModeChanged ) )
.FixedWidth( 128.0f )
.MenuContent()
[
MenuBuilder.MakeWidget()
]
)
]
]
];
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
EColumnSortMode::Type SEventsTree::GetColumnSortMode( const FName ColumnId )
{
if ( SortByColumn != ColumnId )
{
return EColumnSortMode::None;
}
return SortMode;
}
FText SEventsTree::GetDurationColumnTitle() const
{
static const FText Units[] = { NSLOCTEXT("TaskGraph", "microseconds", "microseconds"), NSLOCTEXT("TaskGraph", "milliseconds", "ms"), NSLOCTEXT("TaskGraph", "seconds", "s") };
return FText::Format( NSLOCTEXT("TaskGraph", "ColumnDurationValue", "Duration ({0})"), Units[ DurationUnits ] );
}
void ClearEventsSelection( TArray< TSharedPtr< FVisualizerEvent > >& Events )
{
for( int32 Index = 0; Index < Events.Num(); ++Index )
{
TSharedPtr< FVisualizerEvent > CurrentEvent = Events[ Index ];
CurrentEvent->IsSelected = false;
// Clear recursively
if( CurrentEvent->Children.Num() )
{
ClearEventsSelection( CurrentEvent->Children );
}
}
}
void SEventsTree::OnEventSelectionChanged( TSharedPtr< FVisualizerEvent > Selection, ESelectInfo::Type /*SelectInfo*/ )
{
if( Selection.IsValid() )
{
ClearEventsSelection( SelectedEventsView );
Selection->IsSelected = true;
// Mirror the selection in the source events list
TSharedPtr< FVisualizerEvent > MappedSelection = ViewToEventsMap.FindChecked( Selection );
MappedSelection->IsSelected = true;
if( !bSuppressSelectionChangedEvent )
{
OnEventSelectionChangedDelegate.ExecuteIfBound( MappedSelection );
}
}
else if( !bSuppressSelectionChangedEvent )
{
OnEventSelectionChangedDelegate.ExecuteIfBound( Selection );
}
}
TSharedRef< ITableRow > SEventsTree::OnGenerateWidgetForEventsList( TSharedPtr< FVisualizerEvent > InItem, const TSharedRef<STableViewBase>& OwnerTable )
{
return SNew( SEventItem, OwnerTable )
.EventName( InItem->EventName )
.EventDuration( this, &SEventsTree::GetEventDuration, InItem->DurationMs );
}
double SEventsTree::GetEventDuration( double InDurationMs ) const
{
switch( DurationUnits )
{
case EVisualizerTimeUnits::Microseconds:
return InDurationMs * 1000.0;
case EVisualizerTimeUnits::Milliseconds:
return InDurationMs;
case EVisualizerTimeUnits::Seconds:
return InDurationMs * 0.001;
}
return InDurationMs;
}
void SEventsTree::SetDurationUnits( EVisualizerTimeUnits::Type InUnits )
{
DurationUnits = InUnits;
EventsListView->RequestTreeRefresh();
}
void SEventsTree::SetViewMode( EVisualizerViewMode::Type InMode )
{
ViewMode = InMode;
CreateSelectedEventsView();
SortEventsList();
EventsListView->RequestTreeRefresh();
}
void SEventsTree::OnGetChildrenForEventsList( TSharedPtr<FVisualizerEvent> InItem, TArray<TSharedPtr<FVisualizerEvent> >& OutChildren )
{
OutChildren = InItem->Children;
}
void SEventsTree::OnColumnSortModeChanged( const EColumnSortPriority::Type SortPriority, const FName& ColumnId, const EColumnSortMode::Type InSortMode )
{
SortByColumn = ColumnId;
SortMode = InSortMode;
SortEventsList();
}
void SEventsTree::SortEventsList( TArray< TSharedPtr< FVisualizerEvent > >& Events )
{
// Sort taking the current settings into account
if( SortByColumn == NAME_NameColumn )
{
if( SortMode == EColumnSortMode::Ascending )
{
struct FCompareEventsByName
{
FORCEINLINE bool operator()( const TSharedPtr<FVisualizerEvent> A, const TSharedPtr<FVisualizerEvent> B ) const { return A->EventName < B->EventName; }
};
Events.Sort( FCompareEventsByName() );
}
else if( SortMode == EColumnSortMode::Descending )
{
struct FCompareEventsByNameDescending
{
FORCEINLINE bool operator()( const TSharedPtr<FVisualizerEvent> A, const TSharedPtr<FVisualizerEvent> B ) const { return B->EventName < A->EventName; }
};
Events.Sort( FCompareEventsByNameDescending() );
}
}
else if( SortByColumn == NAME_DurationColumn )
{
if( SortMode == EColumnSortMode::Ascending )
{
struct FCompareEventsByDuration
{
FORCEINLINE bool operator()( const TSharedPtr<FVisualizerEvent> A, const TSharedPtr<FVisualizerEvent> B ) const { return A->DurationMs < B->DurationMs; }
};
Events.Sort( FCompareEventsByDuration() );
}
else if( SortMode == EColumnSortMode::Descending )
{
struct FCompareEventsByDurationDescending
{
FORCEINLINE bool operator()( const TSharedPtr<FVisualizerEvent> A, const TSharedPtr<FVisualizerEvent> B ) const { return B->DurationMs < A->DurationMs; }
};
Events.Sort( FCompareEventsByDurationDescending() );
}
}
// Sort recursively
for( int32 Index = 0; Index < Events.Num(); Index++ )
{
if( Events[ Index ]->Children.Num() )
{
SortEventsList( Events[ Index ]->Children );
}
}
}
void SEventsTree::SortEventsList( void )
{
SortEventsList( SelectedEventsView );
EventsListView->RequestTreeRefresh();
RestoreEventSelection( SelectedEventsView );
}
bool SEventsTree::RestoreEventSelection( TArray< TSharedPtr< FVisualizerEvent > >& Events )
{
// Search for the selected event
for( int32 Index = 0; Index < Events.Num(); ++Index )
{
if( Events[ Index ]->IsSelected )
{
// Select it in the tree view widget
EventsListView->ClearSelection();
EventsListView->RequestTreeRefresh();
EventsListView->SetSelection( Events[ Index ] );
EventsListView->RequestScrollIntoView( Events[ Index ] );
return true;
}
// Search recursively
if( RestoreEventSelection( Events[ Index ]->Children ) )
{
return true;
}
}
return false;
}
void SEventsTree::HandleBarGraphSelectionChanged( TSharedPtr< FVisualizerEvent > Selection )
{
if ( Selection.IsValid() )
{
for( int32 EventIndex = 0; EventIndex < SelectedEvents.Num(); EventIndex++ )
{
TSharedPtr<FVisualizerEvent> Event = SelectedEvents[ EventIndex ];
if( Selection->EventName == Event->EventName )
{
HandleBarEventSelectionChanged( SelectedThread->Category, Event );
break;
}
}
}
}
void SEventsTree::HandleBarGraphExpansionChanged( TSharedPtr< FVisualizerEvent > Selection )
{
if ( Selection.IsValid() )
{
// We don't want to trigger selection changed event when the selection change is actually coming from the bar graph
bSuppressSelectionChangedEvent = true;
SelectedThread = Selection;
SelectedEvents = Selection.Get()->Children;
CreateSelectedEventsView();
SortEventsList();
bSuppressSelectionChangedEvent = false;
}
}
void SEventsTree::HandleBarEventSelectionChanged( int32 Thread, TSharedPtr<FVisualizerEvent> Selection )
{
const TSharedPtr< FVisualizerEvent >* MappedViewSelection = ViewToEventsMap.FindKey( Selection );
if( MappedViewSelection )
{
TSharedPtr< FVisualizerEvent > ViewSelection = *MappedViewSelection;
// Clear the current selection
EventsListView->ClearSelection();
EventsListView->RequestTreeRefresh();
// Expand all parents so that it's visible
for( TSharedPtr< FVisualizerEvent > ParentEvent = ViewSelection->ParentEvent; ParentEvent.IsValid(); ParentEvent = ParentEvent->ParentEvent )
{
EventsListView->SetItemExpansion( ParentEvent, true );
}
EventsListView->SetSelection( ViewSelection );
EventsListView->RequestScrollIntoView( ViewSelection );
}
else
{
EventsListView->ClearSelection();
}
}
FString SEventsTree::GetTabTitle() const
{
if ( SelectedThread.IsValid() )
{
return SelectedThread->EventName;
}
else
{
return NSLOCTEXT("TaskGraph", "EventsVisualizerName", "Empty Events List").ToString();
}
}
int32 SEventsTree::CountEvents( TArray< TSharedPtr< FVisualizerEvent > >& Events )
{
int32 Count = Events.Num();
for( int32 Index = 0; Index < Events.Num(); Index++ )
{
Count += CountEvents( Events[ Index ]->Children );
}
return Count;
}
void SEventsTree::CreateSelectedEventsView()
{
const int32 EventsCount = CountEvents( SelectedEvents );
ViewToEventsMap.Empty( EventsCount );
SelectedEventsView.Empty( SelectedEvents.Num() );
// Create the selected events copy based on the current view mode
if( ViewMode == EVisualizerViewMode::Hierarchical )
{
SelectedEventsView.Empty( SelectedEvents.Num() );
for( int32 Index = 0; Index < SelectedEvents.Num(); Index++ )
{
if( FilterEvent( SelectedEvents[ Index ] ) )
{
TSharedPtr< FVisualizerEvent > EventCopy( CreateSelectedEventsViewRecursively( SelectedEvents[ Index ] ) );
if( EventCopy.IsValid() )
{
SelectedEventsView.Add( EventCopy );
}
}
}
}
else if( ViewMode == EVisualizerViewMode::Flat )
{
SelectedEventsView.Empty( EventsCount );
for( int32 Index = 0; Index < SelectedEvents.Num(); Index++ )
{
CreateSelectedEventsViewRecursivelyAndFlatten( SelectedEvents[ Index ] );
}
}
else if( ViewMode == EVisualizerViewMode::Coalesced )
{
SelectedEventsView.Empty( SelectedEvents.Num() );
CreateSelectedEventsViewRecursivelyCoalesced( SelectedEvents, SelectedEventsView, TSharedPtr< FVisualizerEvent >() );
}
else if( ViewMode == EVisualizerViewMode::FlatCoalesced )
{
SelectedEventsView.Empty( EventsCount );
CreateSelectedEventsViewRecursivelyFlatCoalesced( SelectedEvents );
}
}
TSharedPtr< FVisualizerEvent > SEventsTree::CreateSelectedEventsViewRecursively( TSharedPtr< FVisualizerEvent > SourceEvent )
{
TSharedPtr< FVisualizerEvent > EventCopy( new FVisualizerEvent( *SourceEvent ) );
EventCopy->Children.Empty( SourceEvent->Children.Num() );
for( int32 ChildIndex = 0; ChildIndex < SourceEvent->Children.Num(); ChildIndex++ )
{
if( FilterEvent( SourceEvent->Children[ ChildIndex ] ) )
{
TSharedPtr< FVisualizerEvent > ChildCopy = CreateSelectedEventsViewRecursively( SourceEvent->Children[ ChildIndex ] );
if( ChildCopy.IsValid() )
{
ChildCopy->ParentEvent = EventCopy;
EventCopy->Children.Add( ChildCopy );
}
}
}
// Add this event because it's a leaf or has valid children
if( EventCopy->Children.Num() > 0 || SourceEvent->Children.Num() == 0 )
{
ViewToEventsMap.Add( EventCopy, SourceEvent );
}
else
{
EventCopy.Reset();
}
return EventCopy;
}
void SEventsTree::CreateSelectedEventsViewRecursivelyAndFlatten( TSharedPtr< FVisualizerEvent > SourceEvent )
{
// Collect only children and store them directly into SelectedEventsView
if ( FilterEvent( SourceEvent ) && SourceEvent->Children.Num() == 0 )
{
TSharedPtr< FVisualizerEvent > EventCopy( new FVisualizerEvent( *SourceEvent ) );
EventCopy->ParentEvent.Reset();
ViewToEventsMap.Add( EventCopy, SourceEvent );
SelectedEventsView.Add( EventCopy );
}
for( int32 ChildIndex = 0; ChildIndex < SourceEvent->Children.Num(); ChildIndex++ )
{
CreateSelectedEventsViewRecursivelyAndFlatten( SourceEvent->Children[ ChildIndex ] );
}
}
void SEventsTree::CreateSelectedEventsViewRecursivelyCoalesced( TArray< TSharedPtr< FVisualizerEvent > >& SourceEvents, TArray< TSharedPtr< FVisualizerEvent > >& CopiedEvents, TSharedPtr< FVisualizerEvent > InParent )
{
for( int32 SourceIndex = 0; SourceIndex < SourceEvents.Num(); SourceIndex++ )
{
TSharedPtr< FVisualizerEvent > SourceEvent = SourceEvents[ SourceIndex ];
if( FilterEvent( SourceEvent ) )
{
if( SourceEvent->Children.Num() == 0 )
{
// Check if a child with the same name has already been added to the copied event
bool bEventExists = false;
for( int32 CopiedEventIndex = 0; CopiedEventIndex < CopiedEvents.Num(); CopiedEventIndex++ )
{
if( CopiedEvents[ CopiedEventIndex ]->EventName == SourceEvent->EventName )
{
bEventExists = true;
break;
}
}
if( !bEventExists )
{
TSharedPtr< FVisualizerEvent > EventCopy( new FVisualizerEvent( *SourceEvent ) );
EventCopy->ParentEvent = InParent;
ViewToEventsMap.Add( EventCopy, SourceEvent );
CopiedEvents.Add( EventCopy );
// Find other children with the same name and add their time to the copied one
for( int32 OtherIndex = SourceIndex + 1; OtherIndex < SourceEvents.Num(); OtherIndex++ )
{
TSharedPtr< FVisualizerEvent > OtherEvent = SourceEvents[ OtherIndex ];
if( OtherEvent->Children.Num() == 0 && OtherEvent->EventName == SourceEvent->EventName )
{
EventCopy->DurationMs += OtherEvent->DurationMs;
}
}
}
}
else
{
TSharedPtr< FVisualizerEvent > EventCopy( new FVisualizerEvent( *SourceEvent ) );
EventCopy->Children.Empty( SourceEvent->Children.Num() );
EventCopy->ParentEvent = InParent;
CreateSelectedEventsViewRecursivelyCoalesced( SourceEvent->Children, EventCopy->Children, EventCopy );
// Only add this event if its children haven't been filtered
if( EventCopy->Children.Num() )
{
ViewToEventsMap.Add( EventCopy, SourceEvent );
CopiedEvents.Add( EventCopy );
}
}
}
}
}
void SEventsTree::CreateSelectedEventsViewRecursivelyFlatCoalesced( TArray< TSharedPtr< FVisualizerEvent > >& SourceEvents )
{
for( int32 SourceIndex = 0; SourceIndex < SourceEvents.Num(); SourceIndex++ )
{
TSharedPtr< FVisualizerEvent > SourceEvent = SourceEvents[ SourceIndex ];
if( FilterEvent( SourceEvent ) )
{
if( SourceEvent->Children.Num() == 0 )
{
// Check if a child with the same name has already been added to the copied event
bool bEventExists = false;
for( int32 CopiedEventIndex = 0; CopiedEventIndex < SelectedEventsView.Num(); CopiedEventIndex++ )
{
if( SelectedEventsView[ CopiedEventIndex ]->EventName == SourceEvent->EventName )
{
bEventExists = true;
break;
}
}
if( !bEventExists )
{
TSharedPtr< FVisualizerEvent > EventCopy( new FVisualizerEvent( *SourceEvent ) );
EventCopy->ParentEvent.Reset();
ViewToEventsMap.Add( EventCopy, SourceEvent );
SelectedEventsView.Add( EventCopy );
// Find other children with the same name and add their time to the copied one
for( int32 OtherIndex = SourceIndex + 1; OtherIndex < SourceEvents.Num(); OtherIndex++ )
{
TSharedPtr< FVisualizerEvent > OtherEvent = SourceEvents[ OtherIndex ];
if( OtherEvent->Children.Num() == 0 && OtherEvent->EventName == SourceEvent->EventName )
{
EventCopy->DurationMs += OtherEvent->DurationMs;
}
}
}
}
else
{
CreateSelectedEventsViewRecursivelyFlatCoalesced( SourceEvent->Children );
}
}
}
}
void SEventsTree::OnFilterTextChanged( const FText& InFilterText )
{
FilterText = InFilterText.ToString();
CreateSelectedEventsView();
EventsListView->RequestTreeRefresh();
}
void SEventsTree::OnFilterTextCommitted( const FText& InFilterText, ETextCommit::Type /*CommitInfo*/ )
{
}
#undef LOCTEXT_NAMESPACE