Skip to content
1 change: 1 addition & 0 deletions src/coreclr/inc/clrconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeCircularMB, W("EventPipeCircularMB"),
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeProcNumbers, W("EventPipeProcNumbers"), 0, "Enable/disable capturing processor numbers in EventPipe event headers")
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeOutputStreaming, W("EventPipeOutputStreaming"), 1, "Enable/disable streaming for trace file set in DOTNET_EventPipeOutputPath. Non-zero values enable streaming.")
RETAIL_CONFIG_DWORD_INFO(INTERNAL_EventPipeEnableStackwalk, W("EventPipeEnableStackwalk"), 1, "Set to 0 to disable collecting stacks for EventPipe events.")
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.")

Comment thread
pavelsavara marked this conversation as resolved.
#ifdef FEATURE_AUTO_TRACE
RETAIL_CONFIG_DWORD_INFO_EX(INTERNAL_AutoTrace_N_Tracers, W("AutoTrace_N_Tracers"), 0, "", CLRConfig::LookupOptions::ParseIntegerAsBase10)
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,23 @@ ep_rt_config_value_get_enable_stackwalk (void)
return false;
}

static
inline
uint32_t
ep_rt_config_value_get_sampling_rate (void)
{
STATIC_CONTRACT_NOTHROW;

uint64_t value;
if (RhConfig::Environment::TryGetIntegerValue("EventPipeThreadSamplingRate", &value, true))
{
EP_ASSERT(value <= UINT32_MAX);
return static_cast<uint32_t>(value);
}
Comment thread
pavelsavara marked this conversation as resolved.

return 0;
}

/*
* EventPipeSampleProfiler.
*/
Expand Down
18 changes: 13 additions & 5 deletions src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ ep_rt_provider_config_init (EventPipeProviderConfiguration *provider_config)
// This function is auto-generated from /src/scripts/genEventPipe.py
#ifdef TARGET_UNIX
extern "C" void InitProvidersAndEvents ();
#else
#else // TARGET_UNIX
extern void InitProvidersAndEvents ();
#endif
#endif // TARGET_UNIX

static
void
Expand Down Expand Up @@ -572,6 +572,15 @@ ep_rt_config_value_get_enable_stackwalk (void)
return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeEnableStackwalk) != 0;
}

static
inline
uint32_t
ep_rt_config_value_get_sampling_rate (void)
{
STATIC_CONTRACT_NOTHROW;
return CLRConfig::GetConfigValue(CLRConfig::INTERNAL_EventPipeThreadSamplingRate);
}
Comment thread
pavelsavara marked this conversation as resolved.

/*
* EventPipeSampleProfiler.
*/
Expand Down Expand Up @@ -622,13 +631,12 @@ void
ep_rt_notify_profiler_provider_created (EventPipeProvider *provider)
{
STATIC_CONTRACT_NOTHROW;

#ifndef DACCESS_COMPILE
#if !defined(DACCESS_COMPILE) && defined(PROFILING_SUPPORTED)
// Let the profiler know the provider has been created so it can register if it wants to
BEGIN_PROFILER_CALLBACK (CORProfilerTrackEventPipe ());
(&g_profControlBlock)->EventPipeProviderCreated (provider);
END_PROFILER_CALLBACK ();
#endif // DACCESS_COMPILE
#endif // !DACCESS_COMPILE && PROFILING_SUPPORTED
}

