Skip to content

Commit eb14e69

Browse files
committed
Set TMPDIR for tracee for diagnosticport discovery
1 parent cd48fdf commit eb14e69

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/native/eventpipe/ds-ipc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ ipc_log_poll_handles (dn_vector_t *ipc_poll_handles)
226226
if (ipc_poll_handle.ipc) {
227227
if (!(ds_ipc_to_string (ipc_poll_handle.ipc, buffer, (uint32_t)ARRAY_SIZE (buffer)) > 0))
228228
buffer [0] = '\0';
229-
DS_LOG_DEBUG_2 ("\tSERVER IpcPollHandle[%d] = %s", connection_id, buffer);
229+
ep_char8_t uds_path [DS_IPC_MAX_TO_STRING_LEN];
230+
if (ds_ipc_get_uds_path (ipc_poll_handle.ipc, uds_path, (uint32_t)ARRAY_SIZE (uds_path)) > 0) {
231+
DS_LOG_DEBUG_1 ("ipc_log_poll_handles ipc uds path '%s'", uds_path);
232+
} else {
233+
DS_LOG_DEBUG_2 ("\tSERVER IpcPollHandle[%d] = %s", connection_id, buffer);
234+
}
230235
} else {
231236
if (!(ds_ipc_stream_to_string (ipc_poll_handle.stream, buffer, (uint32_t)ARRAY_SIZE (buffer))))
232237
buffer [0] = '\0';

src/tests/tracing/eventpipe/userevents/userevents.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ public static int TestEntryPoint()
107107
traceeStartInfo.Environment["DOTNET_LogToFile"] = "1";
108108
traceeStartInfo.Environment["DOTNET_LogFile"] = logFilePath;
109109
traceeStartInfo.Environment["DOTNET_LogWithPid"] = "1";
110+
// Currently record-trace only searches /tmp/ for diagnostic ports https://github.com/microsoft/one-collect/issues/183
111+
string diagnosticPortDir = "/tmp/";
112+
traceeStartInfo.Environment["TMPDIR"] = diagnosticPortDir;
110113

111114
Console.WriteLine($"Starting tracee process: {traceeStartInfo.FileName} {traceeStartInfo.Arguments}");
112115
using Process traceeProcess = Process.Start(traceeStartInfo);
113-
Console.WriteLine($"Tracee process started with PID: {traceeProcess.Id}");
116+
int traceePid = traceeProcess.Id;
117+
Console.WriteLine($"Tracee process started with PID: {traceePid}");
114118
traceeProcess.OutputDataReceived += (_, args) =>
115119
{
116120
if (!string.IsNullOrEmpty(args.Data))
@@ -136,6 +140,8 @@ public static int TestEntryPoint()
136140
}
137141
traceeProcess.WaitForExit(); // flush async output
138142

143+
CleanupTraceeDiagnosticPorts(diagnosticPortDir, traceePid);
144+
139145
if (!recordTraceProcess.HasExited)
140146
{
141147
// Until record-trace supports duration, the only way to stop it is to send SIGINT (ctrl+c)
@@ -171,6 +177,23 @@ public static int TestEntryPoint()
171177
return 100;
172178
}
173179

180+
private static void CleanupTraceeDiagnosticPorts(string diagnosticPortDir, int traceePid)
181+
{
182+
try
183+
{
184+
string[] udsFiles = Directory.GetFiles(diagnosticPortDir, $"dotnet-diagnostic-{traceePid}-*-socket");
185+
foreach (string udsFile in udsFiles)
186+
{
187+
Console.WriteLine($"Deleting tracee diagnostic port UDS file: {udsFile}");
188+
File.Delete(udsFile);
189+
}
190+
}
191+
catch (Exception ex)
192+
{
193+
Console.Error.WriteLine($"Failed to cleanup tracee diagnostic ports: {ex}");
194+
}
195+
}
196+
174197
private static bool ValidateTraceeEvents(string traceFilePath)
175198
{
176199
using EventPipeEventSource source = new EventPipeEventSource(traceFilePath);

src/tests/tracing/eventpipe/userevents/usereventstracee.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class UserEventsTracee
1313

1414
public static void Run()
1515
{
16+
Console.WriteLine($"TMPDIR={Environment.GetEnvironmentVariable("TMPDIR")}");
1617
long startTimestamp = Stopwatch.GetTimestamp();
1718
long targetTicks = Stopwatch.Frequency * 10; // 10s
1819

0 commit comments

Comments
 (0)