Skip to content

Commit b1cbc7b

Browse files
committed
rebase
1 parent e3e5dc3 commit b1cbc7b

42 files changed

Lines changed: 1347 additions & 49 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

coreclr-ep-profiler-design.md

Lines changed: 596 additions & 0 deletions
Large diffs are not rendered by default.

src/coreclr/clr.featuredefines.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
<!-- single thread -->
2323
<FeaturePortableTimer Condition="'$(WasmEnableThreads)' != 'true'">false</FeaturePortableTimer>
2424
<FeaturePortableThreadPool Condition="'$(WasmEnableThreads)' != 'true'">false</FeaturePortableThreadPool>
25-
<!-- until we implement ST event pipe for CoreCLR -->
26-
<FeaturePerfTracing>false</FeaturePerfTracing>
2725
<ProfilingSupportedBuild>false</ProfilingSupportedBuild>
2826
</PropertyGroup>
2927

src/coreclr/clrfeatures.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ if(CLR_CMAKE_TARGET_TIZEN_LINUX)
2424
endif()
2525

2626
if(NOT DEFINED FEATURE_EVENT_TRACE)
27-
if (NOT CLR_CMAKE_TARGET_BROWSER)
28-
# To actually disable FEATURE_EVENT_TRACE, also change clr.featuredefines.props
29-
set(FEATURE_EVENT_TRACE 1)
30-
endif()
27+
# To actually disable FEATURE_EVENT_TRACE, also change clr.featuredefines.props
28+
set(FEATURE_EVENT_TRACE 1)
3129
endif(NOT DEFINED FEATURE_EVENT_TRACE)
3230

3331
if(NOT DEFINED FEATURE_EVENTSOURCE_XPLAT)
@@ -37,9 +35,11 @@ if(NOT DEFINED FEATURE_EVENTSOURCE_XPLAT)
3735
endif()
3836
endif(NOT DEFINED FEATURE_EVENTSOURCE_XPLAT)
3937

40-
if(NOT DEFINED FEATURE_PERFTRACING AND FEATURE_EVENT_TRACE)
41-
set(FEATURE_PERFTRACING 1)
42-
endif(NOT DEFINED FEATURE_PERFTRACING AND FEATURE_EVENT_TRACE)
38+
if(NOT DEFINED FEATURE_PERFTRACING)
39+
if(FEATURE_EVENT_TRACE)
40+
set(FEATURE_PERFTRACING 1)
41+
endif()
42+
endif(NOT DEFINED FEATURE_PERFTRACING)
4343

4444
if(NOT DEFINED FEATURE_DBGIPC)
4545
if(CLR_CMAKE_TARGET_UNIX)

src/coreclr/inc/clrconfigvalues.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"),
610610
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers")
611611
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.")
612612
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.")
613+
RETAIL_CONFIG_STRING_INFO(INTERNAL_WasmPerformanceInstrumentation, W("WasmPerformanceInstrumentation"), "Configuration for WASM performance instrumentation profiler.")
614+
RETAIL_CONFIG_DWORD_INFO(INTERNAL_WasmPerformanceInstrumentationInterval, W("WasmPerformanceInstrumentationInterval"), 10, "Desired sample interval in milliseconds for WASM performance instrumentation profiler. 0 means sample every samplepoint.")
613615

614616
#ifdef FEATURE_AUTO_TRACE
615617
RETAIL_CONFIG_DWORD_INFO_EX(INTERNAL_AutoTrace_N_Tracers, W("AutoTrace_N_Tracers"), 0, "", CLRConfig::LookupOptions::ParseIntegerAsBase10)

src/coreclr/inc/eventtracebase.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,20 @@ enum EtwGCSettingFlags
121121
#define ETWFireEvent(EventName) FireEtw##EventName(GetClrInstanceId())
122122

