Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement coreclr side
  • Loading branch information
John Salem committed Jul 1, 2021
commit 8c2ef385517a7443a997df701768a33f8d197171
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeHelpers.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\TypeDependencyAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\GCSettings.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\JitInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\IEnumerable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComTypes\IEnumerator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\DynamicInterfaceCastableHelpers.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<type fullname="Internal.Runtime.InteropServices.InMemoryAssemblyLoader">
<method name="LoadInMemoryAssembly" />
</type>

<type fullname="System.Runtime.CompilerServices.RuntimeHelpers">
<method name="GetNanosecondsInJitForThread" />
</type>
</assembly>

<!-- The private Event methods are accessed by private reflection in the base EventSource class. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,6 @@ private static unsafe void DispatchTailCalls(
}
}
}

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

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int GetMethodsJittedCount();

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

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern long GetNanosecondsInJitForThread();
}
// Helper class to assist with unsafe pinning of arbitrary objects.
// It's used by VM code.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Internal.Runtime.CompilerServices;

namespace System.Runtime
{
public static partial class JitInfo
{
/// <summary>
/// Get the number of bytes of IL that have been compiled. If <paramref name="currentThread"/> is true,
/// then this value is scoped to the current thread, otherwise, this is a global value.
/// </summary>
/// <param name="currentThread">Whether the returned value should be specific to the current thread. Default: false</param>
/// <returns>The number of bytes of IL the JIT has compiled.</returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern long GetCompiledILBytes(bool currentThread = false);

/// <summary>
/// Get the number of methods that have been compiled. If <paramref name="currentThread"/> is true,
/// then this value is scoped to the current thread, otherwise, this is a global value.
/// </summary>
/// <param name="currentThread">Whether the returned value should be specific to the current thread. Default: false</param>
/// <returns>The number of methods the JIT has compiled.</returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetCompiledMethodCount(bool currentThread = false);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern long GetCompilationTimeInTicks(bool currentThread = false);
}
}
11 changes: 7 additions & 4 deletions src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ FCFuncStart(gInterlockedFuncs)
QCFuncElement("_MemoryBarrierProcessWide", COMInterlocked::MemoryBarrierProcessWide)
FCFuncEnd()

FCFuncStart(gJitInfoFuncs)
FCFuncElement("GetCompiledILBytes", GetCompiledILBytes)
FCFuncElement("GetCompiledMethodCount", GetCompiledMethodCount)
FCFuncElement("GetCompilationTimeInTicks", GetCompilationTimeInTicks)
FCFuncEnd()

FCFuncStart(gVarArgFuncs)
FCFuncElementSig(COR_CTOR_METHOD_NAME, &gsig_IM_IntPtr_PtrVoid_RetVoid, VarArgsNative::Init2)
FCFuncElementSig(COR_CTOR_METHOD_NAME, &gsig_IM_IntPtr_RetVoid, VarArgsNative::Init)
Expand Down Expand Up @@ -876,10 +882,6 @@ FCFuncStart(gRuntimeHelpers)
QCFuncElement("AllocateTypeAssociatedMemory", RuntimeTypeHandle::AllocateTypeAssociatedMemory)
FCFuncElement("AllocTailCallArgBuffer", TailCallHelp::AllocTailCallArgBuffer)
FCFuncElement("GetTailCallInfo", TailCallHelp::GetTailCallInfo)
FCFuncElement("GetILBytesJitted", GetJittedBytes)
FCFuncElement("GetMethodsJittedCount", GetJittedMethodsCount)
FCFuncElement("GetNanosecondsInJit", GetNanosecondsInJit)
FCFuncElement("GetNanosecondsInJitForThread", GetNanosecondsInJitForThread)
FCFuncEnd()

FCFuncStart(gMngdFixedArrayMarshalerFuncs)
Expand Down Expand Up @@ -1160,6 +1162,7 @@ FCClassElement("IReflect", "System.Reflection", gStdMngIReflectFuncs)
FCClassElement("InterfaceMarshaler", "System.StubHelpers", gInterfaceMarshalerFuncs)
#endif
FCClassElement("Interlocked", "System.Threading", gInterlockedFuncs)
FCClassElement("JitInfo", "System.Runtime", gJitInfoFuncs)
#if TARGET_UNIX
FCClassElement("Kernel32", "", gPalKernel32Funcs)
#endif
Expand Down
45 changes: 19 additions & 26 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,39 +104,33 @@ GARY_IMPL(VMHELPDEF, hlpDynamicFuncTable, DYNAMIC_CORINFO_HELP_COUNT);

uint64_t g_cbILJitted = 0;
uint32_t g_cMethodsJitted = 0;
thread_local int64_t g_cNanosecondsInJitForThread = 0;
int64_t g_cNanosecondsInJit = 0;
int64_t g_cQPCTicksInJit = 0;
thread_local uint64_t g_cbILJittedForThread = 0;
thread_local uint32_t g_cMethodsJittedForThread = 0;
thread_local int64_t g_cQPCTicksInJitForThread = 0;

#ifndef CROSSGEN_COMPILE
FCIMPL0(INT64, GetJittedBytes)
FCIMPL1(int64_t, GetCompiledILBytes, bool currentThread)
{
FCALL_CONTRACT;

return g_cbILJitted;
return currentThread ? g_cbILJittedForThread : g_cbILJitted;
}
FCIMPLEND

FCIMPL0(INT32, GetJittedMethodsCount)
FCIMPL1(int32_t, GetCompiledMethodCount, bool currentThread)
{
FCALL_CONTRACT;

return g_cMethodsJitted;
return currentThread ? g_cMethodsJittedForThread : g_cMethodsJitted;
}
FCIMPLEND