/*
Expand Down
6 changes: 5 additions & 1 deletion src/mono/browser/build/WasmApp.InTree.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
<Import Sdk="Microsoft.NET.Sdk.WebAssembly" Project="Sdk.props" Condition="'$(UsingNativeAOT)' != 'true' and '$(UsingMicrosoftNETSdkWebAssembly)' == 'true'" />
<Import Project="$(MSBuildThisFileDirectory)BrowserWasmApp.props" Condition="'$(UsingNativeAOT)' != 'true' and '$(RuntimeFlavor)' == 'Mono'" />

<!-- TODO-WASM https://github.com/dotnet/runtime/issues/120226 (CoreCLR on wasm defaults) -->
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
<UseMonoRuntime>false</UseMonoRuntime>
<!-- TODO-WASM https://github.com/dotnet/runtime/issues/120226 (CoreCLR on wasm defaults) -->
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
<UseMonoRuntime>true</UseMonoRuntime>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' or '$(IsOutputTypeLibrary)' == 'true'">
<OutputType>library</OutputType>
Expand Down
2 changes: 0 additions & 2 deletions src/mono/mono/eventpipe/ep-rt-mono-runtime-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,8 +1507,6 @@ void
ep_rt_mono_sample_profiler_enabled (EventPipeEvent *sampling_event)
{
desired_sample_interval_ms = ((double)ep_sample_profiler_get_sampling_rate ()) / 1000000.0;
EP_ASSERT (desired_sample_interval_ms >= 0.0);
EP_ASSERT (desired_sample_interval_ms < 1000.0);

current_sampling_event = sampling_event;
current_sampling_thread = ep_rt_thread_get_handle ();
Expand Down
19 changes: 19 additions & 0 deletions src/mono/mono/eventpipe/ep-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,25 @@ ep_rt_config_value_get_enable_stackwalk (void)
return value_uint32_t != 0;
}

static
inline
uint32_t
ep_rt_config_value_get_sampling_rate (void)
{
uint32_t value_uint32_t = 0;
gchar *value = g_getenv ("DOTNET_EventPipeThreadSamplingRate");
if (!value)
value = g_getenv ("COMPlus_EventPipeThreadSamplingRate");
if (value) {
gchar *endptr = NULL;
guint64 parsed = strtoull (value, &endptr, 10);
if (endptr != value && *endptr == '\0' && value [0] != '-' && parsed <= G_MAXUINT32)
value_uint32_t = (uint32_t)parsed;
}
g_free (value);
return value_uint32_t;
Comment thread
pavelsavara marked this conversation as resolved.
}

/*
* EventPipeSampleProfiler.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,22 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>
</Target>

<Target Name="_AddWasmDiagnosticPortsEnvironmentVariable">
<Target Name="_AddWasmDiagnosticPortsEnvironmentVariable" Condition="'$(EnableDiagnostics)' == 'true'">
<PropertyGroup>
<_WasmPerfInstFilter>$(WasmPerformanceInstrumentation)</_WasmPerfInstFilter>
<_WasmPerfInstInterval></_WasmPerfInstInterval>
<_WasmPerfInstDescriptor></_WasmPerfInstDescriptor>
<_WasmPerfInstInterval Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring($([MSBuild]::Add($(WasmPerformanceInstrumentation.IndexOf(',interval=')), 10))))</_WasmPerfInstInterval>
<_WasmPerfInstFilter Condition="$(WasmPerformanceInstrumentation.Contains(',interval='))">$(WasmPerformanceInstrumentation.Substring(0, $(WasmPerformanceInstrumentation.IndexOf(',interval='))))</_WasmPerfInstFilter>
<_WasmPerfInstInterval Condition="'$(_WasmPerfInstInterval)' != '' and $(_WasmPerfInstInterval.Contains(','))">$(_WasmPerfInstInterval.Substring(0, $(_WasmPerfInstInterval.IndexOf(','))))</_WasmPerfInstInterval>
<_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != '' and '$(UseMonoRuntime)' != 'false'">eventpipe,callspec=$(_WasmPerfInstFilter)</_WasmPerfInstDescriptor>
<_WasmPerfInstFilter Condition="'$(_WasmPerfInstFilter)' == 'all' and '$(UseMonoRuntime)' == 'false'">*</_WasmPerfInstFilter>
<_WasmPerfInstDescriptor Condition="'$(_WasmPerfInstFilter)' != '' and '$(UseMonoRuntime)' == 'false'">$(_WasmPerfInstFilter)</_WasmPerfInstDescriptor>
Comment thread
pavelsavara marked this conversation as resolved.
</PropertyGroup>
<ItemGroup>
<WasmEnvironmentVariable Include="DOTNET_DiagnosticPorts" Value="$(DiagnosticPorts)" Condition="'$(DiagnosticPorts)' != ''"/>
Comment thread
pavelsavara marked this conversation as resolved.
<WasmEnvironmentVariable Include="DOTNET_WasmPerformanceInstrumentation" Value="$(_WasmPerfInstDescriptor)" Condition="'$(_WasmPerfInstDescriptor)' != ''" />
<WasmEnvironmentVariable Condition="'$(_WasmPerfInstInterval)' != ''" Include="DOTNET_EventPipeThreadSamplingRate" Value="$(_WasmPerfInstInterval)" />
</ItemGroup>
Comment thread
pavelsavara marked this conversation as resolved.
</Target>

Expand Down
8 changes: 7 additions & 1 deletion src/native/eventpipe/ds-ipc-pal-websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ struct _DiagnosticsIpcStream {
};
#endif

#ifdef __cplusplus
extern "C" {
#endif
extern int ds_rt_websocket_poll (int client_socket);
extern int ds_rt_websocket_create (const char* url);
extern int ds_rt_websocket_recv (int client_socket, const uint8_t* buffer, uint32_t bytes_to_read);
extern int ds_rt_websocket_recv (int client_socket, uint8_t* buffer, uint32_t bytes_to_read);
extern int ds_rt_websocket_send (int client_socket, const uint8_t* buffer, uint32_t bytes_to_write);
extern int ds_rt_websocket_close(int client_socket);
#ifdef __cplusplus
}
#endif

#endif /* ENABLE_PERFTRACING */
#endif /* __DIAGNOSTICS_IPC_PAL_WEB_SOCKET_H__ */
5 changes: 5 additions & 0 deletions src/native/eventpipe/ep-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ inline
bool
ep_rt_config_value_get_enable_stackwalk (void);

static
inline
uint32_t
ep_rt_config_value_get_sampling_rate (void);

/*
* EventPipeSampleProfiler.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/native/eventpipe/ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,7 +1496,13 @@ ep_init (void)
#else // PERFTRACING_DISABLE_THREADS
const uint32_t default_profiler_sample_rate_in_nanoseconds = 5000000; // 5 msec.
#endif // PERFTRACING_DISABLE_THREADS
ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds);

// Allow overriding the sampling rate via DOTNET_EventPipeThreadSamplingRate (in milliseconds).
uint32_t configured_rate_ms = ep_rt_config_value_get_sampling_rate ();
if (configured_rate_ms > 0)
ep_sample_profiler_set_sampling_rate ((uint64_t)configured_rate_ms * 1000000);
Comment thread
pavelsavara marked this conversation as resolved.
Comment thread
pavelsavara marked this conversation as resolved.
else
ep_sample_profiler_set_sampling_rate (default_profiler_sample_rate_in_nanoseconds);

_ep_deferred_enable_session_ids = dn_vector_alloc_t (EventPipeSessionID);
_ep_deferred_disable_session_ids = dn_vector_alloc_t (EventPipeSessionID);
Expand Down
Loading