Updated MiniProfiler to v2

This commit is contained in:
Mark McDowall 2012-07-27 14:31:33 -07:00
parent 95cdaf25f6
commit 216bf08ced
16 changed files with 2407 additions and 123 deletions

View File

@ -1,20 +1,22 @@
using System;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Linq; using System.Linq;
using MvcMiniProfiler; using StackExchange.Profiling;
using MvcMiniProfiler.MVCHelpers; using StackExchange.Profiling.MVCHelpers;
using Microsoft.Web.Infrastructure;
using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using NzbDrone.Common;
using NzbDrone.Web.Helpers;
//using System.Data; //using System.Data;
//using System.Data.Entity; //using System.Data.Entity;
//using System.Data.Entity.Infrastructure; //using System.Data.Entity.Infrastructure;
//using StackExchange.Profiling.Data.EntityFramework;
//using StackExchange.Profiling.Data.Linq2Sql;
//using MvcMiniProfiler.Data.Linq2Sql; [assembly: WebActivator.PreApplicationStartMethod(
typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PreStart")]
[assembly: WebActivator.PreApplicationStartMethod(typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PreStart")] [assembly: WebActivator.PostApplicationStartMethod(
[assembly: WebActivator.PostApplicationStartMethod(typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PostStart")] typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PostStart")]
namespace NzbDrone.Web.App_Start namespace NzbDrone.Web.App_Start
@ -27,23 +29,37 @@ namespace NzbDrone.Web.App_Start
// Be sure to restart you ASP.NET Developement server, this code will not run until you do that. // Be sure to restart you ASP.NET Developement server, this code will not run until you do that.
//TODO: See - _MINIPROFILER UPDATED Layout.cshtml //TODO: See - _MINIPROFILER UPDATED Layout.cshtml
// For profiling to display in the UI you will have to include the line @MvcMiniProfiler.MiniProfiler.RenderIncludes() // For profiling to display in the UI you will have to include the line @StackExchange.Profiling.MiniProfiler.RenderIncludes()
// in your master layout // in your master layout
//TODO: Non SQL Server based installs can use other formatters like: new MvcMiniProfiler.SqlFormatters.InlineFormatter() //TODO: Non SQL Server based installs can use other formatters like: new StackExchange.Profiling.SqlFormatters.InlineFormatter()
MiniProfiler.Settings.SqlFormatter = new MvcMiniProfiler.SqlFormatters.SqlServerFormatter(); MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();
//TODO: To profile a standard DbConnection: //TODO: To profile a standard DbConnection:
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current); // var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
//TODO: If you are profiling EF code first try: //TODO: If you are profiling EF code first try:
// MiniProfilerEF.Initialize(); // MiniProfilerEF.Initialize();
//Make sure the MiniProfiler handles BeginRequest and EndRequest //Make sure the MiniProfiler handles BeginRequest and EndRequest
DynamicModuleUtility.RegisterModule(typeof(MiniProfilerStartupModule)); DynamicModuleUtility.RegisterModule(typeof(MiniProfilerStartupModule));
//Setup profiler for Controllers via a Global ActionFilter //Setup profiler for Controllers via a Global ActionFilter
GlobalFilters.Filters.Add(new ProfilingActionFilter()); GlobalFilters.Filters.Add(new ProfilingActionFilter());
// You can use this to check if a request is allowed to view results
//MiniProfiler.Settings.Results_Authorize = (request) =>
//{
// you should implement this if you need to restrict visibility of profiling on a per request basis
// return !DisableProfilingResults;
//};
// the list of all sessions in the store is restricted by default, you must return true to alllow it
//MiniProfiler.Settings.Results_List_Authorize = (request) =>
//{
// you may implement this if you need to restrict visibility of profiling lists on a per request basis
//return true; // all requests are kosher
//};
} }
public static void PostStart() public static void PostStart()
@ -65,33 +81,28 @@ namespace NzbDrone.Web.App_Start
{ {
context.BeginRequest += (sender, e) => context.BeginRequest += (sender, e) =>
{ {
//var request = ((HttpApplication)sender).Request; var request = ((HttpApplication)sender).Request;
//TODO: By default only local requests are profiled, optionally you can set it up //TODO: By default only local requests are profiled, optionally you can set it up
// so authenticated users are always profiled // so authenticated users are always profiled
//if (request.IsLocal) { MiniProfiler.Start(); } if (request.IsLocal) { MiniProfiler.Start(); }
if (!EnvironmentProvider.IsProduction || ProfilerHelper.Enabled())
{
var requestPath = ((HttpApplication)sender).Request.AppRelativeCurrentExecutionFilePath.ToLower();
if (!requestPath.StartsWith("~/signalr") && !requestPath.EndsWith("notification/comet"))
{
MiniProfiler.Start();
}
}
}; };
// TODO: You can control who sees the profiling information // TODO: You can control who sees the profiling information
/* /*
context.AuthenticateRequest += (sender, e) => context.AuthenticateRequest += (sender, e) =>
{ {
if (!CurrentUserIsAllowedToSeeProfiler()) if (!CurrentUserIsAllowedToSeeProfiler())
{ {
MvcMiniProfiler.MiniProfiler.Stop(discardResults: true); StackExchange.Profiling.MiniProfiler.Stop(discardResults: true);
} }
}; };
*/ */
context.EndRequest += (sender, e) => MiniProfiler.Stop(); context.EndRequest += (sender, e) =>
{
MiniProfiler.Stop();
};
} }
public void Dispose() { } public void Dispose() { }

