Skip to content

Commit 27c4d9a

Browse files
committed
rebase
1 parent 758abdf commit 27c4d9a

52 files changed

Lines changed: 900 additions & 82 deletions

Some content is hidden

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

eng/testing/scenarios/BuildWasmAppsJobsListCoreCLR.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Wasm.Build.Tests.IcuShardingTests2
2121
Wasm.Build.Tests.IcuTests
2222
Wasm.Build.Tests.MemoryTests
2323
Wasm.Build.Tests.DownloadThenInitTests
24+
Wasm.Build.Tests.Blazor.EventPipeDiagnosticsTests

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/clrdefinitions.cmake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,18 @@ add_definitions(-DFEATURE_DEFAULT_INTERFACES)
7979
if(FEATURE_EVENT_TRACE)
8080
add_compile_definitions(FEATURE_EVENT_TRACE)
8181
add_definitions(-DFEATURE_PERFTRACING)
82-
else(FEATURE_EVENT_TRACE)
82+
elseif(FEATURE_PERFTRACING)
83+
# FEATURE_PERFTRACING without FEATURE_EVENT_TRACE (e.g. browser-wasm):
84+
# Don't add FEATURE_PERFTRACING globally — only eventpipe targets need it.
85+
# This avoids activating ETW-dependent code paths in other targets.
86+
# For cross-component builds (e.g. wasmjit) that don't include vm/eventing/,
87+
# create a dummy target so utilcode's add_dependencies doesn't fail.
88+
if(CLR_CROSS_COMPONENTS_BUILD)
89+
add_custom_target(eventing_headers)
90+
endif()
91+
else()
8392
add_custom_target(eventing_headers) # add a dummy target to avoid checking for FEATURE_EVENT_TRACE in multiple places
84-
endif(FEATURE_EVENT_TRACE)
93+
endif()
8594
if(FEATURE_GDBJIT)
8695
add_definitions(-DFEATURE_GDBJIT)
8796
endif()

src/coreclr/clrfeatures.cmake

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ if(NOT DEFINED FEATURE_EVENTSOURCE_XPLAT)
3737
endif()
3838
endif(NOT DEFINED FEATURE_EVENTSOURCE_XPLAT)
3939

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)
40+
if(NOT DEFINED FEATURE_PERFTRACING)
41+
if(FEATURE_EVENT_TRACE OR FEATURE_PERFTRACING_DISABLE_THREADS)
42+
set(FEATURE_PERFTRACING 1)
43+
endif()
44+
endif(NOT DEFINED FEATURE_PERFTRACING)
4345

4446
if(NOT DEFINED FEATURE_DBGIPC)
4547
if(CLR_CMAKE_TARGET_UNIX)

src/coreclr/inc/clrconfigvalues.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"),
609609
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers")
610610
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.")
611611
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.")
612-
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeThreadSamplingRate, W("EventPipeThreadSamplingRate"), 0, "Desired sample interval in milliseconds for EventPipe thread time sampling profiler. 0 means use the default.")
612+
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeThreadSamplingRate, W("EventPipeThreadSamplingRate"), UINT32_MAX, "Desired sample interval in milliseconds for EventPipe thread time sampling profiler. 0 means maximum frequency (sample every opportunity). Unset uses the default.")
613613

614614
//
615615
// Generational Aware Analysis

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/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ add_library_clr(clrinterpreter_objects OBJECT ${INTERPRETER_SOURCES})
4747

4848
target_include_directories(clrinterpreter_objects PRIVATE ../jitshared)
4949

50+
if (FEATURE_PERFTRACING_DISABLE_THREADS)
51+
target_compile_definitions(clrinterpreter_objects PRIVATE PERFTRACING_DISABLE_THREADS)
52+
endif()
53+
5054
if (NOT CMAKE_GENERATOR MATCHES "Visual Studio")
5155
set_target_properties(clrinterpreter_objects PROPERTIES EXCLUDE_FROM_ALL $<NOT:${FEATURE_INTERPRETER}>)
5256
endif()

src/coreclr/interpreter/compiler.cpp

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

4646
const char* CorInfoHelperToName(CorInfoHelpFunc helper);
4747

48+
#ifdef PERFTRACING_DISABLE_THREADS
49+
bool InterpCompiler::s_samplingProfilerEnabled = false;
50+
#ifdef TARGET_BROWSER
51+
bool InterpCompiler::s_browserProfilerEnabled = false;
52+
#endif
53+
#endif // PERFTRACING_DISABLE_THREADS
54+
4855
#if MEASURE_MEM_ALLOC
4956
#include <minipal/mutex.h>
5057

