コード例 #1
0
        DiffMemoryRegion CreateManagedStackRegion(int regionIndex, CachedSnapshot snapshot, int i)
        {
            ulong  start = snapshot.SortedManagedStacksEntries.Address(i);
            ulong  size  = (ulong)snapshot.SortedManagedStacksEntries.Bytes(i).Length;
            string name  = string.Format("Stack Sections {0}", i);

            DiffMemoryRegion region = new DiffMemoryRegion(RegionType.ManagedStack, start, size, name);

            region.ColorRegion = new Color32(0, 0, 0, (byte)(1 + regionIndex % 255));
            return(region);
        }
コード例 #2
0
        DiffMemoryRegion CreateNativeRegion(int regionIndex, CachedSnapshot snapshot, int i)
        {
            ulong  start = snapshot.SortedNativeRegionsEntries.Address(i);
            ulong  size  = (ulong)snapshot.SortedNativeRegionsEntries.Size(i);
            string name  = snapshot.SortedNativeRegionsEntries.Name(i);

            DiffMemoryRegion region;

            if (name.Contains("Virtual Memory"))
            {
                region             = new DiffMemoryRegion(RegionType.VirtualMemory, start, size, name);
                region.ColorRegion = m_ColorNative[(int)EntryColors.VirtualMemory];
            }
            else
            {
                region             = new DiffMemoryRegion(RegionType.Native, start, size, name);
                region.ColorRegion = m_ColorNative[(int)EntryColors.Region];
            }

            region.ColorRegion = new Color32(region.ColorRegion.r, region.ColorRegion.g, region.ColorRegion.b, (byte)(1 + regionIndex % 255));
            return(region);
        }
コード例 #3
0
        void SetupRegions()
        {
            ProgressBarDisplay.UpdateProgress(0.0f, "Flushing regions ...");

            uint regionCount = 0;

            for (int snapshotIdx = 0; snapshotIdx < m_Snapshots.Length; ++snapshotIdx)
            {
                regionCount += m_Snapshots[snapshotIdx].nativeMemoryRegions.Count + m_Snapshots[snapshotIdx].managedHeapSections.Count + m_Snapshots[snapshotIdx].managedStacks.Count;
            }

            m_SnapshotMemoryRegion = new DiffMemoryRegion[regionCount];

            int regionIndex = 0;

            int offset = 0;

            uint processed = 0;

            for (int i = 0; i != m_Snapshots[0].SortedNativeRegionsEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                DiffMemoryRegion region = CreateNativeRegion(regionIndex, m_Snapshots[0], i);
                region.m_Snapshot = PresenceInSnapshots.First;
                m_SnapshotMemoryRegion[regionIndex++] = region;
            }

            int offsetMax = regionIndex;

            for (int i = 0; i != m_Snapshots[1].SortedNativeRegionsEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                ulong  addr = m_Snapshots[1].SortedNativeRegionsEntries.Address(i);
                ulong  size = (ulong)m_Snapshots[1].SortedNativeRegionsEntries.Size(i);
                string name = m_Snapshots[1].SortedNativeRegionsEntries.Name(i);

                while (offset < offsetMax && m_SnapshotMemoryRegion[offset].AddressBegin < addr)
                {
                    offset++;
                }

                for (int j = offset; j < offsetMax && m_SnapshotMemoryRegion[j].AddressBegin == addr; ++j)
                {
                    if (m_SnapshotMemoryRegion[j].Name == name && m_SnapshotMemoryRegion[j].Size == size)
                    {
                        m_SnapshotMemoryRegion[j].m_Snapshot |= PresenceInSnapshots.Second;
                        name = null;
                        break;
                    }
                }

                if (name != null)
                {
                    DiffMemoryRegion region = CreateNativeRegion(regionIndex, m_Snapshots[1], i);
                    region.m_Snapshot = PresenceInSnapshots.Second;
                    m_SnapshotMemoryRegion[regionIndex++] = region;
                }
            }

            offset = regionIndex;

            for (int i = 0; i != m_Snapshots[0].SortedManagedHeapEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                DiffMemoryRegion region = CreateManagedHeapRegion(regionIndex, m_Snapshots[0], i);
                region.m_Snapshot = PresenceInSnapshots.First;
                m_SnapshotMemoryRegion[regionIndex++] = region;
            }

            offsetMax = regionIndex;

            for (int i = 0; i != m_Snapshots[1].SortedManagedHeapEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                ulong addr = m_Snapshots[1].SortedManagedHeapEntries.Address(i);
                ulong size = (ulong)m_Snapshots[1].SortedManagedHeapEntries.Size(i);

                while (offset < offsetMax && m_SnapshotMemoryRegion[offset].AddressBegin < addr)
                {
                    offset++;
                }

                for (int j = offset; j < offsetMax && m_SnapshotMemoryRegion[j].AddressBegin == addr; ++j)
                {
                    if (m_SnapshotMemoryRegion[j].Size == size)
                    {
                        m_SnapshotMemoryRegion[j].m_Snapshot |= PresenceInSnapshots.Second;
                        addr = size = 0;
                        break;
                    }
                }

                if (addr != 0)
                {
                    DiffMemoryRegion region = CreateManagedHeapRegion(regionIndex, m_Snapshots[1], i);
                    region.m_Snapshot = PresenceInSnapshots.Second;
                    m_SnapshotMemoryRegion[regionIndex++] = region;
                }
            }


            offset = regionIndex;

            for (int i = 0; i != m_Snapshots[0].SortedManagedStacksEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                DiffMemoryRegion region = CreateManagedStackRegion(regionIndex, m_Snapshots[0], i);
                region.m_Snapshot = PresenceInSnapshots.First;
                m_SnapshotMemoryRegion[regionIndex++] = region;
            }

            offsetMax = regionIndex;

            for (int i = 0; i != m_Snapshots[1].SortedManagedStacksEntries.Count; ++i)
            {
                if (processed++ % 10000 == 0)
                {
                    ProgressBarDisplay.UpdateProgress((float)processed / (float)m_SnapshotMemoryRegion.Length);
                }

                ulong addr = m_Snapshots[1].SortedManagedStacksEntries.Address(i);
                ulong size = (ulong)m_Snapshots[1].SortedManagedStacksEntries.Size(i);

                while (offset < offsetMax && m_SnapshotMemoryRegion[offset].AddressBegin < addr)
                {
                    offset++;
                }

                for (int j = offset; j < offsetMax && m_SnapshotMemoryRegion[j].AddressBegin == addr; ++j)
                {
                    if (m_SnapshotMemoryRegion[j].Size == size)
                    {
                        m_SnapshotMemoryRegion[j].m_Snapshot |= PresenceInSnapshots.Second;
                        addr = size = 0;
                        break;
                    }
                }

                if (addr != 0)
                {
                    DiffMemoryRegion region = CreateManagedStackRegion(regionIndex, m_Snapshots[1], i);
                    region.m_Snapshot = PresenceInSnapshots.Second;
                    m_SnapshotMemoryRegion[regionIndex++] = region;
                }
            }


            ProgressBarDisplay.UpdateProgress(0.0f, "Sorting regions ..");

            Array.Resize(ref m_SnapshotMemoryRegion, regionIndex);

            Array.Sort(m_SnapshotMemoryRegion, delegate(MemoryRegion a, MemoryRegion b)
            {
                int result = a.AddressBegin.CompareTo(b.AddressBegin);

                if (result == 0)
                {
                    result = -a.AddressEnd.CompareTo(b.AddressEnd);
                }

                return(result);
            }
                       );
        }