1using System.Collections.Generic;
11 private readonly Dictionary<string, long> sumTicks =
new Dictionary<string, long>();
12 private readonly SortedDictionary<long, LinkedList<ProfilerEvent>> timeline =
new SortedDictionary<long, LinkedList<ProfilerEvent>>();
13 private readonly LinkedList<string> order =
new LinkedList<string>();
15 private readonly
object synchObj =
new object();
16 private long startTick = 0;
17 private long lastTick = 0;
18 private string lastName =
null;
39 this.CheckNameLocked(Tick);
41 this.AddLocked(Tick,
Event);
47 if (!this.timeline.TryGetValue(Tick, out LinkedList<ProfilerEvent> Events))
49 Events =
new LinkedList<ProfilerEvent>();
50 this.timeline[Tick] = Events;
53 Events.AddLast(
Event);
56 private void CheckNameLocked(
long Tick)
58 if (!
string.IsNullOrEmpty(this.lastName))
60 long Diff = Tick - this.lastTick;
62 if (this.sumTicks.TryGetValue(
this.lastName, out
long l))
63 this.sumTicks[this.lastName] = l + Diff;
66 this.sumTicks[this.lastName] = Diff;
67 this.order.AddLast(this.lastName);
94 this.CheckNameLocked(Tick);
109 this.CheckNameLocked(Tick);
110 this.lastTick = Tick;
111 this.lastName =
Event.State;
119 public void Report(List<ProfilerEvent> Result)
123 long Tick = this.startTick;
125 foreach (
string Name
in this.order)
127 if (this.sumTicks.TryGetValue(Name, out
long Ticks))
129 this.AddLocked(Tick,
new NewState(Tick, Name, this.thread));
134 this.AddLocked(Tick,
new Idle(Tick, this.thread));
136 foreach (LinkedList<ProfilerEvent> Events
in this.timeline.Values)
137 Result.AddRange(Events);
Abstract base class for profiler events.
void Sum(NewState Event)
Sums time for a given state.
void Idle(Idle Event)
Reports thread to be idle.
void Report(List< ProfilerEvent > Result)
Reports accumulated events to a list of events.
void Start(Start Event)
Adds an event, as-is.
Accumulator(ProfilerThread Thread)
Accumulates events
void AddAsIs(ProfilerEvent Event)
Adds an event, as-is.
Class that keeps track of events and timing for one thread.