Skip to content

Add support for DOTNET_DiagnosticPortDefaultPrefix #110503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/coreclr/inc/clrconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_GCGenAnalysisDump, W("GCGenAnalysisDump"), 0,
//
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_DOTNET_DefaultDiagnosticPortSuspend, W("DefaultDiagnosticPortSuspend"), 0, "This sets the deafult diagnostic port to suspend causing the runtime to pause during startup before major subsystems are started. Resume using the Diagnostics IPC ResumeStartup command on the default diagnostic port.");
RETAIL_CONFIG_STRING_INFO(EXTERNAL_DOTNET_DiagnosticPorts, W("DiagnosticPorts"), "A semicolon delimited list of additional Diagnostic Ports, where a Diagnostic Port is a NamedPipe path without '\\\\.\\pipe\\' on Windows or the full path of Unix Domain Socket on Linux/Unix followed by optional tags, e.g., '<path>,connect,nosuspend;<path>'");
RETAIL_CONFIG_STRING_INFO(EXTERNAL_DOTNET_DiagnosticPortDefaultPrefix, W("DiagnosticPortDefaultPrefix"), "The default prefix for the diagnostic port name. The default is `dotnet-diagnostic`.");

//
// LTTng
Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ ds_rt_config_value_get_default_port_suspend (void)
return 0;
}

static
inline
ep_char8_t *
ds_rt_config_value_get_port_default_prefix (void)
{
STATIC_CONTRACT_NOTHROW;

char* value;
if (RhConfig::Environment::TryGetStringValue("DiagnosticPortDefaultPrefix", &value))
return (ep_char8_t*)value;

return nullptr;
}

