Example #1
0
        public void GetAllocations(List <FragAllocData> data, ulong addr_lo, ulong addr_hi)
        {
            // Find lower bound.
            var sa = m_Trace.AllocationsByAddress;

            if (sa.Count == 0)
            {
                return;
            }

            var key_lo   = HeapAllocationInfo.CreateSearchKey(addr_lo);
            var key_hi   = HeapAllocationInfo.CreateSearchKey(addr_hi);
            int index_lo = sa.BinarySearch(key_lo, new HeapAllocationInfo.EndComparer());
            int index_hi = sa.BinarySearch(key_hi, new HeapAllocationInfo.StartComparer());

            if (index_lo < 0)
            {
                index_lo = (~index_lo);
            }

            if (index_hi < 0)
            {
                index_hi = (~index_hi);
            }

            index_lo = Math.Min(Math.Max(0, index_lo), sa.Count - 1);
            index_hi = Math.Min(Math.Max(0, index_hi), sa.Count);

            for (int i = index_lo; i < index_hi; ++i)
            {
                ulong col = 0xefefefef;
                var   a   = sa[i];
                foreach (var frame in a.BackTrace.Frames)
                {
                    col = ((col << 60) | (col >> 4)) ^ frame.Address;
                }
                int r = Math.Min((int)(col & 0xff), 0xc0);
                int g = Math.Min((int)(col & 0xff00) >> 8, 0xc0);
                int b = Math.Min((int)(col & 0xff0000) >> 16, 0xc0);
                data.Add(new FragAllocData {
                    Alloc = a, Color = Color.FromArgb(255, (int)col & 0xff, (int)(col >> 8) & 0xff, (int)(col >> 16) & 0xff)
                });
            }
        }