4 using System.Collections.Generic;
5 using System.Diagnostics;
7 namespace SiliconStudio.Core.Diagnostics
19 private readonly
int profilingId;
21 private bool isEnabled;
23 private Dictionary<object, object> attributes;
24 private long startTime;
25 private string beginText;
29 this.profilingId = profilingId;
30 this.profilingKey = profilingKey;
31 this.isEnabled = isEnabled;
32 this.disposeProfileDelegate = null;
42 public bool IsInitialized
46 return profilingKey != null;
54 public int ProfilingId
82 return disposeProfileDelegate;
86 disposeProfileDelegate = value;
99 isEnabled = Profiler.IsEnabled(profilingKey);
110 if (attributes == null)
115 attributes.TryGetValue(key, out result);
128 if (!isEnabled)
return;
130 if (attributes == null)
132 attributes =
new Dictionary<object, object>();
134 attributes[key] = value;
140 if (!isEnabled)
return;
143 if (disposeProfileDelegate != null)
145 disposeProfileDelegate(ref
this);
173 public void Begin(
string textFormat, params
object[] textFormatArguments)
200 public void Mark(
string textFormat, params
object[] textFormatArguments)
217 public void End(
string text)
227 public void End(
string textFormat, params
object[] textFormatArguments)
235 if (!isEnabled)
return;
237 var timeStamp = Stopwatch.GetTimestamp();
246 startTime = timeStamp;
256 var profilerEvent =
new ProfilingEvent(profilingId, profilingKey, profilingType, timeStamp, timeStamp - startTime, text, attributes);
259 Profiler.ProcessEvent(ref profilerEvent);
262 private void EmitEvent(
ProfilingMessageType profilingType,
string textFormat, params
object[] textFormatArguments)
265 if (!isEnabled)
return;
267 var timeStamp = Stopwatch.GetTimestamp();
271 var text = textFormat != null ? string.Format(textFormat, textFormatArguments) : profilingType ==
ProfilingMessageType.Mark ? null : beginText;
275 startTime = timeStamp;
285 var profilerEvent =
new ProfilingEvent(profilingId, profilingKey, profilingType, timeStamp, timeStamp - startTime, text, attributes);
288 Profiler.ProcessEvent(ref profilerEvent);
291 private TimeSpan GetElapsedTime()
293 var delta = Stopwatch.GetTimestamp() - startTime;
294 return new TimeSpan((delta * 10000000) / Stopwatch.Frequency);
A profiler state contains information of a portion of code being profiled. See remarks.
A key to identify a specific profile.
delegate void ProfilerDisposeEventDelegate(ref ProfilingState profilingState)
Delegate called when a ProfilingState is disposed (end of profiling).
void Begin()
Emits a Begin profiling event.
void SetAttribute(string key, object value)
Sets the attribute value for a specified key. See remarks.
Base implementation for ILogger.
void End()
Emits a End profiling event.
void Begin(string text)
Emits a Begin profiling event with the specified text.
ProfilingMessageType
Type of a profiling message.
void End(string text)
Emits a End profiling event with the specified text.
void Mark(string textFormat, params object[] textFormatArguments)
Emits a Mark event with the specified formatted text.
void End(string textFormat, params object[] textFormatArguments)
Emits a End profiling event with the specified formatted text.
object GetAttribute(string key)
Gets the attribute value.
void Mark()
Emits a Mark event.
void Begin(string textFormat, params object[] textFormatArguments)
Emits a Begin profiling event with the specified formatted text.
void CheckIfEnabled()
Checks if the profiling key is enabled and update this instance. See remarks.
void Mark(string text)
Emits a Mark event with the specified text.