public void End(string section) { if (activeSections.Count == 0) { throw new InvalidOperationException("No active sections"); } if (activeSections.Peek().Name != section) { throw new ArgumentException("Section begin/end mismatch", "section"); } ActiveSection activeSection = activeSections.Pop(); long endTick = timer.CurrentTick(); long duration = endTick - activeSection.StartTick; SectionResult result = new SectionResult(section, duration); if (activeSection.Children.Count != 0) { foreach (SectionResult childResult in activeSection.Children) { childResult.Parent = result; result.Children.Add(childResult); } } if (activeSection.Parent == null) { // Last element is the active frame. frameResults[frameResults.Count - 1].Sections.Add(result); } else { activeSection.Parent.Children.Add(result); } }
private void ComputeSection(SectionResult section, long parentDuration) { section.TotalFraction = (float)((double)section.Duration / (double)TotalDuration); section.SiblingFraction = (float)((double)section.Duration / (double)parentDuration); foreach (SectionResult childResult in section.Children) { ComputeSection(childResult, section.Duration); } }
public static FrameResult Deserialize(DataStream stream) { uint frameIndex = stream.ReadUInt(); long totalDuration = stream.ReadLong(); int sectionCount = stream.ReadUShort(); FrameResult result = new FrameResult(frameIndex, totalDuration); for (int i = 0; i < sectionCount; i++) { SectionResult section = SectionResult.Deserialize(stream); result.Sections.Add(section); } return(result); }
public static SectionResult Deserialize(DataStream stream, SectionResult parent = null) { int nameLength = stream.ReadUShort(); byte[] nameBuffer = stream.ReadBytes(nameLength); string name = Encoding.UTF8.GetString(nameBuffer, 0, nameLength); long duration = stream.ReadLong(); float silblingFraction = stream.ReadFloat(); float totalFraction = stream.ReadFloat(); SectionResult result = new SectionResult(name, duration, silblingFraction, totalFraction, parent); int childCount = stream.ReadUShort(); for (int i = 0; i < childCount; i++) { SectionResult child = Deserialize(stream, result); result.Children.Add(child); } return(result); }
private SectionResult(string name, long duration, float siblingFraction, float totalFraction, SectionResult parent) { this.Name = name; this.Duration = duration; this.SiblingFraction = siblingFraction; this.TotalFraction = totalFraction; this.Parent = parent; this.Children = new List <SectionResult>(); }