/*
* DiagnosticsDump.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/vm/eventing/eventpipe/ds-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ ds_rt_config_value_get_default_port_suspend (void)
return static_cast<uint32_t>(CLRConfig::GetConfigValue (CLRConfig::EXTERNAL_DOTNET_DefaultDiagnosticPortSuspend));
}


static
inline
ep_char8_t *
ds_rt_config_value_get_port_default_prefix (void)
{
STATIC_CONTRACT_NOTHROW;

CLRConfigStringHolder value(CLRConfig::GetConfigValue (CLRConfig::EXTERNAL_DOTNET_DiagnosticPortDefaultPrefix));
return ep_rt_utf16_to_utf8_string (reinterpret_cast<ep_char16_t *>(value.GetValue ()));
}

/*
* DiagnosticsDump.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/mono/mono/eventpipe/ds-rt-mono.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ ds_rt_config_value_get_default_port_suspend (void)
return value_uint32_t;
}

static
inline
ep_char8_t *
ds_rt_config_value_get_port_default_prefix (void)
{
return g_getenv ("DOTNET_DiagnosticPortDefaultPrefix");
}

/*
* DiagnosticsDump.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/native/eventpipe/ds-ipc-pal-namedpipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ DiagnosticsIpc *
ds_ipc_alloc (
const ep_char8_t *ipc_name,
DiagnosticsIpcConnectionMode mode,
ds_ipc_error_callback_func callback)
ds_ipc_error_callback_func callback,
const ep_char8_t *ipc_default_prefix)

{
int32_t characters_written = -1;

Expand All @@ -144,7 +146,8 @@ ds_ipc_alloc (
characters_written = sprintf_s (
(char *)&instance->pipe_name,
(size_t)DS_IPC_WIN32_MAX_NAMED_PIPE_LEN,
(const char *)"\\\\.\\pipe\\dotnet-diagnostic-%d",
(const char *)"\\\\.\\pipe\\%s-%d",
ipc_default_prefix,
GetCurrentProcessId ());
}

Expand Down
29 changes: 18 additions & 11 deletions src/native/eventpipe/ds-ipc-pal-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ static
bool
ipc_transport_get_default_name (
ep_char8_t *name,
int32_t name_len);
int32_t name_len,
const ep_char8_t *ipc_default_prefix);

static
bool
Expand All @@ -172,7 +173,8 @@ DiagnosticsIpc *
ipc_alloc_uds_address (
DiagnosticsIpc *ipc,
DiagnosticsIpcConnectionMode mode,
const ep_char8_t *ipc_name);
const ep_char8_t *ipc_name,
const ep_char8_t *ipc_default_prefix);

static
DiagnosticsIpc *
Expand Down Expand Up @@ -694,14 +696,15 @@ inline
bool
ipc_transport_get_default_name (
ep_char8_t *name,
int32_t name_len)
int32_t name_len,
const ep_char8_t *ipc_default_prefix)
{
#ifdef DS_IPC_PAL_AF_UNIX
#ifndef EP_NO_RT_DEPENDENCY
return ds_rt_transport_get_default_name (
name,
name_len,
"dotnet-diagnostic",
ipc_default_prefix,
ep_rt_current_process_get_id (),
NULL,
"socket");
Expand All @@ -711,7 +714,7 @@ ipc_transport_get_default_name (
PAL_GetTransportName(
name_len,
name,
"dotnet-diagnostic",
ipc_default_prefix,
pd.m_Pid,
pd.m_ApplicationGroupId,
"socket");
Expand Down Expand Up @@ -788,7 +791,8 @@ DiagnosticsIpc *
ipc_alloc_uds_address (
DiagnosticsIpc *ipc,
DiagnosticsIpcConnectionMode mode,
const ep_char8_t *ipc_name)
const ep_char8_t *ipc_name,
const ep_char8_t *ipc_default_prefix)
{
#ifdef DS_IPC_PAL_AF_UNIX
EP_ASSERT (ipc != NULL);
Expand All @@ -810,7 +814,8 @@ ipc_alloc_uds_address (
// generate the default socket name
ipc_transport_get_default_name (
server_address->sun_path,
sizeof (server_address->sun_path));
sizeof (server_address->sun_path),
ipc_default_prefix);
}

ipc->server_address = (ds_ipc_socket_address_t *)server_address;
Expand Down Expand Up @@ -942,10 +947,11 @@ DiagnosticsIpc *
ipc_alloc_address (
DiagnosticsIpc *ipc,
DiagnosticsIpcConnectionMode mode,
const ep_char8_t *ipc_name)
const ep_char8_t *ipc_name,
const ep_char8_t *ipc_default_prefix)
{
#ifdef DS_IPC_PAL_AF_UNIX
return ipc_alloc_uds_address (ipc, mode, ipc_name);
return ipc_alloc_uds_address (ipc, mode, ipc_name, ipc_default_prefix);
#elif defined(DS_IPC_PAL_AF_INET) || defined(DS_IPC_PAL_AF_INET6)
return ipc_alloc_tcp_address (ipc, mode, ipc_name);
#else
Expand Down Expand Up @@ -1027,7 +1033,8 @@ DiagnosticsIpc *
ds_ipc_alloc (
const ep_char8_t *ipc_name,
DiagnosticsIpcConnectionMode mode,
ds_ipc_error_callback_func callback)
ds_ipc_error_callback_func callback,
const ep_char8_t *ipc_default_prefix)
{
DiagnosticsIpc *instance = NULL;

Expand All @@ -1039,7 +1046,7 @@ ds_ipc_alloc (
instance->is_closed = false;
instance->is_listening = false;

ep_raise_error_if_nok (ipc_alloc_address (instance, mode, ipc_name) != NULL);
ep_raise_error_if_nok (ipc_alloc_address (instance, mode, ipc_name, ipc_default_prefix) != NULL);

if (mode == DS_IPC_CONNECTION_MODE_LISTEN)
ep_raise_error_if_nok (ipc_init_listener (instance, callback) == true);
Expand Down
3 changes: 2 additions & 1 deletion src/native/eventpipe/ds-ipc-pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ DiagnosticsIpc *
ds_ipc_alloc (
const ep_char8_t *ipc_name,
DiagnosticsIpcConnectionMode mode,
ds_ipc_error_callback_func callback);
ds_ipc_error_callback_func callback,
const ep_char8_t *ipc_default_prefix);

void
ds_ipc_free (DiagnosticsIpc *ipc);
Expand Down
10 changes: 8 additions & 2 deletions src/native/eventpipe/ds-ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ ipc_stream_factory_build_and_add_port (

if (builder->type == DS_PORT_TYPE_LISTEN) {
#ifndef DS_IPC_DISABLE_LISTEN_PORTS
ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_LISTEN, callback);
ep_char8_t* ipc_default_prefix = ds_rt_config_value_get_port_default_prefix();
ipc_default_prefix = ipc_default_prefix != NULL ? ipc_default_prefix : (ep_char8_t*)"dotnet-diagnostic";

ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_LISTEN, callback, ipc_default_prefix);
ep_raise_error_if_nok (ipc != NULL);
ep_raise_error_if_nok (ds_ipc_listen (ipc, callback));
ep_raise_error_if_nok (dn_vector_ptr_push_back (_ds_port_array, (DiagnosticsPort *)ds_listen_port_alloc (ipc, builder)));
Expand All @@ -185,7 +188,10 @@ ipc_stream_factory_build_and_add_port (
#endif
} else if (builder->type == DS_PORT_TYPE_CONNECT) {
#ifndef DS_IPC_DISABLE_CONNECT_PORTS
ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_CONNECT, callback);
ep_char8_t* ipc_default_prefix = ds_rt_config_value_get_port_default_prefix();
ipc_default_prefix = ipc_default_prefix != NULL ? ipc_default_prefix : (ep_char8_t*)"dotnet-diagnostic";

ipc = ds_ipc_alloc (builder->path, DS_IPC_CONNECTION_MODE_CONNECT, callback, ipc_default_prefix);
ep_raise_error_if_nok (ipc != NULL);
ep_raise_error_if_nok (dn_vector_ptr_push_back (_ds_port_array, (DiagnosticsPort *)ds_connect_port_alloc (ipc, builder)));
#else
Expand Down
4 changes: 4 additions & 0 deletions src/native/eventpipe/ds-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ static
uint32_t
ds_rt_config_value_get_default_port_suspend (void);

static
ep_char8_t *
ds_rt_config_value_get_port_default_prefix (void);

/*
* DiagnosticsDump.
*/
Expand Down
Loading