Files
UnrealEngineUWP/Engine/Source/Programs/MemoryProfiler2/HistogramParser.cs
Matt Kuhlenschmidt 4fa92bfa50 Copying //UE4/Dev-Editor to //UE4/Dev-Main (Source: //UE4/Dev-Editor @ 3152045)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================

Change 3106449 on 2016/08/30 by Michael.Dupuis

	#jira UETOOL-229 Added generic command icons used in Edit Menu (including contextual menu)

Change 3133997 on 2016/09/21 by Alex.Delesky

	#jira UE-34079 - FSceneView parameter for FBatchedElements::Draw is no longer an optional parameter.

Change 3134132 on 2016/09/21 by Jamie.Dale

	Added the "unattended" flag when running the localzation commandlets via UAT

Change 3134147 on 2016/09/21 by Frank.Fella

	Core - Add multitouch support to windows.

Change 3134349 on 2016/09/21 by Michael.Dupuis

	#jira UE-36151 Update the title bar to display the branch also

Change 3134355 on 2016/09/21 by Michael.Dupuis

	#jira UE-36041 When initially creating a projet and trying to add everything to source control, also add the uproject file

Change 3134447 on 2016/09/21 by Alexis.Matte

	#jira UE-36064
	The SpriteComponent is now properly reused when duplicating a light.

Change 3134451 on 2016/09/21 by Alexis.Matte

	#jira UE-22782
	Make sure when we re-import we dont try to match the mesh name if the option bCombineToSingle is true

Change 3134457 on 2016/09/21 by Jamie.Dale

	FInternationalization::Leetify now deals with escape sequences correctly.

	This also changes it to mark all leetified text with the start and end marker, and the unit tests have been updated accordingly.

Change 3134685 on 2016/09/21 by Matt.Kuhlenschmidt

	Cleaned up some of the UI for the new material slot workflow (part 1)

Change 3134743 on 2016/09/21 by Matt.Kuhlenschmidt

	Fix crash clicking OK to the import mesh dialog in persona when a path is not selected.  The OK button is now disabled until a valid path is selected

Change 3134760 on 2016/09/21 by Matt.Kuhlenschmidt

	Guard against cascade crash if cascade was shutdown but there is an old cascade particle system component in the undo buffer that attempts to refresh cascade

Change 3134837 on 2016/09/21 by Matt.Kuhlenschmidt

	Fix static analysis warnings in this file

Change 3134939 on 2016/09/21 by Nick.Darnell

	Automation - Moving the functional testing hooks for the editor into a plugin, the goal is to make it so you don't have to see all the extra stuff automation adds to the editor until the game project needs it.  Refactoring the way automation messages are serialized, no longer relying on a comma delimited string to serialize automation data.  Improving the filter for automation window so it lets you put in a path, and find it that way.  Fixing RunTests from the commandline so that it properly finds the tests, instead of jumping out of the loop as soon as it finds any one match.

Change 3134941 on 2016/09/21 by Nick.Darnell

	Automation - Functional tests now support warnings as errors on a per test basis.  Continued itteration on screenshot comparison.

Change 3135051 on 2016/09/21 by Matt.Kuhlenschmidt

	Fixed size of material slots in persona details panel

Change 3135076 on 2016/09/21 by Nick.Darnell

	Automation - Adding a missing file.

Change 3135584 on 2016/09/22 by Gareth.Martin

	Removed unused ULandscapeInfo::BeginDestroy
	Slight cleanup to FLandscapeEditDataInterface::DeleteLayer

Change 3135585 on 2016/09/22 by Gareth.Martin

	New Count algo
	Const'd Copy/Accumulate/Transform

Change 3135599 on 2016/09/22 by Gareth.Martin

	Resolve crash if a Landscape Layer Info object is force deleted while it is in use :(
	#jira UE-35709

Change 3135724 on 2016/09/22 by Michael.Dupuis

	#jira UE-32662 Remove old migration code that was causing this side effect

Change 3135726 on 2016/09/22 by Nick.Darnell

	Slate - Removing the SLATE_PRE_MULTIPLY macro.

Change 3135730 on 2016/09/22 by Nick.Darnell

	UMG - Exposing the 2D hit location that the WidgetInteractionComponent hit on the WidgetComponent.

Change 3135738 on 2016/09/22 by Matt.Kuhlenschmidt

	Ensure any handles to the backbuffer are released before the backbuffer is resized

	https://jira.it.epicgames.net/browse/UE-30488

Change 3135810 on 2016/09/22 by Ben.Marsh

	Build: Compile tools before running automated tests.

Change 3135993 on 2016/09/22 by Matt.Kuhlenschmidt

	Ensure you can unpause after toggling play/pause with a keyboard shortcut.  We were processing the keybinding on key down AND up which caused the unpause to instantly pause again
	https://jira.it.epicgames.net/browse/UE-36276

Change 3136257 on 2016/09/22 by Matt.Kuhlenschmidt

	Fixed assign of materials to components not working if you multi-select multiple components of a blueprint and assign the material.  The construction script was running before all the material had been set on all components.

Change 3136318 on 2016/09/22 by Alex.Delesky

	#jira UE-7405 - Forcing the mouse cursor to show and then clicking inside the viewport will no longer cause the mouse to lose focus

Change 3136494 on 2016/09/22 by Matt.Kuhlenschmidt

	Fix crash restarting a mission in Odin

Change 3136741 on 2016/09/22 by Cody.Albert

	Fixed SButton and SWidget to not multiply color and opacity, since that's already being done by SCompoundWidget

	#jira UE-36322

Change 3137711 on 2016/09/23 by Matt.Kuhlenschmidt

	Added guard against slate rendering with deleted materials.  In this will now be caught with a looged with the deleted material name.

Change 3137713 on 2016/09/23 by Matt.Kuhlenschmidt

	Removed the pooled draw elements stuff which is not used

Change 3137791 on 2016/09/23 by Nick.Darnell

	MediaPlayer - Removing .png from one of the style files, as that's not required.  Was causing warnings to be logged on load.

Change 3137793 on 2016/09/23 by Nick.Darnell

	Localization - Adjusting some log statements to say with instead of w/

Change 3137796 on 2016/09/23 by Nick.Darnell

	Slate - Adding missing and replacing corrupted style files in the editor.

Change 3137864 on 2016/09/23 by Matt.Kuhlenschmidt

	Fixed "actors are referenced are you sure you want to delete" dialog appearing when you are copying a lot of actors to another level

Change 3137876 on 2016/09/23 by Jamie.Dale

	Added allocation tagging to MProf2

	This hooks into the existing FScopeCycleCounterUObject used by the stats system to track object tags (object, package, and class) when an allocation is made. Tags should be in the format "Category:Tag", and the "Tag" part may include "/" to create levels in the tag hierarchy (as shown in the MProf2 tool).

	#jira UETOOL-950

Change 3137982 on 2016/09/23 by Gareth.Martin

	Added Invoke() support to CopyIf

Change 3137983 on 2016/09/23 by Gareth.Martin

	Added ULandscapeInfo::ForAllLandscapeProxies to clean up a lot of horrible code
	- Removed some dependencies on ALandscape and ALandscapeStreamingProxy in the process :)
	Also made FLandscapeEditorLayerSettings's constructor explicit to clean up some other horrible code