123123
#define ETW_TRACING_INITIALIZED(RegHandle) (TRUE)
124+
#if defined(HOST_BROWSER) || defined(HOST_WASI)
125+
#define ETW_EVENT_ENABLED(Context, EventDescriptor) (EventPipeHelper::IsEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword))
126+
#define ETW_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword))
127+
#define ETW_TRACING_ENABLED(Context, EventDescriptor) (EventEnabled##EventDescriptor())
128+
#define ETW_TRACING_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword))
129+
#else // HOST_BROWSER || HOST_WASI
124130
#define ETW_EVENT_ENABLED(Context, EventDescriptor) (EventPipeHelper::IsEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword) || \
125131
(XplatEventLogger::IsKeywordEnabled(Context, EventDescriptor.Level, EventDescriptor.Keyword)))
126132
#define ETW_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword) || \
127133
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)))
128134
#define ETW_TRACING_ENABLED(Context, EventDescriptor) (EventEnabled##EventDescriptor())
129135
#define ETW_TRACING_CATEGORY_ENABLED(Context, Level, Keyword) (EventPipeHelper::IsEnabled(Context, Level, Keyword) || \
130136
(XplatEventLogger::IsKeywordEnabled(Context, Level, Keyword)))
137+
#endif // HOST_BROWSER || HOST_WASI
131138
#define ETW_PROVIDER_ENABLED(ProviderSymbol) (TRUE)
132139
#else //defined(FEATURE_PERFTRACING)
133140
#define ETW_INLINE
@@ -416,7 +423,7 @@ class XplatEventLoggerConfiguration
416423
};
417424
#endif // defined(FEATURE_PERFTRACING) || defined(FEATURE_EVENTSOURCE_XPLAT)
418425

419-
#if defined(HOST_UNIX) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT))
426+
#if defined(HOST_UNIX) && !defined(HOST_BROWSER) && !defined(HOST_WASI) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT))
420427

421428
class XplatEventLoggerController
422429
{
@@ -557,7 +564,7 @@ class XplatEventLogger
557564
};
558565

559566

560-
#endif // defined(HOST_UNIX) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT))
567+
#endif // defined(HOST_UNIX) && !defined(HOST_BROWSER) && !defined(HOST_WASI) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT))
561568

562569
#if defined(FEATURE_EVENT_TRACE)
563570

