diff --git a/src/OmniSharp.Stdio/Host.cs b/src/OmniSharp.Stdio/Host.cs index 1b061f3dee..3824b5beab 100644 --- a/src/OmniSharp.Stdio/Host.cs +++ b/src/OmniSharp.Stdio/Host.cs @@ -16,6 +16,7 @@ using OmniSharp.Services; using OmniSharp.Protocol; using OmniSharp.Utilities; +using System.Globalization; namespace OmniSharp.Stdio { @@ -30,6 +31,7 @@ internal class Host : IDisposable private readonly IOmniSharpEnvironment _environment; private readonly CancellationTokenSource _cancellationTokenSource; private readonly CachedStringBuilder _cachedStringBuilder; + private static readonly double TimestampToTicks = TimeSpan.TicksPerSecond / (double)Stopwatch.Frequency; public Host( TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, @@ -195,6 +197,7 @@ public void Start() private async Task HandleRequest(string json, ILogger logger) { + var startTimestamp = Stopwatch.GetTimestamp(); var request = RequestPacket.Parse(json); if (logger.IsEnabled(LogLevel.Debug)) { @@ -243,7 +246,10 @@ private async Task HandleRequest(string json, ILogger logger) LogRequest(json, logger, LogLevel.Warning); } - LogResponse(response.ToString(), logger, response.Success); + var currentTimestamp = Stopwatch.GetTimestamp(); + var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp))); + + LogResponse(response.ToString(), logger, response.Success, elapsed); } // actually write it @@ -266,12 +272,12 @@ void LogRequest(string json, ILogger logger, LogLevel logLevel) } } - void LogResponse(string json, ILogger logger, bool isSuccess) + void LogResponse(string json, ILogger logger, bool isSuccess, TimeSpan elapsed) { var builder = _cachedStringBuilder.Acquire(); try { - builder.AppendLine("************ Response ************ "); + builder.AppendLine($"************ Response ({elapsed.TotalMilliseconds.ToString("0.0000", CultureInfo.InvariantCulture)}ms) ************ "); builder.Append(JToken.Parse(json).ToString(Formatting.Indented)); if (isSuccess)