Change 3138053 on 2016/09/23 by Matt.Kuhlenschmidt

	Fixed Child Actor Template properties not visible after changing Child Actor Class

Change 3138079 on 2016/09/23 by Jamie.Dale

	Fixing some Clang warnings

Change 3138087 on 2016/09/23 by Jamie.Dale

	Added GetResourceSizeEx and GetResourceSizeBytes, and deprecated GetResourceSize

	GetResourceSizeEx populates a struct which reports not only how much memory is allocated, but also which arenas the memory was allocated from. GetResourceSizeBytes just wraps a call to GetResourceSizeEx and returns the total size from all arenas (this has the same behavior as the now deprecated GetResourceSize).

	Classes that used to override GetResourceSize should instead override GetResourceSizeEx and report their allocations as appropriate.

	#jira UETOOL-952

Change 3138127 on 2016/09/23 by Gareth.Martin

	Fixed crash when merging levels containing landscape
	#jira UE-36267

Change 3138821 on 2016/09/23 by Stephan.Jiang

	Fixes "Select all input node" doesn't work properly on output node.

	#jira UE-36335

Change 3138915 on 2016/09/23 by Stephan.Jiang

	Disable "select all linked nodes" for output nodes in material editor

Change 3139341 on 2016/09/25 by Nick.Darnell

	Automation - Moving the Blueprint Compiler Tests into the RuntimeTests plugin, and making the context client only since that's the only valid place to runt these tests.

Change 3139342 on 2016/09/25 by Nick.Darnell

	Landscape - Fixing some compiler errors on mac.

Change 3139345 on 2016/09/25 by Nick.Darnell

	Automation - Spelling and cleanup.

Change 3139346 on 2016/09/25 by Nick.Darnell

	Engine - Changing a check to an ensure, there's no reason to crash if this happens.

Change 3139347 on 2016/09/25 by Nick.Darnell

	Automation  - Making EFunctionalTestResult a BlueprintType

Change 3139348 on 2016/09/25 by Nick.Darnell

	Automation - Adding another test map.

Change 3139676 on 2016/09/26 by Michael.Dupuis

	#jira UE-32335 If we are a config object simply permit the transaction for undo/redo

Change 3139702 on 2016/09/26 by Nick.Darnell

	UMG - Making GetLocalHitLocation on UWidgetComponent virtual.

Change 3139760 on 2016/09/26 by Alexis.Matte

	Make sure we remove override materials from the list when the mesh point by the component has less materials.
	#jira UE-28845

Change 3139761 on 2016/09/26 by Alex.Delesky

	Added additional validation code to FPropertyNode to now properly validate TMap value and key nodes.

	#jira none

Change 3139843 on 2016/09/26 by Alex.Delesky

	#jira UE-36066 - Clearing all options from a ComboBox String when selecting an option will now also clear out the selected text correctly.

Change 3139880 on 2016/09/26 by Frank.Fella

	QAGame - Update multitouch test with less crashy assets?

Change 3139908 on 2016/09/26 by Matt.Kuhlenschmidt

	Fix selections having the potential to be out of sync after undo/redo

Change 3139928 on 2016/09/26 by Nick.Darnell

	Automation - tweaking the test maps some more.

Change 3140646 on 2016/09/26 by Matt.Kuhlenschmidt

	Fix false positive with the test for vaild materials being rendered by slate.

Change 3140912 on 2016/09/26 by Frank.Fella

	Core - Fix multitouch ifdef which was preventing it from actually being enabled.Also update test level blueprint so that it's actually testable.

Change 3141218 on 2016/09/27 by Matt.Kuhlenschmidt

	PR #2798: BP open anim interferes with mouse movement (Contributed by projectgheist)

Change 3141223 on 2016/09/27 by Jamie.Dale

	Updated UTextProperty::Identical to no longer compare display strings all the time

	It was supposed to compare the identity at runtime as the display string can change at runtime. This was preventing FText properties from being used in TSet/TMap as the hash needs to be consistent.

	#jira UE-36456

Change 3141242 on 2016/09/27 by Richard.TalbotWatkin

	Fixed various issues where making changes to components in the Blueprint Editor could cause a crash if there is an active component in the component visualizer.
	#jira UE-36402 - Editor crash when adding a spline component after having deleted another spline component
	Duplicated CL 3139370 from //UE4/Release-4.13
	Duplicated CL 3139878 from //UE4/Release-4.13

Change 3141323 on 2016/09/27 by Michael.Dupuis

	#jira UE-35081 Enable bDisplayEngineVersionInBadge by default

Change 3141798 on 2016/09/27 by tim.gautier

	Added UMG_DisplayWidget

