public void OnUpdate() { ConsoleOut.Parameters.Text = ""; if (ConsoleOut != null) { for (int i = 0; i < _entries.Count; i++) { var entry = _entries[_entries.Count - 1 - i].Subject; string message = ""; message += FormattedText.FormatColor(Colors[Category.Fine]) + $" {entry.DateTime.ToString()} "; message += FormattedText.FormatColor(Colors[entry.Category]) + $"[{entry.Category.ToString()}] "; message += entry.Content; ConsoleOut.Parameters.Text += message; } } ConsoleOut.UpdateLayoutTree(); }
/// <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());; }
public EntryBuilder Write(string text, ColorRgba color) { Subject.Content += FormattedText.FormatColor(color); Subject.Content += text; return(this); }