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 mono side
  • Loading branch information
John Salem committed Jul 1, 2021
commit e63ed013f0c5480be31c34d585d796cbce611738
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ internal enum RuntimeCounters
GC_LARGE_OBJECT_SIZE_BYTES,
GC_LAST_PERCENT_TIME_IN_GC,
JIT_IL_BYTES_JITTED,
JIT_METHODS_JITTED
JIT_METHODS_JITTED,
JIT_TICKS_IN_JIT
}

#if FEATURE_PERFTRACING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,6 @@ public static object GetUninitializedObject(
return GetUninitializedObjectInternal(new RuntimeTypeHandle(rt).Value);
}

internal static long GetILBytesJitted()
{
return (long)EventPipeInternal.GetRuntimeCounterValue(EventPipeInternal.RuntimeCounters.JIT_IL_BYTES_JITTED);
}

internal static int GetMethodsJittedCount()
{
return (int)EventPipeInternal.GetRuntimeCounterValue(EventPipeInternal.RuntimeCounters.JIT_METHODS_JITTED);
}

[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern unsafe void PrepareMethod(IntPtr method, IntPtr* instantiations, int ninst);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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>
public static long GetCompiledILBytes(bool currentThread = false)
{
return currentThread ? 0 : (long)EventPipeInternal.GetRuntimeCounterValue(EventPipeInternal.RuntimeCounters.JIT_IL_BYTES_JITTED);
}

/// <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>
public static int GetCompiledMethodCount(bool currentThread = false)
{
return currentThread ? 0 : (int)EventPipeInternal.GetRuntimeCounterValue(EventPipeInternal.RuntimeCounters.JIT_METHODS_JITTED);
}

public static long GetCompilationTimeInTicks(bool currentThread = false)
{
return currentThread ? 0 : (long)EventPipeInternal.GetRuntimeCounterValue(EventPipeInternal.RuntimeCounters.JIT_TICKS_IN_JIT);
}
}
}
26 changes: 23 additions & 3 deletions src/mono/mono/metadata/icall-eventpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ typedef enum {
EP_RT_COUNTERS_GC_LARGE_OBJECT_SIZE_BYTES,
EP_RT_COUNTERS_GC_LAST_PERCENT_TIME_IN_GC,
EP_RT_COUNTERS_JIT_IL_BYTES_JITTED,
EP_RT_COUNTERS_JIT_METOHODS_JITTED
EP_RT_COUNTERS_JIT_METOHODS_JITTED,
EP_RT_COUNTERS_JIT_TICKS_IN_JIT
} EventPipeRuntimeCounters;

static
Expand Down Expand Up @@ -265,9 +266,10 @@ get_il_bytes_jitted (void)
gint64 methods_compiled = 0;
gint64 cil_code_size_bytes = 0;
gint64 native_code_size_bytes = 0;
gint64 jit_time = 0;

if (mono_get_runtime_callbacks ()->get_jit_stats)
mono_get_runtime_callbacks ()->get_jit_stats (&methods_compiled, &cil_code_size_bytes, &native_code_size_bytes);
mono_get_runtime_callbacks ()->get_jit_stats (&methods_compiled, &cil_code_size_bytes, &native_code_size_bytes, &jit_time);
return cil_code_size_bytes;
}

Expand All @@ -279,9 +281,10 @@ get_methods_jitted (void)
gint64 methods_compiled = 0;
gint64 cil_code_size_bytes = 0;
gint64 native_code_size_bytes = 0;
gint64 jit_time = 0;

if (mono_get_runtime_callbacks ()->get_jit_stats)
mono_get_runtime_callbacks ()->get_jit_stats (&methods_compiled, &cil_code_size_bytes, &native_code_size_bytes);
mono_get_runtime_callbacks ()->get_jit_stats (&methods_compiled, &cil_code_size_bytes, &native_code_size_bytes, &jit_time);
return (gint32)methods_compiled;
}

Expand All @@ -296,6 +299,21 @@ get_exception_count (void)
return excepion_count;
}

static
inline
gint64
get_ticks_in_jit (void)
{
gint64 methods_compiled = 0;
gint64 cil_code_size_bytes = 0;
gint64 native_code_size_bytes = 0;
gint64 jit_time = 0;

if (mono_get_runtime_callbacks ()->get_jit_stats)
mono_get_runtime_callbacks ()->get_jit_stats (&methods_compiled, &cil_code_size_bytes, &native_code_size_bytes, &jit_time);
return jit_time;
}

guint64 ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetRuntimeCounterValue (gint32 id)
{
EventPipeRuntimeCounters counterID = (EventPipeRuntimeCounters)id;
Expand All @@ -316,6 +334,8 @@ guint64 ves_icall_System_Diagnostics_Tracing_EventPipeInternal_GetRuntimeCounter
return (guint64)get_il_bytes_jitted ();
case EP_RT_COUNTERS_JIT_METOHODS_JITTED :
return (guint64)get_methods_jitted ();
case EP_RT_COUNTERS_JIT_TICKS_IN_JIT :
return (gint64)get_ticks_in_jit ();
default:
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/object-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ typedef struct {
void (*metadata_update_init) (MonoError *error);
void (*metadata_update_published) (MonoAssemblyLoadContext *alc, uint32_t generation);
#endif
void (*get_jit_stats)(gint64 *methods_compiled, gint64 *cil_code_size_bytes, gint64 *native_code_size_bytes);
void (*get_jit_stats)(gint64 *methods_compiled, gint64 *cil_code_size_bytes, gint64 *native_code_size_bytes, gint64 *jit_time);
void (*get_exception_stats)(guint32 *exception_count);
} MonoRuntimeCallbacks;

Expand Down
3 changes: 2 additions & 1 deletion src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -1724,11 +1724,12 @@ typedef struct {
extern MonoJitStats mono_jit_stats;

static inline void
get_jit_stats (gint64 *methods_compiled, gint64 *cil_code_size_bytes, gint64 *native_code_size_bytes)
get_jit_stats (gint64 *methods_compiled, gint64 *cil_code_size_bytes, gint64 *native_code_size_bytes, gint64 *jit_time)
{
*methods_compiled = mono_jit_stats.methods_compiled;
*cil_code_size_bytes = mono_jit_stats.cil_code_size;
*native_code_size_bytes = mono_jit_stats.native_code_size;
*jit_time = mono_jit_stats.jit_time;
}

guint32
Expand Down
11 changes: 2 additions & 9 deletions src/tests/tracing/eventcounter/perthreadjittime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,16 @@ public static int Main(string[] args)
long threadOneJitTime = 0;
long threadTwoJitTime = 0;

MethodInfo getNanosecondsInJitForThread = typeof(RuntimeHelpers).GetMethod("GetNanosecondsInJitForThread", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
if (getNanosecondsInJitForThread is null)
{
foreach (var m in typeof(RuntimeHelpers).GetMembers(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy))
Console.WriteLine($"\t{m}");
}

Thread[] threads = new Thread[2];
threads[0] = new Thread(() => {
var mc = new MyClass();
int n = mc.MyMethod(100);
threadOneJitTime = (long)getNanosecondsInJitForThread.Invoke(null, null);
threadOneJitTime = System.Runtime.JitInfo.GetCompilationTime(currentThread: true);
});
threads[1] = new Thread(() => {
var moc = new MyOtherClass();
int n = moc.MyOtherMethod(10);
threadTwoJitTime = (long)getNanosecondsInJitForThread.Invoke(null, null);
threadTwoJitTime = System.Runtime.JitInfo.GetCompilationTime(currentThread: true);
});

foreach (Thread t in threads)
Expand Down