Skip to content

Commit 368b499

Browse files
committed
Configure DiagnosticPort creation for RecordTrace
1 parent fe00510 commit 368b499

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ public static int TestEntryPoint()
9191
traceeStartInfo.RedirectStandardOutput = true;
9292
traceeStartInfo.RedirectStandardError = true;
9393

94+
// record-trace currently only searches /tmp/ for diagnostic ports https://github.com/microsoft/one-collect/issues/183
95+
string diagnosticPortDir = "/tmp/";
96+
traceeStartInfo.Environment["TMPDIR"] = diagnosticPortDir;
97+
9498
Console.WriteLine($"Starting tracee process: {traceeStartInfo.FileName} {traceeStartInfo.Arguments}");
9599
using Process traceeProcess = Process.Start(traceeStartInfo);
96-
Console.WriteLine($"Tracee process started with PID: {traceeProcess.Id}");
100+
int traceePid = traceeProcess.Id;
101+
Console.WriteLine($"Tracee process started with PID: {traceePid}");
97102
traceeProcess.OutputDataReceived += (_, args) =>
98103
{
99104
if (!string.IsNullOrEmpty(args.Data))
@@ -119,6 +124,12 @@ public static int TestEntryPoint()
119124
}
120125
traceeProcess.WaitForExit(); // flush async output
121126

127+
// Since TMPDIR was configured, the diagnostic port was created outside of helix's default temp datadisk path.
128+
// The diagnostic port should be automatically cleaned up when the tracee shutsdown, but just in case of an
129+
// abrupt exit, ensure cleanup to avoid leaving artifacts on helix machines.
130+
// When https://github.com/microsoft/one-collect/issues/183 is fixed, this and the above TMPDIR should be removed.
131+
CleanupTraceeDiagnosticPorts(diagnosticPortDir, traceePid);
132+
122133
if (!recordTraceProcess.HasExited)
123134
{
124135
// Until record-trace supports duration, the only way to stop it is to send SIGINT (ctrl+c)
@@ -154,6 +165,23 @@ public static int TestEntryPoint()
154165
return 100;
155166
}
156167

168+
private static void CleanupTraceeDiagnosticPorts(string diagnosticPortDir, int traceePid)
169+
{
170+
try
171+
{
172+
string[] udsFiles = Directory.GetFiles(diagnosticPortDir, $"dotnet-diagnostic-{traceePid}-*-socket");
173+
foreach (string udsFile in udsFiles)
174+
{
175+
Console.WriteLine($"Deleting tracee diagnostic port UDS file: {udsFile}");
176+
File.Delete(udsFile);
177+
}
178+
}
179+
catch (Exception ex)
180+
{
181+
Console.Error.WriteLine($"Failed to cleanup tracee diagnostic ports: {ex}");
182+
}
183+
}
184+
157185
private static bool ValidateTraceeEvents(string traceFilePath)
158186
{
159187
using EventPipeEventSource source = new EventPipeEventSource(traceFilePath);

0 commit comments

Comments
 (0)