public override void GetReportData(out ProfileReportCounterData data, ProfileReportOptions options) { data = new ProfileReportCounterData(); data.Severity = 0.5f; if ((options & ProfileReportOptions.LastValue) != ProfileReportOptions.None) data.LastValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.lastValue); if (this.IsSingleValue) { if ((options & ProfileReportOptions.AverageValue) != ProfileReportOptions.None) data.AverageValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.lastValue); } else { if ((options & ProfileReportOptions.AverageValue) != ProfileReportOptions.None) data.AverageValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", (int)Math.Round((double)this.accumValue / (double)this.sampleCount)); if ((options & ProfileReportOptions.MinValue) != ProfileReportOptions.None) data.MinValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.accumMinValue); if ((options & ProfileReportOptions.MaxValue) != ProfileReportOptions.None) data.MaxValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.accumMaxValue); if ((options & ProfileReportOptions.SampleCount) != ProfileReportOptions.None) data.SampleCount = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.sampleCount); } }
public override void GetReportData(out ProfileReportCounterData data, ProfileReportOptions options) { data = new ProfileReportCounterData(); data.Severity = 0.5f; if ((options & ProfileReportOptions.LastValue) != ProfileReportOptions.None) { data.LastValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.lastValue); } if (this.IsSingleValue) { if ((options & ProfileReportOptions.AverageValue) != ProfileReportOptions.None) { data.AverageValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.lastValue); } } else { if ((options & ProfileReportOptions.AverageValue) != ProfileReportOptions.None) { data.AverageValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", (int)Math.Round((double)this.accumValue / (double)this.sampleCount)); } if ((options & ProfileReportOptions.MinValue) != ProfileReportOptions.None) { data.MinValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.accumMinValue); } if ((options & ProfileReportOptions.MaxValue) != ProfileReportOptions.None) { data.MaxValue = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.accumMaxValue); } if ((options & ProfileReportOptions.SampleCount) != ProfileReportOptions.None) { data.SampleCount = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", this.sampleCount); } } }
/// <summary> /// Creates a text report of the current profiling data and returns it as string. /// </summary> /// <param name="filePath"></param> public static string GetTextReport(IEnumerable <ProfileCounter> reportCounters, ProfileReportOptions options = ProfileReportOptions.LastValue) { bool omitMinor = (options & ProfileReportOptions.OmitMinorValues) != ProfileReportOptions.None; // Group Counters by Type Dictionary <Type, List <ProfileCounter> > countersByType = new Dictionary <Type, List <ProfileCounter> >(); Type[] existingTypes = reportCounters.Select(c => c.GetType()).Distinct().ToArray(); foreach (Type type in existingTypes) { countersByType[type] = reportCounters.Where(c => c.GetType() == type).ToList(); } // Prepare text building StringBuilder reportBuilder = new StringBuilder(countersByType.Count * 256); // Handle each group separately foreach (var pair in countersByType) { IEnumerable <ProfileCounter> counters = pair.Value; int minDepth = counters.Min(c => c.ParentDepth); IEnumerable <ProfileCounter> rootCounters = counters.Where(c => c.ParentDepth == minDepth); int maxNameLen = counters.Max(c => c.DisplayName.Length + c.ParentDepth * 2); if (options.HasFlag(ProfileReportOptions.GroupHeader)) { reportBuilder.Append(options.HasFlag(ProfileReportOptions.FormattedText) ? FormattedText.FormatNewline : Environment.NewLine); reportBuilder.AppendLine(("[ " + pair.Key.Name + " ]").PadLeft(35, '-').PadRight(50, '-')); reportBuilder.Append(options.HasFlag(ProfileReportOptions.FormattedText) ? FormattedText.FormatNewline : Environment.NewLine); } else if (reportBuilder.Length > 0) { reportBuilder.Append(options.HasFlag(ProfileReportOptions.FormattedText) ? FormattedText.FormatNewline : Environment.NewLine); } if (options.HasFlag(ProfileReportOptions.Header)) { if (options.HasFlag(ProfileReportOptions.FormattedText)) { reportBuilder.Append(FormattedText.FormatColor(ColorRgba.White.WithAlpha(0.5f))); } reportBuilder.Append("Name"); reportBuilder.Append(' ', 1 + Math.Max((1 + maxNameLen) - "Name".Length, 0)); if (options.HasFlag(ProfileReportOptions.LastValue)) { reportBuilder.Append(" Last Value "); } if (options.HasFlag(ProfileReportOptions.AverageValue)) { reportBuilder.Append(" Avg. Value "); } if (options.HasFlag(ProfileReportOptions.MinValue)) { reportBuilder.Append(" Min. Value "); } if (options.HasFlag(ProfileReportOptions.MaxValue)) { reportBuilder.Append(" Max. Value "); } if (options.HasFlag(ProfileReportOptions.SampleCount)) { reportBuilder.Append(" Samples "); } reportBuilder.Append(options.HasFlag(ProfileReportOptions.FormattedText) ? FormattedText.FormatNewline : Environment.NewLine); if (options.HasFlag(ProfileReportOptions.FormattedText)) { reportBuilder.Append(FormattedText.FormatColor(ColorRgba.White)); } } Stack <ProfileCounter> appendStack = new Stack <ProfileCounter>(rootCounters.Reverse()); while (appendStack.Count > 0) { ProfileCounter current = appendStack.Pop(); ProfileReportCounterData data; current.GetReportData(out data); if (omitMinor && data.Severity <= 0.005f) { continue; } if (options.HasFlag(ProfileReportOptions.FormattedText)) { float severity = data.Severity; ColorRgba lineColor = severity >= 0.5f ? ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, 2.0f * (severity - 0.5f)) : ColorRgba.Lerp(ColorRgba.TransparentWhite, ColorRgba.White, 0.1f + 0.9f * (2.0f * severity)); reportBuilder.Append(FormattedText.FormatColor(lineColor)); } reportBuilder.Append(' ', current.ParentDepth * 2); reportBuilder.Append(current.DisplayName); reportBuilder.Append(':'); reportBuilder.Append(' ', 1 + Math.Max((1 + maxNameLen) - (current.ParentDepth * 2 + current.DisplayName.Length + 1), 0)); if (options.HasFlag(ProfileReportOptions.LastValue)) { string valStr = data.LastValue ?? "-"; reportBuilder.Append(' ', Math.Max(13 - valStr.Length, 0)); reportBuilder.Append(valStr); reportBuilder.Append(' '); } if (options.HasFlag(ProfileReportOptions.AverageValue)) { string valStr = data.AverageValue ?? "-"; reportBuilder.Append(' ', Math.Max(13 - valStr.Length, 0)); reportBuilder.Append(valStr); reportBuilder.Append(' '); } if (options.HasFlag(ProfileReportOptions.MinValue)) { string valStr = data.MinValue ?? "-"; reportBuilder.Append(' ', Math.Max(13 - valStr.Length, 0)); reportBuilder.Append(valStr); reportBuilder.Append(' '); } if (options.HasFlag(ProfileReportOptions.MaxValue)) { string valStr = data.MaxValue ?? "-"; reportBuilder.Append(' ', Math.Max(13 - valStr.Length, 0)); reportBuilder.Append(valStr); reportBuilder.Append(' '); } if (options.HasFlag(ProfileReportOptions.SampleCount)) { string valStr = data.SampleCount ?? "-"; reportBuilder.Append(' ', Math.Max(15 - valStr.Length, 0)); reportBuilder.Append(valStr); reportBuilder.Append(' '); } reportBuilder.Append(options.HasFlag(ProfileReportOptions.FormattedText) ? FormattedText.FormatNewline : Environment.NewLine); IEnumerable <ProfileCounter> childCounters = counters.Where(c => c.Parent == current); foreach (ProfileCounter child in childCounters.Reverse()) { appendStack.Push(child); } } if (options.HasFlag(ProfileReportOptions.FormattedText)) { reportBuilder.Append(FormattedText.FormatColor(ColorRgba.White)); } } return(reportBuilder.ToString());; }
/// <summary> /// Gathers ProfileCounter data for generating a profile report. /// </summary> /// <param name="data"></param> /// <param name="options"></param> public abstract void GetReportData(out ProfileReportCounterData data, ProfileReportOptions options);