Commit 73b375b7 authored by justcoding121's avatar justcoding121

#466 Added diagnostic timer

parent 6ab646f5
using System; using System;
using System.Collections.Generic;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using StreamExtended; using StreamExtended;
...@@ -25,6 +26,11 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -25,6 +26,11 @@ namespace Titanium.Web.Proxy.EventArguments
protected readonly IBufferPool bufferPool; protected readonly IBufferPool bufferPool;
protected readonly ExceptionHandler exceptionFunc; protected readonly ExceptionHandler exceptionFunc;
/// <summary>
/// Relative milliseconds for various events.
/// </summary>
public Dictionary<string, DateTime> TimeLine { get; set; } = new Dictionary<string, DateTime>();
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SessionEventArgsBase" /> class. /// Initializes a new instance of the <see cref="SessionEventArgsBase" /> class.
/// </summary> /// </summary>
...@@ -34,6 +40,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -34,6 +40,7 @@ namespace Titanium.Web.Proxy.EventArguments
bufferSize = server.BufferSize; bufferSize = server.BufferSize;
bufferPool = server.BufferPool; bufferPool = server.BufferPool;
exceptionFunc = server.ExceptionFunc; exceptionFunc = server.ExceptionFunc;
TimeLine.Add("Session Created", DateTime.Now);
} }
protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint, protected SessionEventArgsBase(ProxyServer server, ProxyEndPoint endPoint,
......
...@@ -165,6 +165,8 @@ namespace Titanium.Web.Proxy ...@@ -165,6 +165,8 @@ namespace Titanium.Web.Proxy
//we need this to syphon out data from connection if API user changes them. //we need this to syphon out data from connection if API user changes them.
request.SetOriginalHeaders(); request.SetOriginalHeaders();
args.TimeLine.Add("Request Received", DateTime.Now);
// If user requested interception do it // If user requested interception do it
await invokeBeforeRequest(args); await invokeBeforeRequest(args);
...@@ -213,6 +215,8 @@ namespace Titanium.Web.Proxy ...@@ -213,6 +215,8 @@ namespace Titanium.Web.Proxy
//for connection pool, retry fails until cache is exhausted. //for connection pool, retry fails until cache is exhausted.
var result = await retryPolicy<ServerConnectionException>().ExecuteAsync(async (serverConnection) => var result = await retryPolicy<ServerConnectionException>().ExecuteAsync(async (serverConnection) =>
{ {
args.TimeLine.Add("Server Connection Created", DateTime.Now);
// if upgrading to websocket then relay the request without reading the contents // if upgrading to websocket then relay the request without reading the contents
if (request.UpgradeToWebSocket) if (request.UpgradeToWebSocket)
{ {
...@@ -378,6 +382,8 @@ namespace Titanium.Web.Proxy ...@@ -378,6 +382,8 @@ namespace Titanium.Web.Proxy
{ {
await handleHttpSessionResponse(args); await handleHttpSessionResponse(args);
} }
args.TimeLine.Add("Response Sent", DateTime.Now);
} }
/// <summary> /// <summary>
......
using System.Net; using System;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Extensions; using Titanium.Web.Proxy.Extensions;
...@@ -23,6 +24,8 @@ namespace Titanium.Web.Proxy ...@@ -23,6 +24,8 @@ namespace Titanium.Web.Proxy
// read response & headers from server // read response & headers from server
await args.WebSession.ReceiveResponse(cancellationToken); await args.WebSession.ReceiveResponse(cancellationToken);
args.TimeLine.Add("Response Received", DateTime.Now);
var response = args.WebSession.Response; var response = args.WebSession.Response;
args.ReRequest = false; args.ReRequest = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment