From f69681f2b3efee79d073ba11d734d56c022647d5 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 2 Jan 2016 02:52:41 -0400 Subject: [PATCH] Added logging for READY packet and connection times --- src/Discord.Net/DiscordClient.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index cf8533ba2..3b4552e35 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -9,6 +9,7 @@ using Nito.AsyncEx; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net; @@ -164,6 +165,10 @@ namespace Discord await Disconnect().ConfigureAwait(false); await _taskManager.Stop().ConfigureAwait(false); _taskManager.ClearException(); + + Stopwatch stopwatch = null; + if (Config.LogLevel >= LogSeverity.Verbose) + stopwatch = Stopwatch.StartNew(); State = ConnectionState.Connecting; _disconnectedEvent.Reset(); @@ -181,6 +186,13 @@ namespace Discord await _taskManager.Start(tasks, _cancelTokenSource).ConfigureAwait(false); GatewaySocket.WaitForConnection(CancelToken); + + if (Config.LogLevel >= LogSeverity.Verbose) + { + stopwatch.Stop(); + double seconds = Math.Round(stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerSecond, 2); + Logger.Verbose($"Connection took {seconds} sec"); + } } } catch (Exception ex) @@ -471,6 +483,9 @@ namespace Discord //Global case "READY": { + Stopwatch stopwatch = null; + if (Config.LogLevel >= LogSeverity.Verbose) + stopwatch = Stopwatch.StartNew(); var data = e.Payload.ToObject(_serializer); GatewaySocket.StartHeartbeat(data.HeartbeatInterval); GatewaySocket.SessionId = data.SessionId; @@ -492,6 +507,12 @@ namespace Discord var channel = AddPrivateChannel(model.Id, model.Recipient.Id); channel.Update(model); } + if (Config.LogLevel >= LogSeverity.Verbose) + { + stopwatch.Stop(); + double seconds = Math.Round(stopwatch.ElapsedTicks / (double)TimeSpan.TicksPerSecond, 2); + Logger.Verbose($"READY took {seconds} sec"); + } } break; case "RESUMED":