Change 3143038 on 2016/09/28 by Jamie.Dale

	Added extra context to FTableRowBase::OnPostDataImport

	It now takes the owning data table and the row name as parameters. This allows is to do more useful fix-up that depends on the context of where it's used (such as stabilized text keys).

Change 3143039 on 2016/09/28 by Jamie.Dale

	Optimized UTextProperty::Identical to use a pointer comparison rather than read out the identity

	Only texts which have the same display string pointer can have the same identity, so this is a much faster check.

Change 3143098 on 2016/09/28 by Gareth.Martin

	Fixed crash when loading duplicated landscape levels
	#jira UE-34890

Change 3143300 on 2016/09/28 by Gareth.Martin

	Fixed crash when duplicating a level containing a landscape through the content browser
	#jira UE-34890

Change 3143389 on 2016/09/28 by Jamie.Dale

	LastResort is no longer staged in shipping builds

	You can now use the Content/SlateDebug folder to store any Slate resources that shouldn't be used in a shipping build (either for the Engine or for a game).

	This also removes the old bUsesSlateEditorStyle hack as everything should have migrated away from that now.

Change 3143565 on 2016/09/28 by Matt.Kuhlenschmidt

	Fixed this file

Change 3143717 on 2016/09/28 by Michael.Dupuis

	Fixed lowercase

Change 3143798 on 2016/09/28 by Matt.Kuhlenschmidt

	Fixed StreamingPauseRendering code to not attempt to tick the scene viewport on the slate loading thread while where are blocked on level streaming.  The viewport is rendered once and the render target is passed to slate instead of the entire viewport

Change 3143820 on 2016/09/28 by Alexis.Matte

	Use the PersonaToolikit to get the mesh

Change 3143833 on 2016/09/28 by Matt.Kuhlenschmidt

	Added guard for UE-36499

Change 3144144 on 2016/09/28 by Matt.Kuhlenschmidt

	Fix constructor init order

Change 3144821 on 2016/09/29 by Jamie.Dale

	Fixed feedback loop in FSlateEditableTextLayout::ComputeDesiredSize

	If the wrapping width is less than the scrollbar width, the scrollbar could constantly re-appear and then disappear.

Change 3144867 on 2016/09/29 by Matt.Kuhlenschmidt

	Added a commandlet to allow command line importing of any asset type the engine supports.
	- Intermediate checkin

Change 3144875 on 2016/09/29 by Nick.Darnell

	Automation - Adding CornellBox example map, fixing some additional tests, removing the Movement Test.

Change 3144975 on 2016/09/29 by Matt.Kuhlenschmidt

	Disable auto-applying of scalability settings
	The user will still be asked if the settings should be applied but if they do nothing the notification will just go away without setting stuff.

Change 3145274 on 2016/09/29 by Jamie.Dale

	New asset menu no longer has a scrollbar on most displays

Change 3146004 on 2016/09/29 by Matt.Barnes

	Adding two FBX test files to help facilitate QA coverage on the new material/section workflow.

Change 3146377 on 2016/09/30 by Gareth.Martin

	Fixed landscape rendering errors after using the "change component size" tool
	- also affected initial import of a landscape+weightmaps
	#jira UE-34518

Change 3146455 on 2016/09/30 by Jamie.Dale

	Fixing more menus that had scrollbars due to only being able to use half the vertical resolution

Change 3146466 on 2016/09/30 by Gareth.Martin

	Fixed not being able to erase foliage attached to BSP
	#jira UE-36297

Change 3146471 on 2016/09/30 by Jamie.Dale

	Can no longer localize sequences via the Content Browser

Change 3146569 on 2016/09/30 by Jamie.Dale

	Fixed UGatherTextFromSourceCommandlet::ParseSourceText being able to underflow while parsing

Change 3147116 on 2016/09/30 by Michael.Dupuis

	#jira UE-33068 Update selection once after the bulk operation so the AssetContextMenu will have a proper selection, but only perform this if we're not in UserSearchingMode (which mean AssetPicker)

Change 3148091 on 2016/10/01 by Matt.Barnes

	Adding a map and relevant assets to facilitate testing around the new material blueprint nodes - GetMaterialSlotNames, GetMaterialIndex, and SetMaterialByName, respectively

Change 3148714 on 2016/10/03 by Nick.Darnell

	PR #2770: [Git plugin] Fix bug where history and merging do not work if the user has format.pretty settings in their gitconfig (Contributed by SRombauts)

	#jira UE-35568

Change 3148793 on 2016/10/03 by Nick.Darnell

	Automation - TPS for SM_Cornellbox

Change 3148801 on 2016/10/03 by Nick.Darnell

	PR #2820: [WidgetBlueprintLibrary] Throwing Essential-Functionality-Understanding PIE Errors when Player Controller ptr not supplied (Contributed by EverNewJoy)

	#jira UE-36711

Change 3148805 on 2016/10/03 by Nick.Darnell

	PR #2822: Add missing base includes and forward declarations for UProgressBar and UTextBlock (Contributed by error454)

	#jira UE-36715

Change 3148813 on 2016/10/03 by Nick.Darnell

	UMG - The retainer now contains the SVirtualWindow directly in the hierarchy.  This should now make it possible to reliably focus elements inside the retainer widget.

Change 3148855 on 2016/10/03 by Gareth.Martin

	Fixed performance regression when importing landscape heightmaps
	#jira UE-36659

Change 3149482 on 2016/10/03 by Cody.Albert

	Added link to Support landing page to Help menu

	#jira UE-36603

Change 3149520 on 2016/10/03 by tim.gautier

	Edited UMG_Behavior - Collapsed now has a toggleable state to demonstrate functionality.

Change 3149945 on 2016/10/04 by Gareth.Martin

	Fixed invisible landscape components when using tessellation on landscape material
	#jira UE-35494

Change 3149951 on 2016/10/04 by Gareth.Martin

	Reduced material update log spam when creating and editing landscapes
	- Some will remain, landscape fundementally manipulates a lot of material instances
	#jira UE-34440

