Skip to content

Commit

Permalink
Tweaks to treemap layout algorithm
Browse files Browse the repository at this point in the history
Treemap shows breadcrumbs when drilled down
Show module name along with function name in treemap nodes
Treemap nodes with long captions are shortened via an ellipsis in the middle
Fixed stack graphs being built in the wrong direction
Fixed broken filtering in diff viewer
  • Loading branch information
kg committed Apr 28, 2011
1 parent 09e5dcb commit d47a345
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 243 deletions.
2 changes: 1 addition & 1 deletion CustomTooltip.cs
Expand Up @@ -172,7 +172,7 @@ public partial class CustomTooltip : Form {
FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap |
StringFormatFlags.DisplayFormatControl | StringFormatFlags.MeasureTrailingSpaces,
HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None,
Trimming = StringTrimming.None
Trimming = StringTrimming.EllipsisPath
};

}
Expand Down
3 changes: 2 additions & 1 deletion DeltaHistogram.cs
Expand Up @@ -320,7 +320,8 @@ public class VisibleItemComparer : IComparer<VisibleItem> {
var bitmap = TextCache.Get(
g, itemText, Font, RotateFlipType.Rotate90FlipNone,
white ? Color.White : Color.Black,
white ? Color.Black : Color.LightGray, sf
white ? Color.Black : Color.LightGray, sf,
new SizeF(barRectangle.Height, barRectangle.Width)
);

g.DrawImageUnscaled(
Expand Down
2 changes: 1 addition & 1 deletion DiffViewer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

165 changes: 89 additions & 76 deletions DiffViewer.cs
Expand Up @@ -40,6 +40,8 @@ public partial class DiffViewer : TaskForm {
protected Pair<int> PendingLoadPair = new Pair<int>(-1, -1);
protected HeapRecording Instance = null;

protected IFuture PendingRefresh = null;

protected Pair<int> CurrentPair = new Pair<int>(-1, -1);
protected string Filename;
protected Regex FunctionFilter = null;
Expand Down Expand Up @@ -169,7 +171,10 @@ public DiffViewer (TaskScheduler scheduler)
Filename = filename;

RefreshModules();
Start(RefreshDeltas());

if (PendingRefresh != null)
PendingRefresh.Dispose();
PendingRefresh = Start(RefreshDeltas());

MainMenuStrip.Enabled = true;
LoadingPanel.Visible = false;
Expand Down Expand Up @@ -222,91 +227,93 @@ public DiffViewer (TaskScheduler scheduler)
}

public IEnumerator<object> RefreshDeltas () {
if (Updating)
yield break;

SetBusy(true);

Future<int> fTotalBytes = new Future<int>(),
fTotalAllocs = new Future<int>(),
fMax = new Future<int>();
var newListItems = new List<DeltaInfo>();
var moduleList = ModuleList;
var deltas = Deltas;
var functionFilter = FunctionFilter;

yield return Future.RunInThread(() => {
int max = -int.MaxValue;
int totalBytes = 0, totalAllocs = 0;
foreach (var delta in deltas) {
if (functionFilter != null) {
bool matched = false;
foreach (var functionName in delta.Traceback.Functions) {
if (functionFilter.IsMatch(functionName)) {
matched = true;
break;
try {
if (Updating)
yield break;

SetBusy(true);

Future<int> fTotalBytes = new Future<int>(),
fTotalAllocs = new Future<int>(),
fMax = new Future<int>();
var newListItems = new List<DeltaInfo>();
var moduleList = ModuleList;
var deltas = Deltas;
var functionFilter = FunctionFilter;

yield return Future.RunInThread(() => {
int max = -int.MaxValue;
int totalBytes = 0, totalAllocs = 0;
foreach (var delta in deltas) {
if (functionFilter != null) {
bool matched = false;
foreach (var functionName in delta.Traceback.Functions) {
if (functionFilter.IsMatch(functionName)) {
matched = true;
break;
}
}
if (!matched)
continue;
}
if (!matched)
continue;
}
bool filteredOut = (delta.Traceback.Modules.Count > 0);
foreach (var module in delta.Traceback.Modules) {
filteredOut &= !moduleList.SelectedItems.Contains(module);
bool filteredOut = (delta.Traceback.Modules.Count > 0);
foreach (var module in delta.Traceback.Modules) {
filteredOut &= !moduleList.SelectedItems.Contains(module);
if (!filteredOut)
break;
}
if (!filteredOut)
break;
if (!filteredOut) {
newListItems.Add(delta);
totalBytes += delta.BytesDelta;
totalAllocs += delta.CountDelta.GetValueOrDefault(0);
max = Math.Max(max, delta.BytesDelta);
}
}
if (!filteredOut) {
newListItems.Add(delta);
totalBytes += delta.BytesDelta;
totalAllocs += delta.CountDelta.GetValueOrDefault(0);
max = Math.Max(max, delta.BytesDelta);
}
max = Math.Max(max, Math.Abs(totalBytes));
fTotalBytes.Complete(totalBytes);
fTotalAllocs.Complete(totalAllocs);
fMax.Complete(max);
});

StatusLabel.Text = String.Format("Showing {0} out of {1} item(s)", newListItems.Count, deltas.Count);
AllocationTotals.Text = String.Format("Delta bytes: {0} Delta allocations: {1}", FileSize.Format(fTotalBytes.Result), fTotalAllocs.Result);

if (Instance != null) {
StackGraph = new StackGraph();
yield return StackGraph.Build(Instance, newListItems);
} else
StackGraph = null;

if (StackGraph != null) {
GraphHistogram.Items = StackGraph.Functions.OrderedItems.ToArray();
GraphTreemap.Items = StackGraph.OrderedItems.ToArray();
} else {
GraphHistogram.Items = null;
GraphTreemap.Items = null;
}

max = Math.Max(max, Math.Abs(totalBytes));
fTotalBytes.Complete(totalBytes);
fTotalAllocs.Complete(totalAllocs);
fMax.Complete(max);
});
DeltaHistogram.Items = DeltaList.Items = newListItems;
if (newListItems.Count > 0)
GraphHistogram.Maximum = DeltaHistogram.Maximum = fMax.Result;
else
GraphHistogram.Maximum = DeltaHistogram.Maximum = 1024;

StatusLabel.Text = String.Format("Showing {0} out of {1} item(s)", newListItems.Count, deltas.Count);
AllocationTotals.Text = String.Format("Delta bytes: {0} Delta allocations: {1}", FileSize.Format(fTotalBytes.Result), fTotalAllocs.Result);
GraphHistogram.TotalDelta = DeltaHistogram.TotalDelta = fTotalBytes.Result;

if (Instance != null) {
StackGraph = new StackGraph();
yield return StackGraph.Build(Instance, newListItems);
} else
StackGraph = null;

if (StackGraph != null) {
GraphHistogram.Items = StackGraph.TopItems.ToArray();
GraphTreemap.Items = StackGraph.Roots.ToArray();
} else {
GraphHistogram.Items = null;
GraphTreemap.Items = null;
DeltaList.Invalidate();
DeltaHistogram.Invalidate();
GraphHistogram.Invalidate();
GraphTreemap.Refresh();
} finally {
SetBusy(false);
}

DeltaHistogram.Items = DeltaList.Items = newListItems;
if (newListItems.Count > 0)
GraphHistogram.Maximum = DeltaHistogram.Maximum = fMax.Result;
else
GraphHistogram.Maximum = DeltaHistogram.Maximum = 1024;

GraphHistogram.TotalDelta = DeltaHistogram.TotalDelta = fTotalBytes.Result;

DeltaList.Invalidate();
DeltaHistogram.Invalidate();
GraphHistogram.Invalidate();
GraphTreemap.Refresh();

SetBusy(false);
}

private void DiffViewer_Shown (object sender, EventArgs e) {
Expand Down Expand Up @@ -363,7 +370,11 @@ public DiffViewer (TaskScheduler scheduler)
private void TracebackFilter_FilterChanged (object sender, EventArgs e) {
var filter = MainWindow.FilterToRegex(TracebackFilter.Filter);
GraphHistogram.FunctionFilter = DeltaHistogram.FunctionFilter = DeltaList.FunctionFilter = FunctionFilter = filter;
Start(RefreshDeltas());

if (PendingRefresh != null)
PendingRefresh.Dispose();

PendingRefresh = Start(RefreshDeltas());
}

private void ViewListMenu_Click (object sender, EventArgs e) {
Expand Down Expand Up @@ -398,7 +409,9 @@ public DiffViewer (TaskScheduler scheduler)
}

private void ModuleList_FilterChanged (object sender, EventArgs e) {
Start(RefreshDeltas());
if (PendingRefresh != null)
PendingRefresh.Dispose();
PendingRefresh = Start(RefreshDeltas());
}

private void ViewFunctionHistogramMenu_Click (object sender, EventArgs e) {
Expand Down
18 changes: 10 additions & 8 deletions FilterControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion FilterControl.cs
Expand Up @@ -17,6 +17,12 @@ public partial class FilterControl : UserControl {

public FilterControl () {
InitializeComponent();

var height = Math.Max(FilterText.Height, FilterText.GetPreferredSize(new Size(999, 999)).Height);

MinimumSize = new Size(0, height);
MaximumSize = new Size(999999, height);
Height = height;
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Expand Down Expand Up @@ -51,7 +57,9 @@ public partial class FilterControl : UserControl {
}

private void FilterControl_SizeChanged (object sender, EventArgs e) {
FilterText.Width = this.ClientSize.Width - FindIcon.Width;
FilterText.SetBounds(
FindIcon.Width, 0, ClientSize.Width - FindIcon.Width, ClientSize.Height
);
}

private void FilterText_TextChanged (object sender, EventArgs e) {
Expand Down
2 changes: 1 addition & 1 deletion HeapRecording.cs
Expand Up @@ -836,7 +836,7 @@ string filename

yield return graph.Build(snapshot, tracebacks, symbols);

topNodes.Add(graph.TopItems.Take(resultCount).ToArray());
topNodes.Add(graph.OrderedItems.Take(resultCount).ToArray());

info.ReleaseStrongReference();

Expand Down

0 comments on commit d47a345

Please sign in to comment.