Browse Source

Added page load and generation to footer.

tags/2.0.3
Teknikode 3 years ago
parent
commit
f594ecc734

+ 1
- 1
Teknik/Global.asax.cs View File

@@ -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
- 0
Teknik/Modules/PerformanceMonitorModule.cs View File

@@ -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 >");
}
};
}
}
}

+ 24
- 1
Teknik/Scripts/Common.js View File

@@ -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
- 0
Teknik/Teknik.csproj View File

@@ -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" />

+ 15
- 5
Teknik/Views/Shared/_Footer.cshtml View File

@@ -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
- 0
Teknik/Views/Shared/_Layout.cshtml View File

@@ -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 @@
@RenderBody()
</div>
@Html.Partial("_Footer")

<script type="text/javascript">
$(document).ready(function () {pageloadDoTimer();});
</script>
</body>
</html>

+ 1
- 0
Teknik/Web.config View File

@@ -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…
Cancel
Save