private void showWhoAllocatedMenuItem_Click(object sender, System.EventArgs e) { Histogram selectedHistogram; string title; TypeDesc selectedType = FindSelectedType(); if (selectedType == null) { title = "Allocation Graph"; selectedHistogram = histogram; } else { int minSize = 0; int maxSize = int.MaxValue; foreach (Bucket b in buckets) { if (b.selected) { minSize = b.minSize; maxSize = b.maxSize; } } title = string.Format("Allocation Graph for {0} objects", selectedType.typeName); if (minSize > 0) { title += string.Format(" of size between {0:n0} and {1:n0} bytes", minSize, maxSize); } selectedHistogram = new Histogram(histogram.readNewLog); for (int i = 0; i < histogram.typeSizeStacktraceToCount.Length; i++) { int count = histogram.typeSizeStacktraceToCount[i]; if (count > 0) { int[] stacktrace = histogram.readNewLog.stacktraceTable.IndexToStacktrace(i); int typeIndex = stacktrace[0]; int size = stacktrace[1]; if (minSize <= size && size <= maxSize) { TypeDesc t = (TypeDesc)typeIndexToTypeDesc[typeIndex]; if (t == selectedType) { selectedHistogram.AddObject(i, count); } } } } } Graph graph = selectedHistogram.BuildAllocationGraph(); GraphViewForm graphViewForm = new GraphViewForm(graph, title); graphViewForm.Visible = true; }
private void showWhoAllocatedMenuItem_Click(object sender, System.EventArgs e) { Histogram selectedHistogram; string title; TypeDesc selectedType = FindSelectedType(); double minAge = 0; double maxAge = double.PositiveInfinity; double age = 0; foreach (Bucket b in bucketTable) { if (b.selected) { minAge = age; maxAge = age + timeScale; } age += timeScale; } title = "Allocation Graph for objects"; if (selectedType != null) { title = string.Format("Allocation Graph for {0} objects", selectedType.typeName); } if (minAge > 0.0) { title += string.Format(" of age between {0} and {1} seconds", FormatTime(minAge), FormatTime(maxAge)); } selectedHistogram = new Histogram(liveObjectTable.readNewLog); LiveObjectTable.LiveObject o; double nowTime = liveObjectTable.readNewLog.TickIndexToTime(liveObjectTable.lastTickIndex); for (liveObjectTable.GetNextObject(0, int.MaxValue, out o); o.id < int.MaxValue; liveObjectTable.GetNextObject(o.id + o.size, int.MaxValue, out o)) { age = nowTime - liveObjectTable.readNewLog.TickIndexToTime(o.allocTickIndex); if (minAge <= age && age < maxAge) { TypeDesc t = (TypeDesc)typeIndexToTypeDesc[o.typeIndex]; if (selectedType == null || t == selectedType) { selectedHistogram.AddObject(o.typeSizeStacktraceIndex, 1); } } } Graph graph = selectedHistogram.BuildAllocationGraph(); GraphViewForm graphViewForm = new GraphViewForm(graph, title); graphViewForm.Visible = true; }