src/coreclr/interpreter/compiler.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ static const char *g_stackTypeString[] = { "I4", "I8", "R4", "R8", "O ", "VT", "
4545

4646
const char* CorInfoHelperToName(CorInfoHelpFunc helper);
4747

48+
bool InterpCompiler::s_samplingProfilerEnabled = false;
49+
bool InterpCompiler::s_browserProfilerEnabled = false;
50+
4851
#if MEASURE_MEM_ALLOC
4952
#include <minipal/mutex.h>
5053

@@ -2104,6 +2107,12 @@ InterpCompiler::InterpCompiler(COMP_HANDLE compHnd,
21042107
DWORD jitFlagsSize = m_compHnd->getJitFlags(&m_corJitFlags, sizeof(m_corJitFlags));
21052108
assert(jitFlagsSize == sizeof(m_corJitFlags));
21062109

2110+
m_emitSamplingProfiler = s_samplingProfilerEnabled
2111+
&& InterpConfig.WasmPerformanceInstrumentation().contains(compHnd, m_methodHnd, m_classHnd, &m_methodInfo->args);
2112+
2113+
m_emitBrowserProfiler = s_browserProfilerEnabled
2114+
&& InterpConfig.WasmPerformanceInstrumentation().contains(compHnd, m_methodHnd, m_classHnd, &m_methodInfo->args);
2115+
21072116
#ifdef DEBUG
21082117
m_methodName = ::PrintMethodName(compHnd, m_classHnd, m_methodHnd, &m_methodInfo->args,
21092118
/* includeAssembly */ false,
@@ -2809,7 +2818,11 @@ void InterpCompiler::EmitBranch(InterpOpcode opcode, int32_t ilOffset)
28092818

28102819
// Backwards branch, emit safepoint
28112820
if (ilOffset < 0)
2821+
{
28122822
AddIns(INTOP_SAFEPOINT);
2823+
if (m_emitSamplingProfiler)
2824+
AddIns(INTOP_PROF_SAMPLEPOINT);
2825+
}
28132826

28142827
InterpBasicBlock *pTargetBB = m_ppOffsetToBB[target];
28152828
if (pTargetBB == NULL)
@@ -5648,6 +5661,9 @@ void InterpCompiler::EmitRet(CORINFO_METHOD_INFO* methodInfo)
56485661
return;
56495662
}
56505663

5664+
if (m_emitBrowserProfiler)
5665+
AddIns(INTOP_PROF_LEAVE);
5666+
56515667
if (m_methodInfo->args.isAsyncCall())
56525668
{
56535669
// We're doing a standard return. Set the continuation return to NULL.
@@ -8107,6 +8123,13 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
81078123
// Safepoint at each method entry. This could be done as part of a call, rather than
81088124
// adding an opcode.
81098125
AddIns(INTOP_SAFEPOINT);
8126+
if (m_emitSamplingProfiler)
8127+
AddIns(INTOP_PROF_SAMPLEPOINT);
8128+
if (m_emitBrowserProfiler)
8129+
{
8130+
AddIns(INTOP_PROF_ENTER);
8131+
m_pLastNewIns->data[0] = GetMethodDataItemIndex(m_methodHnd);
8132+
}
81108133

81118134
if (m_continuationArgIndex != -1)
81128135
{

src/coreclr/interpreter/compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ class InterpCompiler
627627
COMP_HANDLE m_compHnd;
628628
CORINFO_METHOD_INFO* m_methodInfo;
629629
CORJIT_FLAGS m_corJitFlags;
630+
bool m_emitSamplingProfiler;
631+
bool m_emitBrowserProfiler;
630632

631633
void DeclarePointerIsClass(CORINFO_CLASS_HANDLE clsHnd)
632634
{
@@ -1106,6 +1108,9 @@ class InterpCompiler
11061108

11071109
int32_t* GetCode(int32_t *pCodeSize);
11081110

1111+
static bool s_samplingProfilerEnabled;
1112+
static bool s_browserProfilerEnabled;
1113+
11091114
#if MEASURE_MEM_ALLOC
11101115
// Memory statistics for profiling.
11111116
using InterpMemStats = MemStats<InterpMemKindTraits>;

src/coreclr/interpreter/eeinterp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ extern "C" INTERP_API void jitStartup(ICorJitHost* jitHost)
2929
InterpCompiler::initMemStats();
3030
#endif
3131

32+
// Enable profiling instrumentation if DOTNET_WasmPerformanceInstrumentation is set.
33+
// This must happen before any managed code is compiled so all methods get samplepoints.
34+
if (!InterpConfig.WasmPerformanceInstrumentation().isEmpty())
35+
{
36+
InterpCompiler::s_samplingProfilerEnabled = true;
37+
InterpCompiler::s_browserProfilerEnabled = true;
38+
}
39+
3240
g_interpInitialized = true;
3341
}
3442
/*****************************************************************************/

src/coreclr/interpreter/inc/intops.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ OPDEF(INTOP_LDLOCA, "ldloca", 3, 1, 0, InterpOpInt)
7575
OPDEF(INTOP_SWITCH, "switch", 0, 0, 1, InterpOpSwitch)
7676

7777
OPDEF(INTOP_SAFEPOINT, "safepoint", 1, 0, 0, InterpOpNoArgs)
78+
OPDEF(INTOP_PROF_SAMPLEPOINT, "prof.samplepoint", 1, 0, 0, InterpOpNoArgs)
79+
OPDEF(INTOP_PROF_ENTER, "prof.enter", 2, 0, 0, InterpOpMethodHandle)
80+
OPDEF(INTOP_PROF_LEAVE, "prof.leave", 1, 0, 0, InterpOpNoArgs)
7881
OPDEF(INTOP_BR, "br", 2, 0, 0, InterpOpBranch)
7982

8083
OPDEF(INTOP_BRFALSE_I4, "brfalse.i4", 3, 0, 1, InterpOpBranch)

src/coreclr/interpreter/interpconfigvalues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ RELEASE_CONFIG_INTEGER(InterpMode, "InterpMode", 0); // Interpreter mode, one of
3636
// 3: use interpreter for everything, the full interpreter-only mode, no fallbacks to R2R or JIT whatsoever. Implies DOTNET_ReadyToRun=0, DOTNET_EnableHWIntrinsic=0
3737

3838
RELEASE_CONFIG_INTEGER(DisplayMemStats, "JitMemStats", 0); // Display interpreter memory usage statistics (0=off, 1=summary, 2=detailed per-method)
39+
RELEASE_CONFIG_METHODSET(WasmPerformanceInstrumentation, "WasmPerformanceInstrumentation") // Method filter for WASM performance instrumentation profiler. Uses standard MethodSet pattern format.
3940

4041
#undef CONFIG_STRING
4142
#undef RELEASE_CONFIG_STRING

0 commit comments

Comments
 (0)