View File

@ -1,4 +1,5 @@
using System.Web.Mvc; using System.Web.Mvc;
using StackExchange.Profiling;
namespace NzbDrone.Web.Controllers namespace NzbDrone.Web.Controllers
{ {
@ -7,7 +8,7 @@ namespace NzbDrone.Web.Controllers
[HttpGet] [HttpGet]
public JsonResult Index() public JsonResult Index()
{ {
MvcMiniProfiler.MiniProfiler.Stop(true); MiniProfiler.Stop(true);
return Json("OK", JsonRequestBehavior.AllowGet); return Json("OK", JsonRequestBehavior.AllowGet);
} }

View File

@ -1,8 +1,8 @@
using System.Threading; using System.Threading;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.UI; using System.Web.UI;
using MvcMiniProfiler;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using StackExchange.Profiling;
namespace NzbDrone.Web.Controllers namespace NzbDrone.Web.Controllers
{ {

View File

@ -4,7 +4,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using MvcMiniProfiler;
using NzbDrone.Common.Model; using NzbDrone.Common.Model;
using NzbDrone.Core; using NzbDrone.Core;
using NzbDrone.Core.Helpers; using NzbDrone.Core.Helpers;
@ -14,6 +13,7 @@ using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality; using NzbDrone.Core.Repository.Quality;
using NzbDrone.Web.Models; using NzbDrone.Web.Models;
using StackExchange.Profiling;
namespace NzbDrone.Web.Controllers namespace NzbDrone.Web.Controllers
{ {

View File

@ -68,8 +68,8 @@
<Private>True</Private> <Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath> <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference> </Reference>
<Reference Include="MvcMiniProfiler, Version=1.9.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3, processorArchitecture=MSIL"> <Reference Include="MiniProfiler">
<HintPath>..\packages\MiniProfiler.1.9\lib\net40\MvcMiniProfiler.dll</HintPath> <HintPath>..\packages\MiniProfiler.2.0.2\lib\net40\MiniProfiler.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@ -148,6 +148,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="App_Start\DataTablesMvc.cs" /> <Compile Include="App_Start\DataTablesMvc.cs" />
<Compile Include="App_Start\MiniProfiler.cs" />
<Compile Include="Controllers\SearchHistoryController.cs" /> <Compile Include="Controllers\SearchHistoryController.cs" />
<Compile Include="Helpers\Validation\RequiredIfAnyAttribute.cs" /> <Compile Include="Helpers\Validation\RequiredIfAnyAttribute.cs" />
<Compile Include="Helpers\Validation\RequiredIfAttribute.cs" /> <Compile Include="Helpers\Validation\RequiredIfAttribute.cs" />
@ -220,7 +221,6 @@
</Compile> </Compile>
<Compile Include="App_Start\EntityFramework.SqlServerCompact.cs" /> <Compile Include="App_Start\EntityFramework.SqlServerCompact.cs" />
<Compile Include="App_Start\Logging.cs" /> <Compile Include="App_Start\Logging.cs" />
<Compile Include="App_Start\MiniProfiler.cs" />
<Compile Include="Filters\JsonErrorFilter.cs" /> <Compile Include="Filters\JsonErrorFilter.cs" />
<Compile Include="Controllers\CommandController.cs" /> <Compile Include="Controllers\CommandController.cs" />
<Compile Include="Controllers\DirectoryController.cs" /> <Compile Include="Controllers\DirectoryController.cs" />
@ -549,6 +549,9 @@
<ItemGroup> <ItemGroup>
<Content Include="Views\Settings\MetadataPartial.cshtml" /> <Content Include="Views\Settings\MetadataPartial.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Views\Shared\_MINIPROFILER UPDATED Layout.cshtml" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -2,6 +2,7 @@
@{ Layout = "~/Views/Shared/_ReferenceLayout.cshtml"; } @{ Layout = "~/Views/Shared/_ReferenceLayout.cshtml"; }
@using NzbDrone.Common @using NzbDrone.Common
@using NzbDrone.Web.Helpers @using NzbDrone.Web.Helpers
@using StackExchange.Profiling
@section HeaderContent @section HeaderContent
{ {
@if (string.IsNullOrWhiteSpace(ViewBag.Title) || String.Equals(ViewBag.Title, "NzbDrone", StringComparison.InvariantCultureIgnoreCase)) @if (string.IsNullOrWhiteSpace(ViewBag.Title) || String.Equals(ViewBag.Title, "NzbDrone", StringComparison.InvariantCultureIgnoreCase))
@ -15,7 +16,7 @@
<title>@ViewBag.Title</title> <title>@ViewBag.Title</title>
@if (!EnvironmentProvider.IsProduction || ProfilerHelper.Enabled()) @if (!EnvironmentProvider.IsProduction || ProfilerHelper.Enabled())
{ {
@MvcMiniProfiler.MiniProfiler.RenderIncludes() @MiniProfiler.RenderIncludes()
} }
@Html.IncludeCss("Grid.css") @Html.IncludeCss("Grid.css")
@RenderSection("HeaderContent", required: false) @RenderSection("HeaderContent", required: false)

View File

@ -15,8 +15,8 @@
<package id="jQuery.Validation.Unobtrusive" version="2.0.20126.16343" /> <package id="jQuery.Validation.Unobtrusive" version="2.0.20126.16343" />
<package id="jQuery.vsdoc" version="1.6" /> <package id="jQuery.vsdoc" version="1.6" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
<package id="MiniProfiler" version="1.9" /> <package id="MiniProfiler" version="2.0.2" />
<package id="MiniProfiler.MVC3" version="1.9.1" /> <package id="MiniProfiler.MVC3" version="2.0.2" />
<package id="Newtonsoft.Json" version="4.5.3" /> <package id="Newtonsoft.Json" version="4.5.3" />
<package id="Ninject" version="2.2.1.4" /> <package id="Ninject" version="2.2.1.4" />
<package id="Ninject.MVC3" version="2.2.2.0" /> <package id="Ninject.MVC3" version="2.2.2.0" />

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -2,15 +2,15 @@
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Linq; using System.Linq;
using MvcMiniProfiler; using StackExchange.Profiling;
using MvcMiniProfiler.MVCHelpers; using StackExchange.Profiling.MVCHelpers;
using Microsoft.Web.Infrastructure; using Microsoft.Web.Infrastructure;
using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Microsoft.Web.Infrastructure.DynamicModuleHelper;
//using System.Data; //using System.Data;
//using System.Data.Entity; //using System.Data.Entity;
//using System.Data.Entity.Infrastructure; //using System.Data.Entity.Infrastructure;
//using MvcMiniProfiler.Data.EntityFramework; //using StackExchange.Profiling.Data.EntityFramework;
//using MvcMiniProfiler.Data.Linq2Sql; //using StackExchange.Profiling.Data.Linq2Sql;
[assembly: WebActivator.PreApplicationStartMethod( [assembly: WebActivator.PreApplicationStartMethod(
typeof($rootnamespace$.App_Start.MiniProfilerPackage), "PreStart")] typeof($rootnamespace$.App_Start.MiniProfilerPackage), "PreStart")]
@ -29,11 +29,11 @@ namespace $rootnamespace$.App_Start
// Be sure to restart you ASP.NET Developement server, this code will not run until you do that. // Be sure to restart you ASP.NET Developement server, this code will not run until you do that.
//TODO: See - _MINIPROFILER UPDATED Layout.cshtml //TODO: See - _MINIPROFILER UPDATED Layout.cshtml
// For profiling to display in the UI you will have to include the line @MvcMiniProfiler.MiniProfiler.RenderIncludes() // For profiling to display in the UI you will have to include the line @StackExchange.Profiling.MiniProfiler.RenderIncludes()
// in your master layout // in your master layout
//TODO: Non SQL Server based installs can use other formatters like: new MvcMiniProfiler.SqlFormatters.InlineFormatter() //TODO: Non SQL Server based installs can use other formatters like: new StackExchange.Profiling.SqlFormatters.InlineFormatter()
MiniProfiler.Settings.SqlFormatter = new MvcMiniProfiler.SqlFormatters.SqlServerFormatter(); MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();
//TODO: To profile a standard DbConnection: //TODO: To profile a standard DbConnection:
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current); // var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
@ -46,6 +46,20 @@ namespace $rootnamespace$.App_Start
//Setup profiler for Controllers via a Global ActionFilter //Setup profiler for Controllers via a Global ActionFilter
GlobalFilters.Filters.Add(new ProfilingActionFilter()); GlobalFilters.Filters.Add(new ProfilingActionFilter());
// You can use this to check if a request is allowed to view results
//MiniProfiler.Settings.Results_Authorize = (request) =>
//{
// you should implement this if you need to restrict visibility of profiling on a per request basis
// return !DisableProfilingResults;
//};
// the list of all sessions in the store is restricted by default, you must return true to alllow it
//MiniProfiler.Settings.Results_List_Authorize = (request) =>
//{
// you may implement this if you need to restrict visibility of profiling lists on a per request basis
//return true; // all requests are kosher
//};
} }
public static void PostStart() public static void PostStart()
@ -80,7 +94,7 @@ namespace $rootnamespace$.App_Start
{ {
if (!CurrentUserIsAllowedToSeeProfiler()) if (!CurrentUserIsAllowedToSeeProfiler())
{ {
MvcMiniProfiler.MiniProfiler.Stop(discardResults: true); StackExchange.Profiling.MiniProfiler.Stop(discardResults: true);
} }
}; };
*/ */

View File

@ -1,16 +1,20 @@
<!DOCTYPE html> @* Required so you have extention methods for client timings *@
@using StackExchange.Profiling;
<!DOCTYPE html>
<html> <html>
<head> <head>
@* optional (enable client timing framework) *@
@this.InitClientTimings()
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>@ViewBag.Title</title> <title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
@* Make sure you've added this one line to your LAYOUT or MASTER PAGE *@
@MvcMiniProfiler.MiniProfiler.RenderIncludes()
@* optional time scripts in the header *@
@this.TimeScript("Content Site.css",
@<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />)
@this.TimeScript("jQuery 1.5.1",
@<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>)
@this.TimeScript("modernizr",
@<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>)
</head> </head>
<body> <body>
@ -35,5 +39,7 @@
<footer> <footer>
</footer> </footer>
</div> </div>
@* Make sure you've added this one line to your LAYOUT or MASTER PAGE *@
@MiniProfiler.RenderIncludes()
</body> </body>
</html> </html>

Binary file not shown.