2012-07-27 21:31:33 +00:00
|
|
|
using System;
|
2011-11-24 05:50:41 +00:00
|
|
|
using System.Web;
|
|
|
|
using System.Web.Mvc;
|
|
|
|
using System.Linq;
|
2012-07-27 21:31:33 +00:00
|
|
|
using StackExchange.Profiling;
|
|
|
|
using StackExchange.Profiling.MVCHelpers;
|
|
|
|
using Microsoft.Web.Infrastructure;
|
2011-11-24 05:50:41 +00:00
|
|
|
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
|
|
|
|
//using System.Data;
|
|
|
|
//using System.Data.Entity;
|
|
|
|
//using System.Data.Entity.Infrastructure;
|
2012-07-27 21:31:33 +00:00
|
|
|
//using StackExchange.Profiling.Data.EntityFramework;
|
|
|
|
//using StackExchange.Profiling.Data.Linq2Sql;
|
2011-11-24 05:50:41 +00:00
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
[assembly: WebActivator.PreApplicationStartMethod(
|
|
|
|
typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PreStart")]
|
2011-11-24 05:50:41 +00:00
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
[assembly: WebActivator.PostApplicationStartMethod(
|
|
|
|
typeof(NzbDrone.Web.App_Start.MiniProfilerPackage), "PostStart")]
|
2011-11-24 05:50:41 +00:00
|
|
|
|
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
namespace NzbDrone.Web.App_Start
|
2011-11-24 05:50:41 +00:00
|
|
|
{
|
|
|
|
public static class MiniProfilerPackage
|
|
|
|
{
|
|
|
|
public static void PreStart()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Be sure to restart you ASP.NET Developement server, this code will not run until you do that.
|
|
|
|
|
|
|
|
//TODO: See - _MINIPROFILER UPDATED Layout.cshtml
|
2012-07-27 21:31:33 +00:00
|
|
|
// For profiling to display in the UI you will have to include the line @StackExchange.Profiling.MiniProfiler.RenderIncludes()
|
2011-11-24 05:50:41 +00:00
|
|
|
// in your master layout
|
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
//TODO: Non SQL Server based installs can use other formatters like: new StackExchange.Profiling.SqlFormatters.InlineFormatter()
|
|
|
|
MiniProfiler.Settings.SqlFormatter = new StackExchange.Profiling.SqlFormatters.SqlServerFormatter();
|
2011-11-24 05:50:41 +00:00
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
//TODO: To profile a standard DbConnection:
|
|
|
|
// var profiled = new ProfiledDbConnection(cnn, MiniProfiler.Current);
|
2011-11-24 05:50:41 +00:00
|
|
|
|
|
|
|
//TODO: If you are profiling EF code first try:
|
2012-07-27 21:31:33 +00:00
|
|
|
// MiniProfilerEF.Initialize();
|
2011-11-24 05:50:41 +00:00
|
|
|
|
|
|
|
//Make sure the MiniProfiler handles BeginRequest and EndRequest
|
|
|
|
DynamicModuleUtility.RegisterModule(typeof(MiniProfilerStartupModule));
|
|
|
|
|
|
|
|
//Setup profiler for Controllers via a Global ActionFilter
|
|
|
|
GlobalFilters.Filters.Add(new ProfilingActionFilter());
|
2012-07-27 21:31:33 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
//};
|
2011-11-24 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void PostStart()
|
|
|
|
{
|
|
|
|
// Intercept ViewEngines to profile all partial views and regular views.
|
|
|
|
// If you prefer to insert your profiling blocks manually you can comment this out
|
|
|
|
var copy = ViewEngines.Engines.ToList();
|
|
|
|
ViewEngines.Engines.Clear();
|
|
|
|
foreach (var item in copy)
|
|
|
|
{
|
|
|
|
ViewEngines.Engines.Add(new ProfilingViewEngine(item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class MiniProfilerStartupModule : IHttpModule
|
|
|
|
{
|
|
|
|
public void Init(HttpApplication context)
|
|
|
|
{
|
|
|
|
context.BeginRequest += (sender, e) =>
|
|
|
|
{
|
2012-07-27 21:31:33 +00:00
|
|
|
var request = ((HttpApplication)sender).Request;
|
2011-11-24 05:50:41 +00:00
|
|
|
//TODO: By default only local requests are profiled, optionally you can set it up
|
|
|
|
// so authenticated users are always profiled
|
2012-07-27 22:33:47 +00:00
|
|
|
//if (request.IsLocal) { MiniProfiler.Start(); }
|
|
|
|
MiniProfiler.Start();
|
2011-11-24 05:50:41 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
|
2011-11-24 05:50:41 +00:00
|
|
|
// TODO: You can control who sees the profiling information
|
|
|
|
/*
|
|
|
|
context.AuthenticateRequest += (sender, e) =>
|
|
|
|
{
|
|
|
|
if (!CurrentUserIsAllowedToSeeProfiler())
|
|
|
|
{
|
2012-07-27 21:31:33 +00:00
|
|
|
StackExchange.Profiling.MiniProfiler.Stop(discardResults: true);
|
2011-11-24 05:50:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2012-07-27 21:31:33 +00:00
|
|
|
context.EndRequest += (sender, e) =>
|
|
|
|
{
|
|
|
|
MiniProfiler.Stop();
|
|
|
|
};
|
2011-11-24 05:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose() { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|