Преглед изворни кода

Added page load and generation to footer.

pull/29/head
Teknikode пре 6 година
родитељ
комит
f594ecc734
  1. 2
      Teknik/Global.asax.cs
  2. 48
      Teknik/Modules/PerformanceMonitorModule.cs
  3. 25
      Teknik/Scripts/Common.js
  4. 1
      Teknik/Teknik.csproj
  5. 20
      Teknik/Views/Shared/_Footer.cshtml
  6. 7
      Teknik/Views/Shared/_Layout.cshtml
  7. 1
      Teknik/Web.config

2
Teknik/Global.asax.cs

@ -53,7 +53,7 @@ namespace Teknik @@ -53,7 +53,7 @@ namespace Teknik
TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0} seconds", ts.TotalSeconds);
context.Response.AddHeader("LoadTime", elapsedTime);
context.Response.AppendHeader("GenerationTime", elapsedTime);
}
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)

48
Teknik/Modules/PerformanceMonitorModule.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace Teknik.Modules
{
public class PerformanceMonitorModule : IHttpModule
{
public void Dispose() { /* Nothing to do */ }
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += delegate (object sender, EventArgs e)
{
HttpContext requestContext = ((HttpApplication)sender).Context;
Stopwatch timer = new Stopwatch();
requestContext.Items["Timer"] = timer;
timer.Start();
};
context.PostRequestHandlerExecute += delegate (object sender, EventArgs e)
{
HttpContext requestContext = ((HttpApplication)sender).Context;
Stopwatch timer = (Stopwatch)requestContext.Items["Timer"];
timer.Stop();
// Don't interfere with non-HTML responses
if (requestContext.Response.ContentType == "text/html" ||
requestContext.Response.ContentType == "application/json")
{
Uri requestUrl = requestContext.Request.Url;
double ms = (double)timer.ElapsedMilliseconds;
string result = string.Format("{0:F0}", ms);
requestContext.Response.Write(
"<script type=\"text/javascript\">" +
"var pageGenerationTime = '" + result + "';" +
"pageloadStopTimer();" +
"</script >");
}
};
}
}
}

25
Teknik/Scripts/Common.js

@ -83,4 +83,27 @@ String.prototype.hashCode = function () { @@ -83,4 +83,27 @@ String.prototype.hashCode = function () {
hash |= 0; // Convert to 32bit integer
}
return hash;
};
};
/***************************** TIMER Page Load *******************************/
var loopTime;
var startTime = new Date();
var pageGenerationTime = "0.0";
function pageloadTimerCount() {
loopTime = setTimeout("pageloadTimerCount()", 100);
}
function pageloadDoTimer() {
pageloadTimerCount();
}
function pageloadStopTimer() {
var timeMs = Math.floor((new Date() - startTime));
$('#loadtime').html(timeMs);
$('#generatetime').html(pageGenerationTime);
$('#pagetime').show();
clearTimeout(loopTime);
}

1
Teknik/Teknik.csproj

@ -194,6 +194,7 @@ @@ -194,6 +194,7 @@
<Compile Include="Areas\Blog\Models\Blog.cs" />
<Compile Include="Areas\Profile\ViewModels\LoginViewModel.cs" />
<Compile Include="Areas\Profile\ViewModels\RegisterViewModel.cs" />
<Compile Include="Modules\PerformanceMonitorModule.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="App_Start\SubdomainRoute.cs" />

20
Teknik/Views/Shared/_Footer.cshtml

@ -8,10 +8,20 @@ @@ -8,10 +8,20 @@
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;
}
<p class="text-muted">
&copy; Teknik 2013-2016 | <a href="@Url.SubRouteUrl("privacy", "Privacy.Index")">Privacy</a> | <a href="@Url.SubRouteUrl("transparency", "Transparency.Index")">Transparency</a> | <a href="@Url.SubRouteUrl("server", "Server.Index")">Server</a>
<br />
@string.Format("{0}", version)
</p>
<div class="row">
<div class="col-md-6 text-left text-muted">
&copy; Teknik 2013-2016 | <a href="@Url.SubRouteUrl("privacy", "Privacy.Index")">Privacy</a> | <a href="@Url.SubRouteUrl("transparency", "Transparency.Index")">Transparency</a> | <a href="@Url.SubRouteUrl("server", "Server.Index")">Server</a>
</div>
<div class="col-md-6 text-right text-muted">
<div id="pagetime" style="display:none;">
Gen: <b><span id="generatetime">0.0</span>ms</b> Load: <b><span id="loadtime">0.0</span>ms</b>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center text-muted">
Version: @string.Format("{0}", version)
</div>
</div>
</div>
</footer>

7
Teknik/Views/Shared/_Layout.cshtml

@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var startTime = new Date();
</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
@ -47,5 +50,9 @@ @@ -47,5 +50,9 @@
@RenderBody()
</div>
@Html.Partial("_Footer")
<script type="text/javascript">
$(document).ready(function () {pageloadDoTimer();});
</script>
</body>
</html>

1
Teknik/Web.config

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
<modules>
<remove name="FormsAuthentication" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="PerfModule" type="Teknik.Modules.PerformanceMonitorModule, Teknik"/>
</modules>
<!--<rewrite>
<rules>

Loading…
Откажи
Сачувај