@@ -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 ) ;
0 commit comments