Skip to content

Commit

Permalink
Added a 'skip to next allocation' button to the heap layout view
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Apr 6, 2011
1 parent cbb0b39 commit c5bc577
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions HeapLayoutView.cs
Expand Up @@ -17,15 +17,9 @@
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Squared.Task;
using Squared.Util;
using System.Drawing.Drawing2D;

namespace HeapProfiler {
Expand All @@ -38,6 +32,7 @@ public class HeapLayoutView : UserControl {

protected ScratchBuffer Scratch = new ScratchBuffer();
protected ScrollBar ScrollBar = null;
protected Button NextAllocationButton = null;

protected int _ScrollOffset = 0;

Expand All @@ -58,10 +53,18 @@ public class HeapLayoutView : UserControl {
TabStop = false
};

NextAllocationButton = new Button {
Text = ">",
TabStop = false,
UseVisualStyleBackColor = true
};
NextAllocationButton.Click += NextAllocationButton_Click;

ScrollBar.Scroll += ScrollBar_Scroll;
OnResize(EventArgs.Empty);

Controls.Add(ScrollBar);
Controls.Add(NextAllocationButton);
}

protected override void Dispose (bool disposing) {
Expand All @@ -74,9 +77,46 @@ public class HeapLayoutView : UserControl {
ScrollOffset = e.NewValue;
}

void NextAllocationButton_Click (object sender, EventArgs e) {
var width = ClientSize.Width - ScrollBar.Width;
int y = 0;
var target = (_ScrollOffset * RowHeight) + (ClientSize.Height / 2);

foreach (var heapId in Snapshot.Heaps.Keys) {
var heap = Snapshot.Heaps[heapId];
var itemHeight = (int)(Math.Ceiling(heap.Info.EstimatedSize / (float)BytesPerRow) + 1) * RowHeight;
var rgn = new Rectangle(0, y, width, itemHeight);
var maxX = width - MarginWidth;

foreach (var allocation in heap.Allocations) {
int pos = (int)(allocation.Address - heap.Info.EstimatedStart);
int y1 = y + ((pos / BytesPerRow) * RowHeight),
y2 = y1 + RowHeight;
float x1 = (pos % BytesPerRow) / (float)BytesPerPixel,
x2 = x1 + ((allocation.Size + allocation.Overhead) / (float)BytesPerPixel);

if (y1 <= target)
continue;

_ScrollOffset = (y1 / RowHeight) - 1;
Invalidate();
return;
}

y += itemHeight;
}
}

protected override void OnResize (EventArgs e) {
var preferredSize = ScrollBar.GetPreferredSize(ClientSize);
ScrollBar.SetBounds(ClientSize.Width - preferredSize.Width, 0, preferredSize.Width, ClientSize.Height);
ScrollBar.SetBounds(
ClientSize.Width - preferredSize.Width, 0,
preferredSize.Width, ClientSize.Height - preferredSize.Width
);

NextAllocationButton.SetBounds(
ScrollBar.Left, ScrollBar.Height, ScrollBar.Width, ScrollBar.Width
);

base.OnResize(e);
}
Expand Down

0 comments on commit c5bc577

Please sign in to comment.