Skip to content

Commit

Permalink
Add ContentionStart_V2 and LockCreated events
Browse files Browse the repository at this point in the history
  • Loading branch information
kouvel committed Oct 19, 2022
1 parent 8b78df4 commit f3037d8
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/TraceEvent/Ctf/CtfTraceEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ private static Dictionary<string, ETWMapping> InitEventMap()
result["DotNETRuntime:ThreadPoolWorkingThreadCount"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 60, 0);
result["DotNETRuntime:ExceptionThrown"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 80, 0);
result["DotNETRuntime:ExceptionThrown_V1"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 80, 1);
result["DotNETRuntime:LockCreated"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 0, 90, 0);
result["DotNETRuntime:Contention"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 81, 0);
result["DotNETRuntime:ContentionStart_V1"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 81, 1);
result["DotNETRuntime:ContentionStart_V2"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 81, 2);
result["DotNETRuntime:StrongNameVerificationStart"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 181, 0);
result["DotNETRuntime:StrongNameVerificationStart_V1"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 181, 1);
result["DotNETRuntime:AuthenticodeVerificationStart"] = new ETWMapping(Parsers.ClrTraceEventParser.ProviderGuid, 1, 183, 0);
Expand Down
101 changes: 98 additions & 3 deletions src/TraceEvent/Parsers/ClrTraceEventParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,18 @@ public event Action<EmptyTraceData> ExceptionStop
source.UnregisterEventTemplate(value, 256, ProviderGuid);
}
}
public event Action<LockCreatedTraceData> LockCreated
{
add
{
RegisterTemplate(LockCreatedTemplate(value));
}
remove
{
source.UnregisterEventTemplate(value, 90, ProviderGuid);
source.UnregisterEventTemplate(value, 0, ContentionTaskGuid);
}
}
public event Action<ContentionStartTraceData> ContentionStart
{
add
Expand Down Expand Up @@ -2125,13 +2137,17 @@ static private ThreadPoolMinMaxThreadsTraceData ThreadPoolMinMaxThreadsTemplate(
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new ThreadPoolMinMaxThreadsTraceData(action, 59, 38, "ThreadPoolMinMaxThreads", ThreadPoolMinMaxThreadsTaskGuid, 0, "Info", ProviderGuid, ProviderName);
}
static private LockCreatedTraceData LockCreatedTemplate(Action<LockCreatedTraceData> action)
{ // action, eventid, taskid, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName
return new LockCreatedTraceData(action, 90, 8, "Contention", ContentionTaskGuid, 0, "Info", ProviderGuid, ProviderName);
}

static private volatile TraceEvent[] s_templates;
protected internal override void EnumerateTemplates(Func<string, string, EventFilterResponse> eventsToObserve, Action<TraceEvent> callback)
{
if (s_templates == null)
{
var templates = new TraceEvent[142];
var templates = new TraceEvent[143];
templates[0] = new GCStartTraceData(null, 1, 1, "GC", GCTaskGuid, 1, "Start", ProviderGuid, ProviderName);
templates[1] = new GCEndTraceData(null, 2, 1, "GC", GCTaskGuid, 2, "Stop", ProviderGuid, ProviderName);
templates[2] = new GCNoUserDataTraceData(null, 3, 1, "GC", GCTaskGuid, 132, "RestartEEStop", ProviderGuid, ProviderName);
Expand Down Expand Up @@ -2283,6 +2299,7 @@ protected internal override void EnumerateTemplates(Func<string, string, EventFi
templates[140] = YieldProcessorMeasurementTemplate(null);

templates[141] = ThreadPoolMinMaxThreadsTemplate(null);
templates[142] = LockCreatedTemplate(null);

s_templates = templates;
}
Expand Down Expand Up @@ -9104,10 +9121,78 @@ public override object PayloadValue(int index)
private event Action<ExceptionTraceData> Action;
#endregion
}
public sealed class LockCreatedTraceData : TraceEvent
{
public Address LockID { get { return (Address)GetInt64At(0); } }
public Address AssociatedObjectID { get { return (Address)GetInt64At(8); } }
public int ClrInstanceID { get { return GetInt16At(16); } }

#region Private
internal LockCreatedTraceData(Action<LockCreatedTraceData> target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName)
: base(eventID, task, taskName, taskGuid, opcode, opcodeName, providerGuid, providerName)
{
m_target = target;
}
protected internal override void Dispatch()
{
m_target(this);
}
protected internal override void Validate()
{
Debug.Assert(!(Version == 0 && EventDataLength != 18));
Debug.Assert(!(Version > 1 && EventDataLength < 18));
}
protected internal override Delegate Target
{
get { return m_target; }
set { m_target = (Action<LockCreatedTraceData>)value; }
}
public override StringBuilder ToXml(StringBuilder sb)
{
Prefix(sb);
XmlAttribHex(sb, "LockID", LockID);
XmlAttribHex(sb, "AssociatedObjectID", AssociatedObjectID);
XmlAttrib(sb, "ClrInstanceID", ClrInstanceID);
sb.Append("/>");
return sb;
}

public override string[] PayloadNames
{
get
{
if (payloadNames == null)
payloadNames = new string[] { "LockID", "AssociatedObjectID", "ClrInstanceID" };
return payloadNames;
}
}

public override object PayloadValue(int index)
{
switch (index)
{
case 0:
return LockID;
case 1:
return AssociatedObjectID;
case 2:
return ClrInstanceID;
default:
Debug.Assert(false, "Bad field index");
return null;
}
}

private event Action<LockCreatedTraceData> m_target;
#endregion
}
public sealed class ContentionStartTraceData : TraceEvent
{
public ContentionFlags ContentionFlags { get { if (Version >= 1) return (ContentionFlags)GetByteAt(0); return (ContentionFlags)0; } }
public int ClrInstanceID { get { if (Version >= 1) return GetInt16At(1); return 0; } }
public Address LockID { get { if (Version >= 2) { return (Address)GetInt64At(3); } return 0; } }
public Address AssociatedObjectID { get { if (Version >= 2) { return (Address)GetInt64At(11); } return 0; } }
public long LockOwnerThreadID { get { if (Version >= 2) { return GetInt64At(19); } return 0; } }

#region Private
internal ContentionStartTraceData(Action<ContentionStartTraceData> target, int eventID, int task, string taskName, Guid taskGuid, int opcode, string opcodeName, Guid providerGuid, string providerName)
Expand All @@ -9124,7 +9209,8 @@ protected internal override void Validate()
// Not sure if hand editing is appropriate but the start event is size 3 whereas the stop event is size 11
// and both of them come here
Debug.Assert(!(Version == 1 && EventDataLength != 3 && EventDataLength != 11));
Debug.Assert(!(Version > 1 && EventDataLength < 3));
Debug.Assert(!(Version == 2 && EventDataLength != 27));
Debug.Assert(!(Version > 2 && EventDataLength < 27));
}
protected internal override Delegate Target
{
Expand All @@ -9136,6 +9222,9 @@ public override StringBuilder ToXml(StringBuilder sb)
Prefix(sb);
XmlAttrib(sb, "ContentionFlags", ContentionFlags);
XmlAttrib(sb, "ClrInstanceID", ClrInstanceID);
XmlAttribHex(sb, "LockID", LockID);
XmlAttribHex(sb, "AssociatedObjectID", AssociatedObjectID);
XmlAttrib(sb, "LockOwnerThreadID", LockOwnerThreadID);
sb.Append("/>");
return sb;
}
Expand All @@ -9145,7 +9234,7 @@ public override string[] PayloadNames
get
{
if (payloadNames == null)
payloadNames = new string[] { "ContentionFlags", "ClrInstanceID" };
payloadNames = new string[] { "ContentionFlags", "ClrInstanceID", "LockID", "AssociatedObjectID", "LockOwnerThreadID" };
return payloadNames;
}
}
Expand All @@ -9158,6 +9247,12 @@ public override object PayloadValue(int index)
return ContentionFlags;
case 1:
return ClrInstanceID;
case 2:
return LockID;
case 3:
return AssociatedObjectID;
case 4:
return LockOwnerThreadID;
default:
Debug.Assert(false, "Bad field index");
return null;
Expand Down

0 comments on commit f3037d8

Please sign in to comment.