Skip to content

Commit

Permalink
Add AwareLockCreated event
Browse files Browse the repository at this point in the history
  • Loading branch information
gleocadie committed Aug 5, 2022
1 parent 5fb79fd commit d6d6398
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/coreclr/gc/env/etmdummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#define FireEtwContentionStart_V1(ContentionFlags, ClrInstanceID) 0
#define FireEtwContentionStart_V2(ContentionFlags, ClrInstanceID, LockObjectID, LockOwnerThreadID) 0
#define FireEtwContentionStop(ContentionFlags, ClrInstanceID) 0
#define FireEtwAwareLockCreated(AwareLockID, ClrInstanceID) 0
#define FireEtwCLRStackWalk(ClrInstanceID, Reserved1, Reserved2, FrameCount, Stack) 0
#define FireEtwAppDomainMemAllocated(AppDomainID, Allocated, ClrInstanceID) 0
#define FireEtwAppDomainMemSurvived(AppDomainID, Survived, ProcessSurvived, ClrInstanceID) 0
Expand Down
22 changes: 22 additions & 0 deletions src/coreclr/vm/ClrEtwAll.man
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
value="8" eventGUID="{561410f5-a138-4ab3-945e-516483cddfbc}"
message="$(string.RuntimePublisher.ContentionTaskMessage)">
<opcodes>
<opcode name="AwareLockCreated" message="$(string.RuntimePublisher.AwareLockCreatedOpcodeMessage)" symbol="CLR_AWARELOCK_CREATED_OPCODE" value="10"> </opcode>
</opcodes>
</task>

Expand Down Expand Up @@ -3109,6 +3110,18 @@
</Settings>
</UserData>
</template>

<template tid="AwareLockCreated">
<data name="AwareLockID" inType="win:Pointer" />
<data name="ClrInstanceID" inType="win:UInt16" />
<UserData>
<AwareLockCreated xmlns="myNs">
<AwareLockID> %1 </AwareLockID>
<ClrInstanceID> %2 </ClrInstanceID>
</AwareLockCreated>
</UserData>
</template>

</templates>

<events>
Expand Down Expand Up @@ -3672,6 +3685,12 @@
task="Contention"
symbol="ContentionStop_V1" message="$(string.RuntimePublisher.ContentionStop_V1EventMessage)"/>

<event value="414" version="0" level="win:Informational" template="AwareLockCreated"
keywords ="ContentionKeyword" opcode="AwareLockCreated"
task="Contention"
symbol="AwareLockCreated" message="$(string.RuntimePublisher.AwareLockEventMessage)"/>


<!-- CLR Stack events -->
<event value="82" version="0" level="win:LogAlways" template="ClrStackWalk"
keywords ="StackKeyword" opcode="CLRStackWalk"
Expand Down Expand Up @@ -8455,6 +8474,7 @@
<string id="RuntimePublisher.ContentionStart_V2EventMessage" value="ContentionFlags=%1;%nClrInstanceID=%2;%LockObjectID=%3;%LockOwnerThreadID=%4"/>
<string id="RuntimePublisher.ContentionStopEventMessage" value="ContentionFlags=%1;%nClrInstanceID=%2"/>
<string id="RuntimePublisher.ContentionStop_V1EventMessage" value="ContentionFlags=%1;%nClrInstanceID=%2;DurationNs=%3"/>
<string id="RuntimePublisher.AwareLockEventMessage" value="AwareLockID=%1;%nClrInstanceID=%2"/>
<string id="RuntimePublisher.DCStartCompleteEventMessage" value="NONE" />
<string id="RuntimePublisher.DCEndCompleteEventMessage" value="NONE" />
<string id="RuntimePublisher.MethodDCStartEventMessage" value="MethodID=%1;%nModuleID=%2;%nMethodStartAddress=%3;%nMethodSize=%4;%nMethodToken=%5;%nMethodFlags=%6" />
Expand Down Expand Up @@ -9232,6 +9252,8 @@
<string id="RundownPublisher.TieredCompilationSettingsDCStartOpcodeMessage" value="SettingsDCStart" />
<string id="RundownPublisher.ExecutionCheckpointDCEndOpcodeMessage" value="ExecutionCheckpointDCEnd" />

<string id="RundownPublisher.AwareLockCreatedOpcodeMessage" value="AwareLockCreated" />

<string id="PrivatePublisher.FailFastOpcodeMessage" value="FailFast" />

<string id="PrivatePublisher.GCDecisionOpcodeMessage" value="Decision" />
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/ClrEtwAllMeta.lst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ nostack:Contention:::ContentionStop
nomac:Contention:::ContentionStop
nostack:Contention:::ContentionStop_V1
nomac:Contention:::ContentionStop_V1
nostack:Contention:::AwareLockCreated
nomac:Contention:::AwareLockCreated

##################
# StackWalk events
Expand Down
12 changes: 8 additions & 4 deletions src/coreclr/vm/syncblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2546,15 +2546,15 @@ BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)

OBJECTREF obj = GetOwningObject();

BOOLEAN IsContentionKeywordEnabled = ETW_TRACING_CATEGORY_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context, TRACE_LEVEL_INFORMATION, CLR_CONTENTION_KEYWORD);
BOOLEAN isContentionKeywordEnabled = IsContentionKeywordEnabled();
LARGE_INTEGER startTicks = { {0} };

if (IsContentionKeywordEnabled)
if (isContentionKeywordEnabled)
{
QueryPerformanceCounter(&startTicks);

// Fire a contention start event for a managed contention
FireEtwContentionStart_V2(ETW::ContentionLog::ContentionStructs::ManagedContention, GetClrInstanceId(), OBJECTREFToObject(obj), m_HoldingThread);
FireEtwContentionStart_V2(ETW::ContentionLog::ContentionStructs::ManagedContention, GetClrInstanceId(), OBJECTREFToObject(obj), this);
}

// We cannot allow the AwareLock to be cleaned up underneath us by the GC.
Expand Down Expand Up @@ -2684,7 +2684,7 @@ BOOL AwareLock::EnterEpilogHelper(Thread* pCurThread, INT32 timeOut)
GCPROTECT_END();
DecrementTransientPrecious();

if (IsContentionKeywordEnabled)
if (isContentionKeywordEnabled)
{
LARGE_INTEGER endTicks;
QueryPerformanceCounter(&endTicks);
Expand Down Expand Up @@ -2765,6 +2765,10 @@ BOOL AwareLock::OwnedByCurrentThread()
return (GetThread() == m_HoldingThread);
}

BOOLEAN AwareLock::IsContentionKeywordEnabled() const
{
return ETW_TRACING_CATEGORY_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context, TRACE_LEVEL_INFORMATION, CLR_CONTENTION_KEYWORD);
}

// ***************************************************************************
//
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/vm/syncblk.h
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ class AwareLock
m_waiterStarvationStartTimeMs(0)
{
LIMITED_METHOD_CONTRACT;

if (IsContentionKeywordEnabled())
{
FireEtwAwareLockCreated(this, GetClrInstanceId());
}
}

~AwareLock()
Expand Down Expand Up @@ -601,6 +606,9 @@ class AwareLock
LIMITED_METHOD_CONTRACT;
return m_HoldingThread;
}

BOOLEAN IsContentionKeywordEnabled() const;

};

#ifdef FEATURE_COMINTEROP
Expand Down

0 comments on commit d6d6398

Please sign in to comment.