Change 3150143 on 2016/10/04 by Matt.Kuhlenschmidt

	Fix not crashing when trying to clear objects which have a specific class filter in the property settings
	https://jira.it.epicgames.net/browse/UE-36692

Change 3150614 on 2016/10/04 by Nick.Darnell

	Git - Disabling some logging in non-debug builds of the git source control plugin.

Change 3151647 on 2016/10/05 by Matt.Kuhlenschmidt

	Fix loc warnings in these files (duplicate loc keys)

Change 3151679 on 2016/10/05 by Nick.Darnell

	Editor - Fixing the build, removing the VREditor module from the dynamically loaded list.

Change 3151722 on 2016/10/05 by Gareth.Martin

	Fix breakage to LandscapeEdModeSplineTools.cpp caused by Dev-VREditor from main integration

Change 3151816 on 2016/10/05 by Gareth.Martin

	Fixed more breakage to Landscape caused by Dev-VREditor from main integration

[CL 3152072 by Matt Kuhlenschmidt in Main branch]
2016-10-05 13:23:01 -04:00

763 lines
25 KiB
C#

/**
* Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace MemoryProfiler2
{
/// <summary> Histogram parser. </summary>
public static class FHistogramParser
{
/// <summary>
/// The assumption that this constant is 2 is still hardcoded
/// in some places, so increasing the number of banks is not
/// as simple as changing this constant.
///
/// Second memory bank is used only on PS3 to show local memory.
/// </summary>
public const int NUM_MEMORY_BANKS = 2;
/// <summary> Array of histogram bars. </summary>
static public List<FHistogramBar>[] HistogramBars;
/// <summary> Array of histogram bars for selected main histogram bar. </summary>
static private List<FHistogramBar> HistogramSelectionBars = new List<FHistogramBar>();
/// <summary> Currently selected histogram bar from the memory bank. </summary>
static private FHistogramBar SelectedHistogramBar;
/// <summary> Currently selected histogram bar from the detailed bank. </summary>
static private FHistogramBar SubselectedHistogramBar;
/// <summary> Index of the bank for the currently selected histogram bar. </summary>
static private int SelectedMemoryBankIndex = 0;
/// <summary> Indices of the currently selected histogram bars in the memory banks. </summary>
static private int[] SelectedHistogramBarIndex = new int[ 2 ] { 0, 0 };
static private Pen BlackDashedPen = new Pen( Color.Black );
static private Pen RedDashedPen = new Pen( Color.Red );
private static Brush CheckerBWBrush1x1 = new HatchBrush( HatchStyle.Percent50, Color.FromArgb( 224, Color.Plum ), Color.FromArgb( 224, Color.SkyBlue ) );
private static Brush CheckerBWBrush2x2 = new HatchBrush( HatchStyle.SmallCheckerBoard, Color.FromArgb( 192, Color.Plum ), Color.FromArgb( 192, Color.SkyBlue ) );
private static Brush CheckerBWBrush4x4 = new HatchBrush( HatchStyle.LargeCheckerBoard, Color.FromArgb( 160, Color.Plum ), Color.FromArgb( 160, Color.SkyBlue ) );
private static Pen OutlinePen1 = new Pen( Color.FromArgb( 128, Color.White ) );
private static Pen OutlinePen2 = new Pen( Color.FromArgb( 192, Color.Black ) );
/// <summary> Pen with 1x1 checker used to draw selected histogram bar. </summary>
private static Pen CheckerPen1x1 = new Pen( CheckerBWBrush1x1 );
/// <summary> Pen with 2x2 checker used to draw selected histogram bar. </summary>
private static Pen CheckerPen2x2 = new Pen( CheckerBWBrush2x2 );
/// <summary> Pen with 4x4 checker used to draw selected histogram bar. </summary>
private static Pen CheckerPen4x4 = new Pen( CheckerBWBrush4x4 );
private static Pen SelectedSolidPen = new Pen( new SolidBrush( Color.LightSteelBlue ) );
/// <summary> Pen used to draw the selected histogram bar. Size of the checker is based on the selection height. </summary>
private static Pen SelectedBarPen( FHistogramBar HistogramBar )
{
int SelectionHeight = ( int )HistogramBar.Rect.Height;
if( SelectionHeight < 8 )
{
return CheckerPen1x1;
}
else if( SelectionHeight < 16 )
{
return CheckerPen2x2;
}
return CheckerPen4x4;
}
/// <summary> Reference to the main memory profiler window. </summary>
private static MainWindow OwnerWindow;
public static void SetProfilerWindow( MainWindow InMainWindow )
{
BlackDashedPen.DashStyle = DashStyle.Dash;
RedDashedPen.DashStyle = DashStyle.Dash;
OwnerWindow = InMainWindow;
}
public static void ParseSnapshot( List<FCallStackAllocationInfo> CallStackList, string FilterText )
{
// Progress bar
long ProgressInterval = CallStackList.Count / 20;
long NextProgressUpdate = ProgressInterval;
int CallStackCurrent = 0;
OwnerWindow.ToolStripProgressBar.Value = 0;
OwnerWindow.ToolStripProgressBar.Visible = true;
OwnerWindow.UpdateStatus( "Updating histogram view for " + OwnerWindow.CurrentFilename );
List<ClassGroup> CallStackGroups = OwnerWindow.Options.ClassGroups;
List<FHistogramBar>[] Bars = new List<FHistogramBar>[ NUM_MEMORY_BANKS ];
for( int BankIndex = 0; BankIndex < Bars.Length; BankIndex++ )
{
Bars[ BankIndex ] = new List<FHistogramBar>();
// The first bar in each column is for callstacks unmatched by any pattern.
Bars[ BankIndex ].Add( new FHistogramBar( "Other", Color.White ) );
// Add all groups to all memory bank columns.
foreach( ClassGroup CallStackGroup in CallStackGroups )
{
var Bar = new FHistogramBar( CallStackGroup );
Bar.BeginBatchAddition();
Bars[ BankIndex ].Add( Bar );
}
}
using( FScopedLogTimer ParseTiming = new FScopedLogTimer( "HistogramParser.ParseSnapshot" ) )
{
long Size = 0;
int Count = 0;
bool bFilterIn = OwnerWindow.IsFilteringIn();
var FilteredCallstackList = new List<FCallStackAllocationInfo>(CallStackList.Count);
foreach (var AllocationInfo in CallStackList)
{
var FilteredAllocationInfo = AllocationInfo.GetAllocationInfoForTags(OwnerWindow.GetTagsFilter(), bFilterIn);
if (FilteredAllocationInfo.TotalCount != 0)
{
FilteredCallstackList.Add(FilteredAllocationInfo);
}
}
foreach ( FCallStackAllocationInfo AllocationInfo in FilteredCallstackList )
{
// Update progress bar.
if ( CallStackCurrent >= NextProgressUpdate )
{
OwnerWindow.ToolStripProgressBar.PerformStep();
NextProgressUpdate += ProgressInterval;
Debug.WriteLine( "FHistogramParser.ParseSnapshot " + OwnerWindow.ToolStripProgressBar.Value + "/20" );
}
CallStackCurrent++;
FCallStack OriginalCallStack = FStreamInfo.GlobalInstance.CallStackArray[AllocationInfo.CallStackIndex ];
if( OriginalCallStack.RunFilters( FilterText, CallStackGroups, bFilterIn, OwnerWindow.SelectedMemoryPool ) )
{
bool bFound = false;
int Column = FMemoryPoolInfo.GetMemoryPoolHistogramColumn( OriginalCallStack.MemoryPool );
if( Column == -1 )
{
// If the callstack is in multiple pools, just put it in the first bank.
// The user has already been warned about multi-pool callstacks.
Column = 0;
}
for( int GroupIndex = 0; GroupIndex < CallStackGroups.Count; GroupIndex++ )
{
foreach( CallStackPattern CallStackPatternIt in CallStackGroups[ GroupIndex ].CallStackPatterns )
{
if (CallStackPatternIt.ContainsCallStack(FStreamInfo.GlobalInstance.CallStackArray[AllocationInfo.CallStackIndex]))
{
Bars[Column][GroupIndex + 1].AddAllocation(AllocationInfo);
bFound = true;
goto HackyBreakAll;
}
}
}
HackyBreakAll:
if( !bFound )
{
// No pattern matched this callstack, so add it to the Other bar
Bars[ Column ][ 0 ].AddAllocation( AllocationInfo );
}
}
Size += AllocationInfo.TotalSize;
Count += AllocationInfo.TotalCount;
}
}
// End the update batch and allow things to sort
for( int BankIndex = 0; BankIndex < Bars.Length; BankIndex++ )
{
foreach( ClassGroup CallStackGroup in CallStackGroups )
{
foreach (var Bar in Bars[ BankIndex ])
{
Bar.EndBatchAddition();
}
}
}
OwnerWindow.ToolStripProgressBar.Visible = false;
HistogramBars = Bars;
// Select first valid histogram bar.
SelectFirstValidHistogramBar();
}
/// <summary> Selects first valid histogram bar, searches through all memory banks. </summary>
private static void SelectFirstValidHistogramBar()
{
SelectedMemoryBankIndex = 0;
SelectedHistogramBarIndex[ 0 ] = 0;
SelectedHistogramBarIndex[ 1 ] = 0;
SubselectedHistogramBar = null;
for( int MemoryBankIndex = 0; MemoryBankIndex < HistogramBars.Length; MemoryBankIndex++ )
{
for( int BarIndex = 0; BarIndex < HistogramBars[ MemoryBankIndex ].Count; BarIndex++ )
{
FHistogramBar Bar = FHistogramParser.HistogramBars[ MemoryBankIndex ][ BarIndex ];
if( Bar.AllocationCount > 0 )
{
SelectedMemoryBankIndex = MemoryBankIndex;
SelectedHistogramBarIndex[ SelectedMemoryBankIndex ] = BarIndex;
SelectHistogramBar( Bar );
return;
}
}
}
SelectedHistogramBar = null;
}
public static void ClearView()
{
if( HistogramBars != null )
{
HistogramBars[ 0 ].Clear();
HistogramBars[ 1 ].Clear();
}
HistogramSelectionBars.Clear();
SelectedMemoryBankIndex = 0;
SelectedHistogramBarIndex[ 0 ] = 0;
SelectedHistogramBarIndex[ 1 ] = 0;
SelectedHistogramBar = null;
SubselectedHistogramBar = null;
OwnerWindow.HistogramViewCallStackListView.BeginUpdate();
OwnerWindow.HistogramViewCallStackListView.Items.Clear();
OwnerWindow.HistogramViewCallStackListView.SelectedItems.Clear();
OwnerWindow.HistogramViewCallStackListView.EndUpdate();
OwnerWindow.HistogramViewNameLabel.Text = "";
OwnerWindow.HistogramViewSizeLabel.Text = "";
OwnerWindow.HistogramViewAllocationsLabel.Text = "";
OwnerWindow.MemoryBitmapAllocatedMemoryLabel.Text = "";
}
public static void PaintPanel( PaintEventArgs e )
{
int[] MemorySizes = new int[]
{
FStreamInfo.GetMemoryBankSize( 0 ),
FStreamInfo.GetMemoryBankSize( 1 )
};
string[] MemoryCaptions = new string[]
{
"MB (Local)",
"MB (Video)"
};
const int MinorTick = 2;
const int MajorTick = 10;
const int TickRight = 70;
const int GraphYBorder = 30;
const int BarLeft = TickRight + 10;
int NumColumns = 3;
int TotalBordersSize = NumColumns * BarLeft;
int GraphWidth = Math.Min( ( OwnerWindow.HistogramPanel.Width - TotalBordersSize ) / 3, 150 );
float BarWidth = GraphWidth * 0.6f;
float GraphXGap = GraphWidth * 0.4f;
int MaxMemorySize = 0;
for( int BankIndex = 0; BankIndex < NUM_MEMORY_BANKS; BankIndex++ )
{
MaxMemorySize = Math.Max( MemorySizes[ BankIndex ], MaxMemorySize );
}
float TotalGraphHeight = OwnerWindow.HistogramPanel.Height - GraphYBorder * 2;
if( HistogramBars != null )
{
for( int MemoryBankIndex = 0; MemoryBankIndex < MemorySizes.Length; MemoryBankIndex++ )
{
float GraphTop = GraphYBorder;
float GraphLeft = MemoryBankIndex * ( BarLeft + BarWidth + GraphXGap );
float YScale = TotalGraphHeight / MemorySizes[ MemoryBankIndex ];
// Draw vertical axes.
OwnerWindow.DrawYAxis( e.Graphics, Pens.Black, Color.Black, MajorTick, MinorTick, GraphLeft + TickRight, GraphTop, TotalGraphHeight, MemoryCaptions[ MemoryBankIndex ], MemorySizes[ MemoryBankIndex ] );
float BarY = GraphTop + YScale * MemorySizes[ MemoryBankIndex ];
for( int BarIndex = HistogramBars[ MemoryBankIndex ].Count - 1; BarIndex >= 0; BarIndex-- )
{
FHistogramBar Bar = HistogramBars[ MemoryBankIndex ][ BarIndex ];
if( Bar.AllocationCount == 0 )
{
continue;
}
float BarHeight = ( float )Bar.MemorySize / ( 1024 * 1024 ) * YScale;
Bar.Rect.X = GraphLeft + BarLeft;
Bar.Rect.Y = BarY - BarHeight;
Bar.Rect.Width = BarWidth;
Bar.Rect.Height = BarHeight;
e.Graphics.FillRectangle( new SolidBrush( Bar.Colour ), Bar.Rect.X, Bar.Rect.Y, Bar.Rect.Width, Bar.Rect.Height );
BarY -= BarHeight;
}
}
if( SelectedHistogramBar != null )
{
e.Graphics.FillRectangle
(
SelectedBarPen( SelectedHistogramBar ).Brush,
SelectedHistogramBar.Rect.X,
SelectedHistogramBar.Rect.Y,
SelectedHistogramBar.Rect.Width,
Math.Max( SelectedHistogramBar.Rect.Height, 1.0f )
);
float MarkerHeight = Math.Max( SelectedHistogramBar.Rect.Height, 1.0f );
float MarkerPosX = SelectedHistogramBar.Rect.Left + SelectedHistogramBar.Rect.Width + 1.0f;
float MarkerPosY = ( float )Math.Ceiling( ( double )SelectedHistogramBar.Rect.Top ) - 1;
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 0, MarkerPosY, MarkerPosX + 5, MarkerPosY );
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 5, MarkerPosY, MarkerPosX + 5, MarkerPosY + MarkerHeight );
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 0, MarkerPosY + MarkerHeight + 1, MarkerPosX + 5, MarkerPosY + MarkerHeight + 1 );
}
TextRenderer.DrawText(
e.Graphics,
"Use key up or key down to change selected allocation",
OwnerWindow.AxisFont,
new Point((int)(BarLeft * 0.5f), (int)(OwnerWindow.HistogramPanel.Height - (GraphYBorder + OwnerWindow.AxisFont.Height) * 0.5f)),
Color.Black
);
}
/*
// Draw "Total Memory Used" line.
if( OwnerWindow.CurrentSnapshot != null && OwnerWindow.CurrentSnapshot.MetricArray.Count > 0 )
{
float YScale = TotalGraphHeight / MemorySizes[ 0 ];
float GraphBottom = GraphYBorder + YScale * MemorySizes[ 0 ];
float TotalUsedLineY = GraphBottom - YScale * ( OwnerWindow.CurrentSnapshot.MemoryAllocationStats.TotalAllocated / 1024f / 1024f );
float OverheadLineY = TotalUsedLineY + YScale * ( OwnerWindow.CurrentSnapshot.MetricArray[ ( int )ESnapshotMetricV3.MemoryProfilingOverhead ] / 1024f / 1024f );
e.Graphics.DrawLine( BlackDashedPen, TickRight, TotalUsedLineY, BarLeft + BarWidth, TotalUsedLineY );
e.Graphics.DrawLine( RedDashedPen, TickRight, OverheadLineY, BarLeft + BarWidth, OverheadLineY );
}
*/
if( SelectedHistogramBar != null && SelectedHistogramBar.MemorySize > 0 )
{
float GraphLeft = MemorySizes.Length * ( BarLeft + BarWidth + GraphXGap );
float MemorySizeMB = ( float )( ( double )SelectedHistogramBar.MemorySize / ( 1024 * 1024 ) );
float SelectedYScale = TotalGraphHeight / MemorySizeMB;
string AxisLabel = "MB";
int AxisMemorySize = ( int )MemorySizeMB;
if( AxisMemorySize < 32 )
{
// Drop down into kilobytes.
AxisMemorySize = ( int )( SelectedHistogramBar.MemorySize / 1024 );
AxisLabel = "KB";
}
if( AxisMemorySize < 32 )
{
// Drop down into bytes.
AxisMemorySize = ( int )Math.Max( SelectedHistogramBar.MemorySize, 32 );
AxisLabel = "bytes";
}
// Select a major tick that's divisible by 4 so that the minor tick divides into it without remainder.
int SelectedMajorTick = ( AxisMemorySize / 8 ) / 4 * 4;
int SelectedMinorTick = SelectedMajorTick / 4;
OwnerWindow.DrawYAxis( e.Graphics, Pens.Black, Color.Black, SelectedMajorTick, SelectedMinorTick, GraphLeft + TickRight, GraphYBorder, TotalGraphHeight, AxisLabel, AxisMemorySize );
{
// Used to batch up drawing as individual calls are slow
var FillRects = new Dictionary<Color, List<RectangleF>>();
var DrawRects = new List<RectangleF>();
float BarY = GraphYBorder + SelectedYScale * MemorySizeMB;
for (int SelBarIndex = HistogramSelectionBars.Count - 1; SelBarIndex >= 0; SelBarIndex--)
{
FHistogramBar Bar = HistogramSelectionBars[SelBarIndex];
float BarHeight = (float)((double)Bar.MemorySize / (1024 * 1024) * SelectedYScale);
Bar.Rect.X = GraphLeft + BarLeft;
Bar.Rect.Y = BarY - BarHeight;
Bar.Rect.Width = BarWidth;
Bar.Rect.Height = BarHeight;
List<RectangleF> FillRectsList;
if (FillRects.TryGetValue(Bar.Colour, out FillRectsList))
{
FillRectsList.Add(new RectangleF(Bar.Rect.X, Bar.Rect.Y, Bar.Rect.Width, Bar.Rect.Height));
}
else
{
FillRectsList = new List<RectangleF>() { new RectangleF(Bar.Rect.X, Bar.Rect.Y, Bar.Rect.Width, Bar.Rect.Height) };
FillRects.Add(Bar.Colour, FillRectsList);
}
DrawRects.Add(new RectangleF(Bar.Rect.X, Bar.Rect.Y, Bar.Rect.Width - 1, Bar.Rect.Height));
BarY -= BarHeight;
}
// Draw batched
foreach (var FillRectPair in FillRects)
{
e.Graphics.FillRectangles(new SolidBrush(FillRectPair.Key), FillRectPair.Value.ToArray());
}
e.Graphics.DrawRectangles(Pens.Black, DrawRects.ToArray());
}
if( SubselectedHistogramBar != null )
{
e.Graphics.FillRectangle
(
SelectedBarPen( SubselectedHistogramBar ).Brush,
SubselectedHistogramBar.Rect.X,
SubselectedHistogramBar.Rect.Y,
SubselectedHistogramBar.Rect.Width,
Math.Max( SubselectedHistogramBar.Rect.Height, 1.0f )
);
float MarkerHeight = Math.Max( SubselectedHistogramBar.Rect.Height, 1.0f );
float MarkerPosX = SubselectedHistogramBar.Rect.Left + SubselectedHistogramBar.Rect.Width + 1.0f;
float MarkerPosY = ( float )Math.Ceiling( ( double )SubselectedHistogramBar.Rect.Top ) - 1;
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 0, MarkerPosY, MarkerPosX + 5, MarkerPosY );
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 5, MarkerPosY, MarkerPosX + 5, MarkerPosY + MarkerHeight );
e.Graphics.DrawLine( Pens.Black, MarkerPosX + 0, MarkerPosY + MarkerHeight + 1, MarkerPosX + 5, MarkerPosY + MarkerHeight + 1 );;
}
}
}
static public void UnsafeMouseClick( object sender, MouseEventArgs e )
{
// Work out which bar, if any, the user clicked on.
for( int MemoryBankIndex = 0; MemoryBankIndex < HistogramBars.Length; MemoryBankIndex++ )
{
for( int BarIndex = 0; BarIndex < HistogramBars[ MemoryBankIndex ].Count; BarIndex++ )
{
FHistogramBar Bar = FHistogramParser.HistogramBars[ MemoryBankIndex ][ BarIndex ];
if( Bar.Rect.Contains( e.X, e.Y ) )
{
SelectedMemoryBankIndex = MemoryBankIndex;
SelectedHistogramBarIndex[ SelectedMemoryBankIndex ] = BarIndex;
SelectHistogramBar( Bar );
if( e.Button == MouseButtons.Right )
{
OwnerWindow.ViewHistoryContextMenu.Tag = Bar;
OwnerWindow.ViewHistoryContextMenu.Show( ( Control )sender, e.Location );
}
return;
}
}
}
// Check selection bars (the graph that appears when you select a bar in another graph).
if( SelectedHistogramBar != null )
{
for( int DetailedBarIndex = 0; DetailedBarIndex < HistogramSelectionBars.Count; DetailedBarIndex++ )
{
FHistogramBar HistogramBar = HistogramSelectionBars[ DetailedBarIndex ];
if( HistogramBar.Rect.Contains( e.X, e.Y ) )
{
SubselectHistogramBar( HistogramBar );
if( e.Button == MouseButtons.Right )
{
OwnerWindow.ViewHistoryContextMenu.Tag = HistogramBar;
OwnerWindow.ViewHistoryContextMenu.Show( ( Control )sender, e.Location );
}
return;
}
}
}
SubselectHistogramBar(null);
}
static public bool ProcessKeys( Keys KeyData )
{
switch( KeyData )
{
case Keys.Up:
{
if( SubselectedHistogramBar != null )
{
int Index = HistogramSelectionBars.IndexOf( SubselectedHistogramBar );
if( Index > 0 )
{
SubselectHistogramBar( HistogramSelectionBars[ Index - 1 ] );
}
}
else if( SelectedHistogramBar != null )
{
for( int BarIndex = 0; BarIndex < HistogramBars.Length; BarIndex++ )
{
List<FHistogramBar> HistogramBarArray = HistogramBars[ BarIndex ];
int Index = HistogramBarArray.IndexOf( SelectedHistogramBar );
if( Index > 0 )
{
for( ; Index > 0; Index -- )
{
if( HistogramBarArray[ Index - 1 ].AllocationCount > 0 )
{
SelectedHistogramBarIndex[ SelectedMemoryBankIndex ] = Index - 1;
SelectHistogramBar( HistogramBarArray[ Index - 1 ] );
break;
}
}
break;
}
}
}
return true;
}
case Keys.Down:
{
if( SubselectedHistogramBar != null )
{
int Index = HistogramSelectionBars.IndexOf( SubselectedHistogramBar );
if( Index != -1 && Index < HistogramSelectionBars.Count - 1 )
{
SubselectHistogramBar( HistogramSelectionBars[ Index + 1 ] );
}
}
else if( SelectedHistogramBar != null )
{
for( int BarIndex = 0; BarIndex < HistogramBars.Length; BarIndex++ )
{
List<FHistogramBar> HistogramBarArray = HistogramBars[ BarIndex ];
int Index = HistogramBarArray.IndexOf( SelectedHistogramBar );
if( Index != -1 && Index < HistogramBarArray.Count - 1 )
{
for( ; Index < HistogramBarArray.Count - 2; Index++ )
{
if( HistogramBarArray[ Index + 1 ].AllocationCount > 0 )
{
SelectedHistogramBarIndex[ SelectedMemoryBankIndex ] = Index + 1;
SelectHistogramBar( HistogramBarArray[ Index + 1 ] );
break;
}
}
break;
}
}
}
return true;
}
}
// Not processed
return false;
}
public static void SelectHistogramBar( FHistogramBar Bar )
{
if( Bar != SelectedHistogramBar )
{
// Cancel any subselection if the main selection is changing.
SubselectedHistogramBar = null;
}
SelectedHistogramBar = Bar;
if( SelectedHistogramBar != null )
{
HistogramSelectionBars.Clear();
foreach( FCallStackAllocationInfo AllocationInfo in SelectedHistogramBar.CallStackList )
{
int Address = FStreamInfo.GlobalInstance.CallStackArray[ AllocationInfo.CallStackIndex ].AddressIndices[ 0 ];
string FunctionName = FStreamInfo.GlobalInstance.NameArray[ FStreamInfo.GlobalInstance.CallStackAddressArray[ Address ].FunctionIndex ];
FHistogramBar AllocBar = new FHistogramBar( FunctionName, SelectedHistogramBar.Colour );
AllocBar.AddAllocation( AllocationInfo );
HistogramSelectionBars.Add( AllocBar );
}
}
UpdateHistogramDetails();
OwnerWindow.HistogramPanel.Invalidate();
}
public static void SubselectHistogramBar( FHistogramBar HistogramBar )
{
SubselectedHistogramBar = HistogramBar;
UpdateHistogramDetails();
OwnerWindow.HistogramPanel.Invalidate();
}
private static void UpdateHistogramDetails()
{
OwnerWindow.HistogramViewCallStackListView.BeginUpdate();
OwnerWindow.HistogramViewCallStackListView.Items.Clear();
FHistogramBar Bar = null;
if( SubselectedHistogramBar != null )
{
Bar = SubselectedHistogramBar;
}
else if( SelectedHistogramBar != null )
{
Bar = SelectedHistogramBar;
}
if( Bar != null )
{
if( Bar != SubselectedHistogramBar )
{
OwnerWindow.HistogramViewNameLabel.Text = Bar.Description;
}
OwnerWindow.HistogramViewSizeLabel.Text = MainWindow.FormatSizeString2( Bar.MemorySize );
OwnerWindow.HistogramViewAllocationsLabel.Text = Bar.AllocationCount.ToString("N0");
if( Bar.CallStackList.Count == 1 )
{
foreach( int AddressIndex in FStreamInfo.GlobalInstance.CallStackArray[ Bar.CallStackList[ 0 ].CallStackIndex ].AddressIndices )
{
string FunctionName = FStreamInfo.GlobalInstance.NameArray[ FStreamInfo.GlobalInstance.CallStackAddressArray[ AddressIndex ].FunctionIndex ];
OwnerWindow.HistogramViewCallStackListView.Items.Add( FunctionName );
}
}
}
OwnerWindow.HistogramViewCallStackListView.EndUpdate();
}
}
/// <summary> Encapsulates histogram bar information. </summary>
public class FHistogramBar
{
/// <summary> List of callstack allocations, sorted by size. </summary>
public List<FCallStackAllocationInfo> CallStackList = new List<FCallStackAllocationInfo>();
/// <summary> Memory allocated in this bar. </summary>
public long MemorySize;
/// <summary> Number of allocation in this bar. </summary>
public int AllocationCount;
/// <summary> The class group that this bar is associated with. </summary>
public ClassGroup CallStackGroup;
/// <summary> Description of this bar, usually taken from the callstack group. </summary>
public string Description;
/// <summary> The colour used to draw this bar, usually taken from the callstack group. </summary>
public Color Colour;
/// <summary> Rectangle used to draw this bar. </summary>
public RectangleF Rect;
/// <summary> > 0 if we are batch adding. See BeginBatchAddition and EndBatchAddition. </summary>
int BatchAddingCount = 0;
/// <summary> Default constructor. </summary>
public FHistogramBar( ClassGroup InCallStackGroup )
{
CallStackGroup = InCallStackGroup;
Description = InCallStackGroup.Name;
Colour = InCallStackGroup.Color;
}
/// <summary> Custom constructor. </summary>
public FHistogramBar( string InDescription, Color InColour )
{
Description = InDescription;
Colour = InColour;
}
/// <summary> Begin the process of adding a batch of new entries to this bar. Calls to AddAllocation will defer the Sort until EndBatchAddition is called. </summary>
public void BeginBatchAddition()
{
++BatchAddingCount;
}
/// <summary> End the process of adding a batch of new entries to this bar. Calls Sort to ensure new entries are in the correct order. </summary>
public void EndBatchAddition()
{
if (--BatchAddingCount < 0)
{
BatchAddingCount = 0;
}
if (BatchAddingCount == 0)
{
// Sorting largest -> smallest
CallStackList.Sort((First, Second) => Math.Sign(First.TotalSize - Second.TotalSize));
}
}
/// <summary> Inserts the new allocation so that the list stays in size order. </summary>
public void AddAllocation( FCallStackAllocationInfo AllocationInfo )
{
bool bInserted = false;
if (BatchAddingCount == 0)
{
for (int Index = 0; Index < CallStackList.Count; Index++)
{
if (CallStackList[Index].TotalSize > AllocationInfo.TotalSize)
{
CallStackList.Insert(Index, AllocationInfo);
bInserted = true;
break;
}
}
}
if (!bInserted)
{
CallStackList.Add(AllocationInfo);
}
MemorySize += AllocationInfo.TotalSize;
AllocationCount += AllocationInfo.TotalCount;
}
}
}