Ejemplo n.º 1
0
        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();
        }
		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;

				foreach( FCallStackAllocationInfo AllocationInfo in CallStackList )
				{
					// 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, OwnerWindow.IsFilteringIn(), 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.Size;
					Count += AllocationInfo.Count;
				}
			}

			// 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();
		}