public void BeginRequest(HttpResponseBase httpResponseBase) { _totalStopwatch.Restart(); _moduleStopwatch.Restart(); RequestAnalysis = new RequestAnalysis { RequestId = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", "") }; _numRequests++; try { _capture = new StreamCapture(httpResponseBase.Filter); httpResponseBase.Filter = _capture; } catch (Exception ex) { SharedUtils.Log("RequestId " + RequestAnalysis.RequestId + "Exception " + ex, _logger); } _startStrings = RequestAnalysisUtils.GetStringCount(); _startMemory = GC.GetTotalMemory(true); _moduleStopwatch.Stop(); }
public void EndRequest(HttpContextBase contextBase) { _moduleStopwatch.Start(); SizeCalculations(_capture.Length); try { string response = contextBase.Response.Filter.ToString(); contextBase.Response.Clear(); RequestAnalysis.AssemblyCount = AppDomain.CurrentDomain.GetAssemblies().Length; _endStrings = RequestAnalysisUtils.GetStringCount(); RequestAnalysis.StringsCount = _endStrings - _startStrings; _endMemory = GC.GetTotalMemory(true); RequestAnalysis.MemoryUsage = _endMemory - _startMemory; _moduleStopwatch.Stop(); _totalStopwatch.Stop(); RequestAnalysis.TotalRequestTime = _totalStopwatch.Elapsed; RequestAnalysis.ModuleRequestTime = _moduleStopwatch.Elapsed; RequestAnalysisUtils.WriteToLog(RequestAnalysis, _requestsLogger); NameValueCollection appSettings = SharedUtils.GetConfigSection("appSettings"); string featureToggle_Interface = appSettings["FeatureToggle_Interface"]; bool.TryParse(featureToggle_Interface, out bool enabled); // Building the stats and writing the response will take some time but it can't be displayed to the user response = response.Replace("</body>", RequestAnalysisUtils.BuildStatsOutput(RequestAnalysis, enabled)); contextBase.Response.Write(response); } catch (Exception ex) { SharedUtils.Log("RequestId " + RequestAnalysis.RequestId + "Exception " + ex, _logger); } }