Skip to content

Commit

Permalink
Add JIT EventCounters (#36489)
Browse files Browse the repository at this point in the history
* Add JIT counters

* Some renames

* fix build

* change return type of GetMethodsJittedCount to int

* remove ifdef

* Fix

* CR feedback

* More CR feedback

* More CR Feedback

* more code review feedback

* Fix build error and add displayunit to IL bytes jitted counter
  • Loading branch information
sywhang committed May 21, 2020
1 parent 02db9d2 commit 00c0328
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)

[MethodImpl(MethodImplOptions.InternalCall)]
private static unsafe extern TailCallTls* GetTailCallInfo(IntPtr retAddrSlot, IntPtr* retAddr);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern long GetILBytesJitted();

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int GetMethodsJittedCount();
}
// Helper class to assist with unsafe pinning of arbitrary objects.
// It's used by VM code.
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ FCFuncStart(gRuntimeHelpers)
FCFuncElement("AllocTailCallArgBuffer", TailCallHelp::AllocTailCallArgBuffer)
FCFuncElement("FreeTailCallArgBuffer", TailCallHelp::FreeTailCallArgBuffer)
FCFuncElement("GetTailCallInfo", TailCallHelp::GetTailCallInfo)
FCFuncElement("GetILBytesJitted", GetJittedBytes)
FCFuncElement("GetMethodsJittedCount", GetJittedMethodsCount)
FCFuncEnd()

FCFuncStart(gContextSynchronizationFuncs)
Expand Down
29 changes: 24 additions & 5 deletions src/coreclr/src/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ GARY_IMPL(VMHELPDEF, hlpDynamicFuncTable, DYNAMIC_CORINFO_HELP_COUNT);

#else // DACCESS_COMPILE

uint64_t g_cbILJitted = 0;
uint32_t g_cMethodsJitted = 0;

#ifndef CROSSGEN_COMPILE
FCIMPL0(INT64, GetJittedBytes)
{
FCALL_CONTRACT;

return g_cbILJitted;
}
FCIMPLEND

FCIMPL0(INT32, GetJittedMethodsCount)
{
FCALL_CONTRACT;

return g_cMethodsJitted;
}
FCIMPLEND
#endif

/*********************************************************************/

inline CORINFO_MODULE_HANDLE GetScopeHandle(MethodDesc* method)
Expand Down Expand Up @@ -12585,10 +12606,6 @@ void ThrowExceptionForJit(HRESULT res)
}

// ********************************************************************
#ifdef _DEBUG
LONG g_JitCount = 0;
#endif

//#define PERF_TRACK_METHOD_JITTIMES
#ifdef TARGET_AMD64
BOOL g_fAllowRel32 = TRUE;
Expand Down Expand Up @@ -12965,7 +12982,6 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
}

#ifdef _DEBUG
FastInterlockIncrement(&g_JitCount);
static BOOL fHeartbeat = -1;

if (fHeartbeat == -1)
Expand All @@ -12975,6 +12991,9 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
printf(".");
#endif // _DEBUG

FastInterlockExchangeAddLong((LONG64*)&g_cbILJitted, methodInfo.ILCodeSize);
FastInterlockIncrement((LONG*)&g_cMethodsJitted);

COOPERATIVE_TRANSITION_END();
return ret;
}
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/src/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1684,5 +1684,8 @@ CORJIT_FLAGS GetDebuggerCompileFlags(Module* pModule, CORJIT_FLAGS flags);

bool __stdcall TrackAllocationsEnabled();

FCDECL0(INT64, GetJittedBytes);
FCDECL0(INT32, GetJittedMethodsCount);

#endif // JITINTERFACE_H

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ internal sealed class RuntimeEventSource : EventSource
private PollingCounter? _lohSizeCounter;
private PollingCounter? _pohSizeCounter;
private PollingCounter? _assemblyCounter;
private PollingCounter? _ilBytesJittedCounter;
private PollingCounter? _methodsJittedCounter;
#endif

public static void Initialize()
Expand Down Expand Up @@ -69,7 +71,6 @@ protected override void OnEventCommand(EventCommandEventArgs command)
_completedItemsCounter ??= new IncrementingPollingCounter("threadpool-completed-items-count", this, () => ThreadPool.CompletedWorkItemCount) { DisplayName = "ThreadPool Completed Work Item Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
_allocRateCounter ??= new IncrementingPollingCounter("alloc-rate", this, () => GC.GetTotalAllocatedBytes()) { DisplayName = "Allocation Rate", DisplayUnits = "B", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
_timerCounter ??= new PollingCounter("active-timer-count", this, () => Timer.ActiveCount) { DisplayName = "Number of Active Timers" };

#if !MONO
_exceptionCounter ??= new IncrementingPollingCounter("exception-count", this, () => Exception.GetExceptionCount()) { DisplayName = "Exception Count", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
_gcTimeCounter ??= new PollingCounter("time-in-gc", this, () => GC.GetLastGCPercentTimeInGC()) { DisplayName = "% Time in GC since last GC", DisplayUnits = "%" };
Expand All @@ -79,6 +80,8 @@ protected override void OnEventCommand(EventCommandEventArgs command)
_lohSizeCounter ??= new PollingCounter("loh-size", this, () => GC.GetGenerationSize(3)) { DisplayName = "LOH Size", DisplayUnits = "B" };
_pohSizeCounter ??= new PollingCounter("poh-size", this, () => GC.GetGenerationSize(4)) { DisplayName = "POH (Pinned Object Heap) Size", DisplayUnits = "B" };
_assemblyCounter ??= new PollingCounter("assembly-count", this, () => System.Reflection.Assembly.GetAssemblyCount()) { DisplayName = "Number of Assemblies Loaded" };
_ilBytesJittedCounter ??= new PollingCounter("il-bytes-jitted", this, () => System.Runtime.CompilerServices.RuntimeHelpers.GetILBytesJitted()) { DisplayName = "IL Bytes Jitted", DisplayUnits = "B" };
_methodsJittedCounter ??= new PollingCounter("methods-jitted-count", this, () => System.Runtime.CompilerServices.RuntimeHelpers.GetMethodsJittedCount()) { DisplayName = "Number of Methods Jitted" };
#endif
}

Expand Down

0 comments on commit 00c0328

Please sign in to comment.