Esempio n. 1
0
        public int Compare(listing <string> a, listing <string> b)
        {
            int cmp = _cmps[0].Compare(a, b);
            int ndx = 1;

            while (ndx < _cmps.Length && cmp == 0)
            {
                cmp = _cmps[ndx++].Compare(a, b);
            }
            return(cmp);
        }
Esempio n. 2
0
 public int Compare(listing <string> a, listing <string> b)
 {
     return(Utils.NumStrAscComparer.Compare(b.Item(_ndx), a.Item(_ndx)));
 }
Esempio n. 3
0
 public int Compare(listing <string> a, listing <string> b)
 {
     return(string.Compare(b.Item(_ndx), a.Item(_ndx), StringComparison.Ordinal));
 }
Esempio n. 4
0
        public static ListingInfo ReadReportFile(string path, out string title, out string error)
        {
            error = null;
            title = String.Empty;
            StreamReader  sr      = null;
            StringBuilder sbDescr = StringBuilderCache.Acquire();

            try
            {
                int      itemCnt    = 0;
                string   colSpecs   = string.Empty;
                string[] separators = new string[] { Constants.HeavyAsteriskPadded };
                string   report     = null;
                sr = new StreamReader(path);
                string ln = sr.ReadLine();
                if (!ln.StartsWith(ReportFile.ReportPrefix))
                {
                    error = "This is not a mdrdesk report file";
                    return(null);
                }
                report = ln.Substring(ReportPrefix.Length);
                if (!string.IsNullOrWhiteSpace(report))
                {
                    sbDescr.Append("Report: ").Append(report).AppendLine();
                }
                while (ln.StartsWith(InfoPrefix))
                {
                    if (ln.StartsWith(CountPrefix))
                    {
                        var pos = Utils.SkipWhites(ln, CountPrefix.Length);
                        itemCnt = Int32.Parse(ln.Substring(pos, ln.Length - pos), NumberStyles.AllowThousands);
                        ln      = sr.ReadLine();
                    }
                    else if (ln.StartsWith(ColumnPrefix))
                    {
                        var pos = Utils.SkipWhites(ln, ColumnPrefix.Length);
                        colSpecs = ln.Substring(pos);
                        ln       = sr.ReadLine();
                    }
                    else if (ln.StartsWith(TitlePrefix))
                    {
                        title = ln.Substring(TitlePrefix.Length);
                        ln    = sr.ReadLine();
                    }
                    else if (ln.StartsWith(SeparatorPrefix))
                    {
                        var sep = ln.Substring(SeparatorPrefix.Length);
                        separators = new[] { sep };
                        ln         = sr.ReadLine();
                    }
                    else
                    {
                        ln = sr.ReadLine();
                    }
                }

                while (ln.StartsWith(DescrPrefix))
                {
                    sbDescr.Append(ln.Substring(DescrPrefix.Length)).AppendLine();
                    ln = sr.ReadLine();
                }

                ColumnType[] colTypes;
                ValueTuple <string, ColumnType, int>[] columns = GetColumnInfo(colSpecs, separators, out colTypes);

                var itemLst = new List <string>(itemCnt * columns.Length);

                while (ln != null)
                {
                    if (ln.Length == 0 || ln[0] != '#')
                    {
                        ParseReportLine(ln, separators, colTypes, itemLst);
                    }
                    else
                    {
                        if (ln.StartsWith(DescrPrefix))
                        {
                            sbDescr.Append(ln.Substring(DescrPrefix.Length)).AppendLine();
                        }
                        else if (ln.StartsWith(CountPrefix))
                        {
                            var pos = Utils.SkipWhites(ln, CountPrefix.Length);
                            itemCnt = Int32.Parse(ln.Substring(pos, ln.Length - pos), NumberStyles.AllowThousands);
                        }
                    }
                    ln = sr.ReadLine();
                }

                int colCnt = columns.Length;
                Debug.Assert((itemLst.Count % colCnt) == 0);
                var dataAry = itemLst.ToArray();
                var itemAry = new listing <string> [dataAry.Length / colCnt];
                var dataNdx = 0;
                for (int i = 0, icnt = dataAry.Length; i < icnt; i += colCnt)
                {
                    itemAry[dataNdx++] = new listing <string>(dataAry, i, colCnt);
                }

                var colInfos = new ColumnInfo[columns.Length];
                for (int i = 0, icnt = colInfos.Length; i < icnt; ++i)
                {
                    colInfos[i] = new ColumnInfo(columns[i].Item1, columns[i].Item2, columns[i].Item3, i + 1, true);
                }

                //if (IsColumnTypeString(colInfos[0].ColumnType))
                //{
                //	Array.Sort(itemAry, new ListingStrCmpAsc(0));
                //}
                //else
                //{
                //	Array.Sort(itemAry, new ListingNumCmpAsc(0));
                //}

                var result = new ListingInfo(null, itemAry, colInfos, sbDescr.ToString(), title);
                return(result);
            }
            catch (Exception ex)
            {
                error = Utils.GetExceptionErrorString(ex);
                return(null);
            }
            finally
            {
                StringBuilderCache.Release(sbDescr);
                sr?.Close();
            }
        }
Esempio n. 5
0
 public listing(listing <T> other)
 {
     _ary    = other._ary;
     _offset = other._offset;
     _count  = other._count;
 }
Esempio n. 6
0
        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);
            }
        }