FCIMPL0(INT64, GetNanosecondsInJit)
FCIMPL1(int64_t, GetCompilationTimeInTicks, bool currentThread)
{
FCALL_CONTRACT;

return g_cNanosecondsInJit;
}
FCIMPLEND

FCIMPL0(INT64, GetNanosecondsInJitForThread)
{
FCALL_CONTRACT;

return g_cNanosecondsInJitForThread;
return currentThread ? g_cQPCTicksInJitForThread : g_cQPCTicksInJit;
}
FCIMPLEND
#endif
Expand Down Expand Up @@ -13035,16 +13029,11 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
PCODE ret = NULL;
int64_t jitStartTimestamp = 0;
int64_t jitEndTimestamp = 0;
int64_t jitTimeNs = 0;
static int64_t qpcFrequency = 1;
int64_t jitTimeQPCTicks = 0;
LARGE_INTEGER qpcValue;

COOPERATIVE_TRANSITION_BEGIN();

if (qpcFrequency == 1)
if (QueryPerformanceFrequency (&qpcValue))
qpcFrequency = static_cast<int64_t>(qpcValue.QuadPart) / 1000000000 /* ns per s */;

if (QueryPerformanceCounter (&qpcValue))
jitStartTimestamp = static_cast<int64_t>(qpcValue.QuadPart);

Expand Down Expand Up @@ -13412,12 +13401,16 @@ PCODE UnsafeJitFunction(PrepareCodeConfig* config,
if (QueryPerformanceCounter (&qpcValue))
jitEndTimestamp = static_cast<int64_t>(qpcValue.QuadPart);

jitTimeNs = jitEndTimestamp - jitStartTimestamp;
jitTimeNs /= qpcFrequency;
FastInterlockExchangeAddLong((LONG64*)&g_cNanosecondsInJit, jitTimeNs);
FastInterlockExchangeAddLong((LONG64*)&g_cNanosecondsInJitForThread, jitTimeNs);
jitTimeQPCTicks = jitEndTimestamp - jitStartTimestamp;

FastInterlockExchangeAddLong((LONG64*)&g_cQPCTicksInJit, jitTimeQPCTicks);
FastInterlockExchangeAddLong((LONG64*)&g_cQPCTicksInJitForThread, jitTimeQPCTicks);

FastInterlockExchangeAddLong((LONG64*)&g_cbILJitted, methodInfo.ILCodeSize);
FastInterlockExchangeAddLong((LONG64*)&g_cbILJittedForThread, methodInfo.ILCodeSize);

FastInterlockIncrement((LONG*)&g_cMethodsJitted);
FastInterlockIncrement((LONG*)&g_cMethodsJittedForThread);

COOPERATIVE_TRANSITION_END();
return ret;
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,9 @@ CORJIT_FLAGS GetDebuggerCompileFlags(Module* pModule, CORJIT_FLAGS flags);

bool __stdcall TrackAllocationsEnabled();

FCDECL0(INT64, GetJittedBytes);
FCDECL0(INT32, GetJittedMethodsCount);
FCDECL0(INT64, GetNanosecondsInJit);
FCDECL0(INT64, GetNanosecondsInJitForThread);
FCDECL1(int64_t, GetCompiledILBytes, bool currentThread);
FCDECL1(int32_t, GetCompiledMethodCount, bool currentThread);
FCDECL1(int64_t, GetCompilationTimeInTicks, bool currentThread);

#endif // JITINTERFACE_H

Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector64_1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\Vector64DebugView_1.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Intrinsics\X86\Enums.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\JitInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\AssemblyDependencyResolver.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\AssemblyLoadContext.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ 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" };
_jitTimeCounter ??= new IncrementingPollingCounter("nanoseconds-in-jit", this, () => System.Runtime.CompilerServices.RuntimeHelpers.GetNanosecondsInJit()) { DisplayName = "Nanoseconds spent in JIT", DisplayUnits = "ns", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
_ilBytesJittedCounter ??= new PollingCounter("il-bytes-jitted", this, () => System.Runtime.JitInfo.GetCompiledILBytes()) { DisplayName = "IL Bytes Jitted", DisplayUnits = "B" };
_methodsJittedCounter ??= new PollingCounter("methods-jitted-count", this, () => System.Runtime.JitInfo.GetCompiledMethodCount()) { DisplayName = "Number of Methods Jitted" };
_jitTimeCounter ??= new IncrementingPollingCounter("time-in-jit", this, () => System.Runtime.JitInfo.GetCompilationTime().TotalMilliseconds) { DisplayName = "Time spent in JIT", DisplayUnits = "ms", DisplayRateTimeScale = new TimeSpan(0, 0, 1) };
}

}
Expand Down
19 changes: 19 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Runtime/JitInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Runtime
{
public static partial class JitInfo
{
/// <summary>
/// Get the amount of time the JIT Compiler has spent compiling methods. If <paramref name="currentThread"/> is true,
/// then this value is scoped to the current thread, otherwise, this is a global value.
/// </summary>
/// <param name="currentThread">Whether the returned value should be specific to the current thread. Default: false</param>
/// <returns>The amount of time the JIT Compiler has spent compiling methods.</returns>
public static TimeSpan GetCompilationTime(bool currentThread = false)
{
return TimeSpan.FromTicks(GetCompilationTimeInTicks(currentThread));
}
}
}
2 changes: 1 addition & 1 deletion src/tests/tracing/eventcounter/runtimecounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public RuntimeCounterListener()
{ "assembly-count", false },
{ "il-bytes-jitted", false },
{ "methods-jitted-count", false },
{ "nanoseconds-in-jit", false }
{ "time-in-jit", false }
};
}
private Dictionary<string, bool> observedRuntimeCounters;
Expand Down