2using System.Collections.Generic;
3using System.Globalization;
47 private readonly List<ProfilerThread> subThreads =
new List<ProfilerThread>();
48 private readonly List<ProfilerEvent> events =
new List<ProfilerEvent>();
49 private readonly
string name;
50 private readonly
int order;
54 private long? startedAt =
null;
55 private long? stoppedAt =
null;
86 this.profiler = this.parent.
Profiler;
92 public string Name => this.name;
133 this.subThreads.Add(Result);
143 this.events.Add(
new NewState(this.profiler.ElapsedTicks, State,
this));
152 this.events.Add(
new NewSample(this.profiler.ElapsedTicks, Sample,
this));
160 this.events.Add(
new Idle(this.profiler.ElapsedTicks,
this));
185 public void Interval(DateTime From, DateTime To,
string Label)
187 this.events.Add(
new Interval(this.profiler.GetTicks(From),
this.profiler.GetTicks(To), Label,
this));
196 public void Interval(
long From,
long To,
string Label)
198 this.events.Add(
new Interval(From, To, Label,
this));
207 this.events.Add(
new Event(this.profiler.ElapsedTicks,
Name,
this));
217 this.events.Add(
new Event(this.profiler.ElapsedTicks,
Name, Label,
this));
226 this.events.Add(
new Events.Exception(
this.profiler.ElapsedTicks,
Exception,
this));
236 this.events.Add(
new Events.Exception(
this.profiler.ElapsedTicks,
Exception, Label,
this));
244 long Ticks = this.profiler.ElapsedTicks;
245 this.startedAt = Ticks;
246 this.events.Add(
new Start(Ticks,
this));
254 long Ticks = this.profiler.ElapsedTicks;
255 this.stoppedAt = Ticks;
256 this.events.Add(
new Stop(Ticks,
this));
266 Output.WriteStartElement(
"Thread");
267 Output.WriteAttributeString(
"name", this.name);
268 Output.WriteAttributeString(
"type", this.type.ToString());
270 Output.WriteStartElement(
"Events");
280 Output.WriteEndElement();
285 Output.WriteEndElement();
298 Output.Append(
"robust \"");
302 Output.Append(
"binary \"");
306 Output.Append(
"analog \"");
312 Output.Append(
"concise \"");
316 Output.Append(this.name);
317 Output.Append(
"\" as T");
318 Output.AppendLine(this.order.ToString());
342 public string Key =>
"T" + this.order.ToString();
356 if (this.startedAt.HasValue &&
this.stoppedAt.HasValue)
358 StringBuilder Output = States.Summary;
359 long Ticks = this.stoppedAt.Value - this.startedAt.Value;
360 string ElapsedStr = this.profiler.ToTimeStr(Ticks,
this, States.TimeUnit, 3);
361 KeyValuePair<double, string> Time;
363 Output.Append(this.Key);
366 Time = this.profiler.ToTime(this.startedAt.Value,
this, States.TimeUnit);
367 Output.Append(Time.Key.ToString(
"F0").Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
"."));
369 Output.Append(
" <-> @");
371 Time = this.profiler.ToTime(this.stoppedAt.Value,
this, States.TimeUnit);
372 Output.Append(Time.Key.ToString(
"F0").Replace(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator,
"."));
374 Output.Append(
" : ");
375 Output.AppendLine(ElapsedStr);
387 return this.profiler.ToTime(Ticks,
this,
TimeUnit);
398 return this.profiler.ToTimeStr(Ticks,
this,
TimeUnit, 7);
override void ExportPlantUml(PlantUmlStates States)
Exports events to PlantUML.
override void ExportPlantUmlPreparation()
Prepares the event for export to PlantUML
Contains a new sample value.
Abstract base class for profiler events.
virtual void Accumulate(Accumulator Accumulator)
Accumulates the event.
virtual void ExportXml(XmlWriter Output, ProfilerEvent Previous, TimeUnit TimeUnit)
Exports the event to XML.
void Report(List< ProfilerEvent > Result)
Reports accumulated events to a list of events.
Contains internal states used during generation of PlantUML diagram.s
Class that keeps track of events and timing.
Class that keeps track of events and timing for one thread.
ProfilerThread CreateSubThread(string Name, ProfilerThreadType Type)
Creates a new profiler thread.
void Start()
Processing starts.
long? StoppedAt
Ticks when thread was stopped.
void NewSample(double Sample)
A new sample value has been recored
void Exception(System.Exception Exception)
Exception occurred
void Low()
Sets the (binary) state to "low".
void Stop()
Processing starts.
void ExportXml(XmlWriter Output, TimeUnit TimeUnit)
Exports events to XML.
string ToTimeStr(long Ticks, TimeUnit TimeUnit)
String representation of time, corresponding to a measured number of high-frequency clock ticks.
void Event(string Name, string Label)
Event occurred
void Interval(DateTime From, DateTime To, string Label)
Records an interval in the profiler thread.
ProfilerThreadType Type
Type of profiler thread.
void ExportPlantUmlEvents(PlantUmlStates States)
Exports events to PlantUML.
void High()
Sets the (binary) state to "high".
KeyValuePair< double, string > ToTime(long Ticks, TimeUnit TimeUnit)
Time (amount, unit), corresponding to a measured number of high-frequency clock ticks.
void Event(string Name)
Event occurred
long? StartedAt
Ticks when thread was started.
ProfilerThread(string Name, int Order, ProfilerThreadType Type, Profiler Profiler)
Class that keeps track of events and timing for one thread.
Profiler Profiler
Profiler reference.
string Key
Thread key in diagrams.
ProfilerThread Parent
Parent profiler thread, if any.
void Exception(System.Exception Exception, string Label)
Exception occurred
ProfilerThread(string Name, int Order, ProfilerThreadType Type, ProfilerThread Parent)
Class that keeps track of events and timing for one thread.
string Name
Name of thread.
void ExportPlantUmlDescription(StringBuilder Output, TimeUnit TimeUnit)
Exports events to PlantUML.
void Idle()
Thread goes idle.
void NewState(string State)
Thread changes state.
void Interval(long From, long To, string Label)
Records an interval in the profiler thread.
TimeUnit
Options for presenting time in reports.
ProfilerThreadType
Type of profiler thread.