Example #1
0
 public FMemoryPoolInfoCollection()
 {
     for (int i = 0; i < MemoryPoolInfos.Length; i++)
     {
         MemoryPoolInfos[i] = new FMemoryPoolInfo();
     }
 }
Example #2
0
        /// <summary> Reads additional data required for GCM callstacks. </summary>
        /// <param name="BinaryStream"> Stream to serialize data from </param>
        bool ReadGCMData(BinaryReader BinaryStream, ref UInt32 UnsignedSize)
        {
            // @see FMallocGcmProfiler.h
            const UInt32 GCM_MEMORY_PROFILER_ID_BIT = 0x80000000;
            bool         bHasGCMData = false;

            if ((UnsignedSize & GCM_MEMORY_PROFILER_ID_BIT) == GCM_MEMORY_PROFILER_ID_BIT)
            {
                // Lower five bits are EAllocationType, upper three bits are EMemoryPool
                byte AllocationType = BinaryStream.ReadByte();
                Pool = FMemoryPoolInfo.ConvertToMemoryPoolFlag(( EMemoryPoolSerialized )(AllocationType & 0xe0));

                UnsignedSize &= ~GCM_MEMORY_PROFILER_ID_BIT;

                bHasGCMData = true;
            }

            return(bHasGCMData);
        }
Example #3
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();
        }
Example #4
0
        public static void RefreshMemoryBitmap()
        {
            if (OwnerWindow == null || OwnerWindow.CurrentSnapshot == null || !FStreamInfo.GlobalInstance.CreationOptions.KeepLifecyclesCheckBox.Checked || OwnerWindow.WindowState == FormWindowState.Minimized)
            {
                return;
            }

            if (MemoryBitmap != null)
            {
                MemoryBitmap.Dispose();
                MemoryBitmap = null;
            }

            if (bZoomSelectionActive)
            {
                MemoryBase = ZoomSelectionMemoryBase;
                MemorySize = ZoomSelectionMemorySize;
            }
            else
            {
                MemoryBase = ulong.MaxValue;
                ulong MemoryTop = ulong.MinValue;

                bool bAtLeastOnePoolSelected = false;
                bool bAtLeastOneAllocation   = false;
                foreach (EMemoryPool MemoryPool in FMemoryPoolInfo.GetMemoryPoolEnumerable())
                {
                    if (((OwnerWindow.SelectedMemoryPool & MemoryPool) != EMemoryPool.MEMPOOL_None)
                        == OwnerWindow.IsFilteringIn())
                    {
                        bAtLeastOnePoolSelected = true;

                        FMemoryPoolInfo MemPoolInfo = FStreamInfo.GlobalInstance.MemoryPoolInfo[MemoryPool];

                        if (!MemPoolInfo.IsEmpty)
                        {
                            bAtLeastOneAllocation = true;

                            MemoryBase = Math.Min(MemPoolInfo.MemoryBottom, MemoryBase);
                            MemoryTop  = Math.Max(MemPoolInfo.MemoryTop, MemoryTop);
                        }
                    }
                }

                if (!bAtLeastOnePoolSelected)
                {
                    MessageBox.Show("All memory pools are being filtered out. No data to display.");
                    return;
                }

                if (!bAtLeastOneAllocation)
                {
                    MessageBox.Show("The selected memory pools were never allocated to in this profiling run.");
                    return;
                }

                MemorySize = MemoryTop - MemoryBase;
            }

            ulong DiffbaseSnapshotStreamIndex = FStreamInfo.INVALID_STREAM_INDEX;
            ulong CurrentSnapshotStreamIndex  = OwnerWindow.CurrentSnapshot.StreamIndex;

            if (OwnerWindow.CurrentSnapshot.bIsDiffResult)
            {
                if (OwnerWindow.DiffStartComboBox.SelectedIndex == 0)
                {
                    DiffbaseSnapshotStreamIndex = 0;
                }
                else
                {
                    DiffbaseSnapshotStreamIndex = FStreamInfo.GlobalInstance.SnapshotList[OwnerWindow.DiffStartComboBox.SelectedIndex - 1].StreamIndex;
                }

                if (OwnerWindow.DiffEndComboBox.SelectedIndex == 0)
                {
                    CurrentSnapshotStreamIndex = 0;
                }
                else
                {
                    CurrentSnapshotStreamIndex = FStreamInfo.GlobalInstance.SnapshotList[OwnerWindow.DiffEndComboBox.SelectedIndex - 1].StreamIndex;
                }
            }

            OwnerWindow.SetWaitCursor(true);
            MemoryBitmap = ParseSnapshot(OwnerWindow.MemoryBitmapPanel.ClientRectangle.Width - MEMORY_BITMAP_LEFT_MARGIN, OwnerWindow.MemoryBitmapPanel.ClientRectangle.Height, CurrentSnapshotStreamIndex, DiffbaseSnapshotStreamIndex, OwnerWindow.FilterTextBox.Text);
            OwnerWindow.SetWaitCursor(false);

            if (MemoryBitmap != null)
            {
                OwnerWindow.MemoryBitmapMemorySpaceLabel.Text     = "0x" + MemoryBase.ToString("x16") + " - 0x" + (MemoryBase + MemorySize - 1).ToString("x16");
                OwnerWindow.MemoryBitmapSpaceSizeLabel.Text       = MainWindow.FormatSizeString(( long )MemorySize);
                OwnerWindow.MemoryBitmapAllocatedMemoryLabel.Text = MainWindow.FormatSizeString(AllocatedMemorySize);
            }
            else
            {
                OwnerWindow.MemoryBitmapMemorySpaceLabel.Text     = "0x00000000 - 0x00000000";
                OwnerWindow.MemoryBitmapSpaceSizeLabel.Text       = "0 bytes";
                OwnerWindow.MemoryBitmapAllocatedMemoryLabel.Text = "0 bytes";
            }

            OwnerWindow.MemoryBitmapBytesPerPixelLabel.Text = BytesPerPixel.ToString();

            OwnerWindow.MemoryBitmapAllocationHistoryListView.Items.Clear();
            OwnerWindow.MemoryBitmapCallStackListView.Items.Clear();
            OwnerWindow.MemoryBitmapPanel.Invalidate();
        }