4 using System.Collections.Generic;
5 using System.Collections.ObjectModel;
6 using System.Diagnostics;
10 namespace SiliconStudio.Core.Diagnostics
18 if (
string.IsNullOrWhiteSpace(text))
19 throw new ArgumentException(
"Invalid 'text' argument");
21 throw new ArgumentNullException(
"report");
24 this.report.BeginMeasure(text);
37 public string Text {
get; set; }
38 public long Milliseconds {
get; set; }
39 public long Ticks {
get; set; }
44 private readonly List<PerformanceReportInfo> measures =
new List<PerformanceReportInfo>();
46 private readonly Stopwatch stopwatch =
new Stopwatch();
47 private string currentMeasureText;
51 Measures =
new ReadOnlyCollection<PerformanceReportInfo>(measures);
54 [Conditional(
"DEBUG")]
57 if (currentMeasureText != null)
60 currentMeasureText = text;
65 [Conditional(
"DEBUG")]
70 var ticks = stopwatch.ElapsedTicks;
71 var ms = stopwatch.ElapsedMilliseconds;
73 measures.Add(
new PerformanceReportInfo { Text = currentMeasureText, Milliseconds = ms, Ticks = ticks });
74 currentMeasureText = null;
84 var sb =
new StringBuilder();
86 var totalTicks = measures.Sum(info => info.Ticks);
88 foreach (var info
in measures)
90 sb.AppendLine(string.Format(
"{0}: {1} ms, {2} ticks ({3:F2}%)",
91 info.Text, info.Milliseconds, info.Ticks, ((double)info.Ticks * 100.0 / (
double)totalTicks)));