public static ClrtSegment[] ReadSegments(BinaryReader reader) { var count = reader.ReadInt32(); ClrtSegment[] segments = new ClrtSegment[count]; for (var i = 0; i < count; ++i) { segments[i] = Read(reader); } return(segments); }
private static ClrtSegment Read(BinaryReader reader) { var seg = new ClrtSegment { CommittedEnd = reader.ReadUInt64(), ReservedEnd = reader.ReadUInt64(), Start = reader.ReadUInt64(), End = reader.ReadUInt64(), Gen0Start = reader.ReadUInt64(), Gen0Length = reader.ReadUInt64(), Gen1Start = reader.ReadUInt64(), Gen1Length = reader.ReadUInt64(), Gen2Start = reader.ReadUInt64(), Gen2Length = reader.ReadUInt64(), FirstObject = reader.ReadUInt64(), FirstAddress = reader.ReadUInt64(), LastAddress = reader.ReadUInt64(), ProcessorAffinity = reader.ReadInt32(), FirstIndex = reader.ReadInt32(), EndIndex = reader.ReadInt32(), Ephemeral = reader.ReadBoolean(), Large = reader.ReadBoolean(), _gen0Count = reader.ReadInt32(), _gen1Count = reader.ReadInt32(), _gen2Count = reader.ReadInt32(), _gen0Size = reader.ReadUInt64(), _gen1Size = reader.ReadUInt64(), _gen2Size = reader.ReadUInt64(), _gen0UnrootedCount = reader.ReadInt32(), _gen1UnrootedCount = reader.ReadInt32(), _gen2UnrootedCount = reader.ReadInt32(), _gen0UnrootedSize = reader.ReadUInt64(), _gen1UnrootedSize = reader.ReadUInt64(), _gen2UnrootedSize = reader.ReadUInt64(), _gen0FreeCount = reader.ReadInt32(), _gen1FreeCount = reader.ReadInt32(), _gen2FreeCount = reader.ReadInt32(), _gen0FreeSize = reader.ReadUInt64(), _gen1FreeSize = reader.ReadUInt64(), _gen2FreeSize = reader.ReadUInt64(), FirstObjBad = reader.ReadBoolean(), BadCount = reader.ReadInt32() }; return(seg); }
/// <summary> /// /// </summary> /// <param name="rtmNdx"></param> /// <param name="segments"></param> /// <param name="instances"></param> /// <param name="sizes"></param> /// <param name="fileMoniker"></param> /// <param name="hasUnrootedInfo"></param> /// <returns></returns> public static Tuple <int[], ulong[], int[], ulong[], int[], ulong[]> GetTotalGenerationDistributions(int rtmNdx, ClrtSegment[] segments, ulong[] instances, uint[] sizes, DumpFileMoniker fileMoniker, bool hasUnrootedInfo) { var genTotalCount = new int[4]; var genTotalSize = new ulong[4]; var genTotalUnrootedCount = new int[4]; var genTotalUnrootedSize = new ulong[4]; var freeTotalGenCount = new int[4]; var freeTotalGenSize = new ulong[4]; // check unrooted // if (!hasUnrootedInfo) { for (int i = 0, icnt = instances.Length; i < icnt; ++i) { if (!Utils.IsRooted(instances[i])) { var addr = instances[i]; var seg = ClrtSegment.FindSegment(segments, addr); if (seg == null) { continue; } var gen = seg.GetGeneration(addr); if (gen == Generation.Uknown) { continue; } seg.IncUnrooted(gen, sizes[i]); } } string error; ClrtSegment.DumpSegments(fileMoniker.GetFilePath(rtmNdx, Constants.MapSegmentInfoFilePostfix), segments, out error, true); } for (int i = 0, icnt = segments.Length; i < icnt; ++i) { var seg = segments[i]; if (seg.Large) { genTotalCount[(int)Generation.Large] += seg.Gen0Count; genTotalSize[(int)Generation.Large] += seg.Gen0Size; freeTotalGenCount[(int)Generation.Large] += seg.Gen0FreeCount; freeTotalGenSize[(int)Generation.Large] += seg.Gen0FreeSize; genTotalUnrootedCount[(int)Generation.Large] += seg.Gen0UnrootedCount; genTotalSize[(int)Generation.Large] += seg.Gen0UnrootedSize; continue; } genTotalCount[(int)Generation.Gen0] += seg.Gen0Count; genTotalSize[(int)Generation.Gen0] += seg.Gen0Size; genTotalUnrootedCount[(int)Generation.Gen0] += seg.Gen0UnrootedCount; genTotalUnrootedSize[(int)Generation.Gen0] += seg.Gen0UnrootedSize; freeTotalGenCount[(int)Generation.Gen0] += seg.Gen0FreeCount; freeTotalGenSize[(int)Generation.Gen0] += seg.Gen0FreeSize; genTotalCount[(int)Generation.Gen1] += seg.Gen1Count; genTotalSize[(int)Generation.Gen1] += seg.Gen1Size; genTotalUnrootedCount[(int)Generation.Gen1] += seg.Gen1UnrootedCount; genTotalUnrootedSize[(int)Generation.Gen1] += seg.Gen1UnrootedSize; freeTotalGenCount[(int)Generation.Gen1] += seg.Gen1FreeCount; freeTotalGenSize[(int)Generation.Gen1] += seg.Gen1FreeSize; genTotalCount[(int)Generation.Gen2] += seg.Gen2Count; genTotalSize[(int)Generation.Gen2] += seg.Gen2Size; genTotalUnrootedCount[(int)Generation.Gen2] += seg.Gen2UnrootedCount; genTotalUnrootedSize[(int)Generation.Gen2] += seg.Gen2UnrootedSize; freeTotalGenCount[(int)Generation.Gen2] += seg.Gen2FreeCount; freeTotalGenSize[(int)Generation.Gen2] += seg.Gen2FreeSize; } return(Tuple.Create(genTotalCount, genTotalSize, freeTotalGenCount, freeTotalGenSize, genTotalUnrootedCount, genTotalUnrootedSize)); }
public ListingInfo GetGridData(int minReferenceCount, ClrtSegment[] segments, out string error) { const int COLUMN_COUNT = 8; error = null; try { string[] dataAry; listing <string>[] itemAry; if (minReferenceCount < 1) { minReferenceCount = 1; } if (minReferenceCount < 2) { dataAry = new string[_strings.Length * COLUMN_COUNT]; itemAry = new listing <string> [dataAry.Length / COLUMN_COUNT]; int dataNdx = 0; for (int i = 0, icnt = _strings.Length; i < icnt; ++i) { var count = _counts[i]; var countStr = Utils.LargeNumberString(count); var size = _sizes[i]; var sizeStr = Utils.LargeNumberString(size); long totSize = (long)count * (long)size; var totSizeStr = Utils.LargeNumberString(totSize); var str = ReportFile.GetReportLineString(_strings[i]); var generations = ClrtSegment.GetGenerationHistogram(segments, _adddresses[i]); itemAry[i] = new listing <string>(dataAry, dataNdx, COLUMN_COUNT); dataAry[dataNdx++] = countStr; dataAry[dataNdx++] = sizeStr; dataAry[dataNdx++] = totSizeStr; dataAry[dataNdx++] = Utils.LargeNumberString(generations[0]); dataAry[dataNdx++] = Utils.LargeNumberString(generations[1]); dataAry[dataNdx++] = Utils.LargeNumberString(generations[2]); dataAry[dataNdx++] = Utils.LargeNumberString(generations[3]); dataAry[dataNdx++] = str; } } else { List <string> lst = new List <string>(_strings.Length); for (int i = 0, icnt = _strings.Length; i < icnt; ++i) { var count = _counts[i]; if (count < minReferenceCount) { continue; } var countStr = Utils.LargeNumberString(count); var size = _sizes[i]; var sizeStr = Utils.LargeNumberString(size); long totSize = (long)count * (long)size; var totSizeStr = Utils.LargeNumberString(totSize); var str = ReportFile.GetReportLineString(_strings[i]); var generations = ClrtSegment.GetGenerationHistogram(segments, _adddresses[i]); lst.Add(countStr); lst.Add(sizeStr); lst.Add(totSizeStr); lst.Add(Utils.LargeNumberString(generations[0])); lst.Add(Utils.LargeNumberString(generations[1])); lst.Add(Utils.LargeNumberString(generations[2])); lst.Add(Utils.LargeNumberString(generations[3])); lst.Add(str); } dataAry = lst.ToArray(); itemAry = new listing <string> [dataAry.Length / COLUMN_COUNT]; int dataNdx = 0; for (int i = 0, icnt = itemAry.Length; i < icnt; ++i) { itemAry[i] = new listing <string>(dataAry, dataNdx, COLUMN_COUNT); dataNdx += COLUMN_COUNT; } } StringBuilder sb = StringBuilderCache.Acquire(StringBuilderCache.MaxCapacity); sb.Append(ReportFile.DescrPrefix); sb.Append("String instance count: ") .Append(Utils.LargeNumberString(_totalCount)) .Append(", unique string count: ") .Append(Utils.LargeNumberString(_strings.Length)) .AppendLine(); sb.Append(ReportFile.DescrPrefix); sb.Append("Total size: ") .Append(Utils.LargeNumberString(_totalSize)) .Append(", total unique size: ") .Append(Utils.LargeNumberString(_totalUniqueSize)) .AppendLine(); sb.Append(ReportFile.DescrPrefix); sb.Append("Possible memory savings: ") .Append(Utils.LargeNumberString(_totalSize - _totalUniqueSize)) .AppendLine(); sb.Append(ReportFile.DescrPrefix); sb.Append("LISTING CONTAINS STRINGS WITH REFERENCE COUNT AT LEAST " + minReferenceCount) .Append(", DISPLAYED COUNT: ").Append(Utils.LargeNumberString(itemAry.Length)) .AppendLine(); ColumnInfo[] columns = { new ColumnInfo("Count", ReportFile.ColumnType.Int32, 100, 1, true), new ColumnInfo("Size", ReportFile.ColumnType.Int32, 100, 2, true), new ColumnInfo("Total Size", ReportFile.ColumnType.Int64, 100, 3, true), new ColumnInfo("Gen 0", ReportFile.ColumnType.Int64, 100, 4, true), new ColumnInfo("Gen 1", ReportFile.ColumnType.Int64, 100, 5, true), new ColumnInfo("Gen 2", ReportFile.ColumnType.Int64, 100, 6, true), new ColumnInfo("LOH", ReportFile.ColumnType.Int64, 100, 7, true), new ColumnInfo("String Content", ReportFile.ColumnType.String, 1500, 8, true), }; return(new ListingInfo(null, itemAry, columns, StringBuilderCache.GetStringAndRelease(sb))); } catch (Exception ex) { error = Utils.GetExceptionErrorString(ex); return(null); } }