From 1a6e62456d4a1afb6cb59ebad239cf8d8a2a5f76 Mon Sep 17 00:00:00 2001 From: Michal Pavlik Date: Tue, 12 Jul 2022 09:33:30 +0200 Subject: [PATCH 1/2] Reduces allocations in case the tracing is not enabled --- src/Build/BackEnd/Client/MSBuildClient.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Build/BackEnd/Client/MSBuildClient.cs b/src/Build/BackEnd/Client/MSBuildClient.cs index bb0e2033c9a..6c8951868e2 100644 --- a/src/Build/BackEnd/Client/MSBuildClient.cs +++ b/src/Build/BackEnd/Client/MSBuildClient.cs @@ -354,11 +354,11 @@ private bool TrySendPacket(Func packetResolver) { packet = packetResolver(); WritePacket(_nodeStream, packet); - CommunicationsUtilities.Trace($"Command packet of type '{packet.Type}' sent..."); + CommunicationsUtilities.Trace("Command packet of type '{0}' sent...", packet.Type); } catch (Exception ex) { - CommunicationsUtilities.Trace($"Failed to send command packet of type '{packet?.Type.ToString() ?? "Unknown"}' to server: {0}", ex); + CommunicationsUtilities.Trace("Failed to send command packet of type '{0}' to server: {1}", ex, packet?.Type.ToString() ?? "Unknown"); _exitResult.MSBuildClientExitType = MSBuildClientExitType.ConnectionError; return false; } @@ -392,11 +392,11 @@ private bool TryLaunchServer() NodeLauncher nodeLauncher = new NodeLauncher(); CommunicationsUtilities.Trace("Starting Server..."); Process msbuildProcess = nodeLauncher.Start(_msbuildLocation, string.Join(" ", msBuildServerOptions)); - CommunicationsUtilities.Trace($"Server started with PID: {msbuildProcess?.Id}"); + CommunicationsUtilities.Trace("Server started with PID: {0}", msbuildProcess?.Id); } catch (Exception ex) { - CommunicationsUtilities.Trace($"Failed to launch the msbuild server: {ex}"); + CommunicationsUtilities.Trace("Failed to launch the msbuild server: {0}", ex); _exitResult.MSBuildClientExitType = MSBuildClientExitType.LaunchError; return false; } @@ -454,7 +454,7 @@ private void HandleCancellation() /// private void HandlePacketPumpError(MSBuildClientPacketPump packetPump) { - CommunicationsUtilities.Trace($"MSBuild client error: packet pump unexpectedly shut down: {packetPump.PacketPumpException}"); + CommunicationsUtilities.Trace("MSBuild client error: packet pump unexpectedly shut down: {0}", packetPump.PacketPumpException); throw packetPump.PacketPumpException ?? new InternalErrorException("Packet pump unexpectedly shut down"); } @@ -496,7 +496,7 @@ private void HandleServerNodeConsoleWrite(ServerNodeConsoleWrite consoleWrite) private void HandleServerNodeBuildResult(ServerNodeBuildResult response) { - CommunicationsUtilities.Trace($"Build response received: exit code {response.ExitCode}, exit type '{response.ExitType}'"); + CommunicationsUtilities.Trace("Build response received: exit code '{0}', exit type '{1}'", response.ExitCode, response.ExitType); _exitResult.MSBuildClientExitType = MSBuildClientExitType.Success; _exitResult.MSBuildAppExitTypeString = response.ExitType; _buildFinished = true; @@ -514,7 +514,7 @@ private bool TryConnectToServer(int timeout) } catch (Exception ex) { - CommunicationsUtilities.Trace($"Failed to connect to server: {ex}"); + CommunicationsUtilities.Trace("Failed to connect to server: {0}", ex); _exitResult.MSBuildClientExitType = MSBuildClientExitType.ConnectionError; return false; } From 4f95479286066444fccbb1383a2c54d0dfbd9dca Mon Sep 17 00:00:00 2001 From: Michal Pavlik Date: Tue, 12 Jul 2022 10:02:52 +0200 Subject: [PATCH 2/2] Resolving comment --- src/Build/BackEnd/Client/MSBuildClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Build/BackEnd/Client/MSBuildClient.cs b/src/Build/BackEnd/Client/MSBuildClient.cs index 6c8951868e2..27fc6f75d0e 100644 --- a/src/Build/BackEnd/Client/MSBuildClient.cs +++ b/src/Build/BackEnd/Client/MSBuildClient.cs @@ -358,7 +358,7 @@ private bool TrySendPacket(Func packetResolver) } catch (Exception ex) { - CommunicationsUtilities.Trace("Failed to send command packet of type '{0}' to server: {1}", ex, packet?.Type.ToString() ?? "Unknown"); + CommunicationsUtilities.Trace("Failed to send command packet of type '{0}' to server: {1}", packet?.Type.ToString() ?? "Unknown", ex); _exitResult.MSBuildClientExitType = MSBuildClientExitType.ConnectionError; return false; }