@@ -2194,6 +2201,16 @@ InterpCompiler::InterpCompiler(COMP_HANDLE compHnd,
21942201
DWORD jitFlagsSize = m_compHnd->getJitFlags(&m_corJitFlags, sizeof(m_corJitFlags));
21952202
assert(jitFlagsSize == sizeof(m_corJitFlags));
21962203

2204+
#ifdef PERFTRACING_DISABLE_THREADS
2205+
m_emitSamplingProfiler = s_samplingProfilerEnabled
2206+
&& InterpConfig.WasmPerformanceInstrumentation().contains(compHnd, m_methodHnd, m_classHnd, &m_methodInfo->args);
2207+
2208+
#ifdef TARGET_BROWSER
2209+
m_emitBrowserProfiler = s_browserProfilerEnabled
2210+
&& InterpConfig.WasmPerformanceInstrumentation().contains(compHnd, m_methodHnd, m_classHnd, &m_methodInfo->args);
2211+
#endif
2212+
#endif // PERFTRACING_DISABLE_THREADS
2213+
21972214
#ifdef DEBUG
21982215
m_methodName = ::PrintMethodName(compHnd, m_classHnd, m_methodHnd, &m_methodInfo->args,
21992216
/* includeAssembly */ false,
@@ -2903,7 +2920,13 @@ void InterpCompiler::EmitBranch(InterpOpcode opcode, int32_t ilOffset)
29032920

29042921
// Backwards branch, emit safepoint
29052922
if (ilOffset < 0)
2923+
{
29062924
AddIns(INTOP_SAFEPOINT);
2925+
#ifdef PERFTRACING_DISABLE_THREADS
2926+
if (m_emitSamplingProfiler)
2927+
AddIns(INTOP_PROF_SAMPLEPOINT);
2928+
#endif // PERFTRACING_DISABLE_THREADS
2929+
}
29072930

29082931
InterpBasicBlock *pTargetBB = m_ppOffsetToBB[target];
29092932
if (pTargetBB == NULL)
@@ -5729,6 +5752,13 @@ void InterpCompiler::EmitRet(CORINFO_METHOD_INFO* methodInfo)
57295752
return;
57305753
}
57315754

5755+
#ifdef PERFTRACING_DISABLE_THREADS
5756+
#ifdef TARGET_BROWSER
5757+
if (m_emitBrowserProfiler)
5758+
AddIns(INTOP_PROF_LEAVE);
5759+
#endif // TARGET_BROWSER
5760+
#endif // PERFTRACING_DISABLE_THREADS
5761+
57325762
if (m_methodInfo->args.isAsyncCall())
57335763
{
57345764
// We're doing a standard return. Set the continuation return to NULL.
@@ -8252,6 +8282,17 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
82528282
// Safepoint at each method entry. This could be done as part of a call, rather than
82538283
// adding an opcode.
82548284
AddIns(INTOP_SAFEPOINT);
8285+
#ifdef PERFTRACING_DISABLE_THREADS
8286+
if (m_emitSamplingProfiler)
8287+
AddIns(INTOP_PROF_SAMPLEPOINT);
8288+
#ifdef TARGET_BROWSER
8289+
if (m_emitBrowserProfiler)
8290+
{
8291+
AddIns(INTOP_PROF_ENTER);
8292+
m_pLastNewIns->data[0] = GetMethodDataItemIndex(m_methodHnd);
8293+
}
8294+
#endif // TARGET_BROWSER
8295+
#endif // PERFTRACING_DISABLE_THREADS
82558296

82568297
if (m_continuationArgIndex != -1)
82578298
{

src/coreclr/interpreter/compiler.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,12 @@ class InterpCompiler
627627
COMP_HANDLE m_compHnd;
628628
CORINFO_METHOD_INFO* m_methodInfo;
629629
CORJIT_FLAGS m_corJitFlags;
630+
#ifdef PERFTRACING_DISABLE_THREADS
631+
bool m_emitSamplingProfiler;
632+
#ifdef TARGET_BROWSER
633+
bool m_emitBrowserProfiler;
634+
#endif
635+
#endif // PERFTRACING_DISABLE_THREADS
630636

631637
void DeclarePointerIsClass(CORINFO_CLASS_HANDLE clsHnd)
632638
{
@@ -1112,6 +1118,13 @@ class InterpCompiler
11121118

11131119
int32_t* GetCode(int32_t *pCodeSize);
11141120

1121+
#ifdef PERFTRACING_DISABLE_THREADS
1122+
static bool s_samplingProfilerEnabled;
1123+
#ifdef TARGET_BROWSER
1124+
static bool s_browserProfilerEnabled;
1125+
#endif
1126+
#endif // PERFTRACING_DISABLE_THREADS
1127+
11151128
#if MEASURE_MEM_ALLOC
11161129
// Memory statistics for profiling.
11171130
using InterpMemStats = MemStats<InterpMemKindTraits>;

src/coreclr/interpreter/eeinterp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ 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+
#ifdef PERFTRACING_DISABLE_THREADS
37+
InterpCompiler::s_samplingProfilerEnabled = true;
38+
#ifdef TARGET_BROWSER
39+
InterpCompiler::s_browserProfilerEnabled = true;
40+
#endif
41+
#endif // PERFTRACING_DISABLE_THREADS
42+
}
43+
3244
g_interpInitialized = true;
3345
}
3446
/*****************************************************************************/

0 commit comments

Comments
 (0)