本文整理汇总了C#中StackExchange.Profiling.MiniProfiler类的典型用法代码示例。如果您正苦于以下问题:C# MiniProfiler类的具体用法?C# MiniProfiler怎么用?C# MiniProfiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MiniProfiler类属于StackExchange.Profiling命名空间,在下文中一共展示了MiniProfiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: EnsureName
private static void EnsureName(MiniProfiler profiler, HttpRequest request)
{
// also set the profiler name to Controller/Action or /url
if (string.IsNullOrWhiteSpace(profiler.Name))
{
var rc = request.RequestContext;
RouteValueDictionary values;
if (rc != null && rc.RouteData != null && (values = rc.RouteData.Values).Count > 0)
{
var controller = values["Controller"];
var action = values["Action"];
if (controller != null && action != null)
profiler.Name = controller.ToString() + "/" + action.ToString();
}
if (string.IsNullOrWhiteSpace(profiler.Name))
{
profiler.Name = request.Url.AbsolutePath ?? string.Empty;
if (profiler.Name.Length > 50)
profiler.Name = profiler.Name.Remove(50);
}
}
}
开发者ID:krk,项目名称:MiniProfiler,代码行数:25,代码来源:WebRequestProfilerProvider.cs
示例2: Write
public void Write(MiniProfiler miniProfiler)
{
if (miniProfiler != null && miniProfiler.DurationMilliseconds > 50)
{
StringBuilder sb = new StringBuilder();
// Write step times
if (miniProfiler.Root.HasChildren)
{
var children = miniProfiler.Root.Children;
foreach (var child in children)
{
sb.AppendLine(child.Name + " " + child.DurationMilliseconds);
}
}
// Write overall request time
sb.AppendLine(string.Format("{0} {1}\n",
miniProfiler.DurationMilliseconds,
miniProfiler.Root));
// Write to file
try
{
File.AppendAllText(@"c:\temp\out.txt", sb.ToString());
}
catch (Exception)
{
}
}
}
开发者ID:PublicHealthEngland,项目名称:fingertips-open,代码行数:31,代码来源:MiniProfilerWriter.cs
示例3: HomeController
public HomeController()
{
DbInitializer.Initialize();
profiler = MiniProfiler.Current;
EasternStandardTimeId = "Eastern Standard Time";
ESTTimeZone = TimeZoneInfo.FindSystemTimeZoneById(EasternStandardTimeId);
}
开发者ID:mhsohail,项目名称:eQuiz,代码行数:7,代码来源:HomeController.cs
示例4: Start
public override MiniProfiler Start(ProfileLevel level, string sessionName = null)
{
var context = HttpContext.Current;
if (context == null || context.Request.AppRelativeCurrentExecutionFilePath == null) return null;
var url = context.Request.Url;
var path = context.Request.AppRelativeCurrentExecutionFilePath.Substring(1).ToUpperInvariant();
// don't profile /content or /scripts, either - happens in web.dev
foreach (var ignored in MiniProfiler.Settings.IgnoredPaths ?? new string[0])
{
if (path.Contains((ignored ?? string.Empty).ToUpperInvariant()))
return null;
}
if (context.Request.Path.StartsWith(VirtualPathUtility.ToAbsolute(MiniProfiler.Settings.RouteBasePath), StringComparison.InvariantCultureIgnoreCase))
{
return null;
}
var result = new MiniProfiler(sessionName ?? url.OriginalString, level);
Current = result;
SetProfilerActive(result);
// don't really want to pass in the context to MiniProfler's constructor or access it statically in there, either
result.User = Settings.UserProvider.GetUser(context.Request);
return result;
}
开发者ID:CurufinweU,项目名称:dotnet,代码行数:30,代码来源:WebRequestProfilerProvider.cs
示例5: Start
public override StackExchange.Profiling.MiniProfiler Start(ProfileLevel level, string sessionName = null)
{
_profiler = new StackExchange.Profiling.MiniProfiler(ConsoleProfiling.ProfilingUrl(), level);
SetProfilerActive(_profiler);
_profiler.User = ConsoleProfiling.CurrentUser();
return _profiler;
}
开发者ID:Choonster,项目名称:MiniProfiler.Windows,代码行数:7,代码来源:ConsoleProfilingProvider.cs
示例6: Save
/// <summary>
/// Stores <paramref name="profiler"/> under its <see cref="P:StackExchange.Profiling.MiniProfiler.Id"/>.
/// </summary>
/// <param name="profiler">The results of a profiling session.</param>
/// <remarks>
/// Should also ensure the profiler is stored as being un-viewed by its profiling <see cref="P:StackExchange.Profiling.MiniProfiler.User"/>.
/// </remarks>
public void Save(MiniProfiler profiler)
{
if (_log == null)
{
return;
}
switch (_profilerProfilerLevel)
{
case Log4NetLevels.Off:
//Off
return;
case Log4NetLevels.Fatal:
_log.FatalExt(GetProfilerText(profiler));
break;
case Log4NetLevels.Error:
_log.ErrorExt(GetProfilerText(profiler));
break;
case Log4NetLevels.Warn:
_log.WarnExt(GetProfilerText(profiler));
break;
case Log4NetLevels.Info:
_log.InfoExt(GetProfilerText(profiler));
break;
case Log4NetLevels.Debug:
_log.DebugExt(GetProfilerText(profiler));
break;
}
}
开发者ID:SvyatSlav,项目名称:MiniProfiler.Log4Net,代码行数:36,代码来源:Log4NetStorage.cs
示例7: SetProfilerActive
/// <summary>
/// Sets <paramref name="profiler"/> to be active (read to start profiling)
/// This should be called once a new MiniProfiler has been created.
/// </summary>
/// <exception cref="ArgumentNullException">If <paramref name="profiler"/> is null</exception>
protected static void SetProfilerActive(MiniProfiler profiler)
{
if (profiler == null)
throw new ArgumentNullException("profiler");
profiler.IsActive = true;
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:12,代码来源:BaseProfilerProvider.cs
示例8: CreateContextProfiler
/// <summary>
/// Creates a new profiler for the current context, used for background tasks
/// </summary>
/// <param name="name">The name of the profiler to create</param>
/// <param name="id">The Id of the profiler</param>
public static MiniProfiler CreateContextProfiler(string name, Guid? id = null)
{
var profiler = new MiniProfiler(name);
SetProfilerActive(profiler);
if (id.HasValue) profiler.Id = id.Value;
CallContext.LogicalSetData(LocalContextKey, profiler);
return profiler;
}
开发者ID:JonBons,项目名称:Opserver,代码行数:13,代码来源:OpserverProfileProvider.cs
示例9: BlogController
/// <summary>
/// Initializes a new instance of the <see cref="BlogController" /> class.
/// </summary>
/// <param name="blogRepository">The blog post repository.</param>
/// <param name="commentRepository">The Disqus comment repository</param>
/// <param name="urlShortener">The URL shortener</param>
/// <param name="socialManager">The social network manager used to get sharing URLs</param>
/// <param name="siteConfig">Site configuration</param>
public BlogController(IBlogRepository blogRepository, IDisqusCommentRepository commentRepository, IUrlShortener urlShortener, ISocialManager socialManager, ISiteConfiguration siteConfig)
{
_blogRepository = blogRepository;
_commentRepository = commentRepository;
_urlShortener = urlShortener;
_socialManager = socialManager;
_siteConfig = siteConfig;
_profiler = MiniProfiler.Current;
}
开发者ID:TobiasWooldridge,项目名称:Website,代码行数:17,代码来源:BlogController.cs
示例10: SaveProfiler
/// <summary>
/// Calls <see cref="MiniProfiler.Settings.EnsureStorageStrategy"/> to save the current
/// profiler using the current storage settings
/// </summary>
protected static void SaveProfiler(MiniProfiler current)
{
// because we fetch profiler results after the page loads, we have to put them somewhere in the meantime
MiniProfiler.Settings.EnsureStorageStrategy();
MiniProfiler.Settings.Storage.Save(current);
if (current.HasUserViewed == false)
{
MiniProfiler.Settings.Storage.SetUnviewed(current.User, current.Id);
}
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:14,代码来源:BaseProfilerProvider.cs
示例11: StopProfiler
/// <summary>
/// Stops the profiler and marks it as inactive.
/// </summary>
/// <returns>True if successful, false if Stop had previously been called on this profiler</returns>
/// <exception cref="ArgumentNullException">If <paramref name="profiler"/> is null</exception>
protected static bool StopProfiler(MiniProfiler profiler)
{
if (profiler == null)
throw new ArgumentNullException("profiler");
if (!profiler.StopImpl())
return false;
profiler.IsActive = false;
return true;
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:16,代码来源:BaseProfilerProvider.cs
示例12: GetProfiler
public void GetProfiler()
{
var expectedProfiler = new MiniProfiler("http://fake");
var storage = NSubstitute.Substitute.For<IStorage>();
storage.Load(expectedProfiler.Id).Returns(expectedProfiler);
MiniProfiler.Settings.Storage = storage;
var controller = new ProfilerResultsController();
var profiler = controller.Get(expectedProfiler.Id);
Assert.AreEqual<MiniProfiler>(expectedProfiler, profiler);
}
开发者ID:jjschlesinger,项目名称:DefiantCode.WebApiProfiler,代码行数:13,代码来源:ProfilerResultsControllerTests.cs
示例13: CustomTiming
/// <summary>
/// Returns a new CustomTiming, also initializing its <see cref="Id"/> and, optionally, its <see cref="StackTraceSnippet"/>.
/// </summary>
public CustomTiming(MiniProfiler profiler, string commandString)
{
_profiler = profiler;
_startTicks = profiler.ElapsedTicks;
CommandString = commandString;
Id = Guid.NewGuid();
StartMilliseconds = profiler.GetRoundedMilliseconds(profiler.ElapsedTicks);
if (!MiniProfiler.Settings.ExcludeStackTraceSnippetFromCustomTimings)
{
StackTraceSnippet = Helpers.StackTraceSnippet.Get();
}
}
开发者ID:haroonxml,项目名称:dotnet,代码行数:17,代码来源:CustomTiming.cs
示例14: GetAllProfilerIdsWithDefaultParams
public void GetAllProfilerIdsWithDefaultParams()
{
var expectedProfilerIds = new List<Guid>();
var profiler = new MiniProfiler("http://fake");
expectedProfilerIds.Add(profiler.Id);
var storage = NSubstitute.Substitute.For<IStorage>();
storage.List(25).Returns(expectedProfilerIds);
MiniProfiler.Settings.Storage = storage;
var controller = new ProfilerResultsController();
var profilerIds = controller.Get().ToList();
Assert.AreEqual<Guid>(expectedProfilerIds.First(), profilerIds.First());
}
开发者ID:jjschlesinger,项目名称:DefiantCode.WebApiProfiler,代码行数:15,代码来源:ProfilerResultsControllerTests.cs
示例15: Start
/// <summary>
/// Starts a new MiniProfiler and sets it to be current. By the end of this method
/// <see cref="M:StackExchange.Profiling.BaseProfilerProvider.GetCurrentProfiler"/> should return the new MiniProfiler.
/// </summary>
public override MiniProfiler Start(string sessionName = null)
{
_profiler = new MiniProfiler(sessionName ?? AppDomain.CurrentDomain.FriendlyName);
if (IsLogEnabled(_logger, _profilerLogLevel))
{
SetProfilerActive(_profiler);
}
else
{
StopProfiler(_profiler);
}
return _profiler;
}
开发者ID:SvyatSlav,项目名称:MiniProfiler.Log4Net,代码行数:19,代码来源:Log4NetProfilerProvider.cs
示例16: Timing
/// <summary>
/// Creates a new Timing named 'name' in the 'profiler's session, with 'parent' as this Timing's immediate ancestor.
/// </summary>
public Timing(MiniProfiler profiler, Timing parent, string name)
{
this.Id = Guid.NewGuid();
Profiler = profiler;
Profiler.Head = this;
if (parent != null) // root will have no parent
{
parent.AddChild(this);
}
Name = name;
_startTicks = profiler.ElapsedTicks;
StartMilliseconds = profiler.GetRoundedMilliseconds(_startTicks);
}
开发者ID:appacitive,项目名称:Profiling,代码行数:18,代码来源:Timing.cs
示例17: SqlTiming
/// <summary>
/// Initialises a new instance of the <see cref="SqlTiming"/> class.
/// Creates a new <c>SqlTiming</c> to profile 'command'.
/// </summary>
public SqlTiming(IDbCommand command, SqlExecuteType type, MiniProfiler profiler)
{
if (profiler == null) throw new ArgumentNullException("profiler");
_profiler = profiler;
var commandText = AddSpacesToParameters(command.CommandText);
var parameters = GetCommandParameters(command);
if (MiniProfiler.Settings.SqlFormatter != null)
{
commandText = MiniProfiler.Settings.SqlFormatter.GetFormattedSql(commandText, parameters, command);
}
_customTiming = profiler.CustomTiming("sql", commandText, type.ToString());
if (_customTiming == null) throw new InvalidOperationException();
}
开发者ID:BiYiTuan,项目名称:dotnet,代码行数:20,代码来源:SqlTiming.cs
示例18: Suppression
/// <summary>
/// Initialises a new instance of the <see cref="Suppression"/> class.
/// Creates a new Suppression to deactive profiling while alive
/// </summary>
public Suppression(MiniProfiler profiler)
{
if (profiler == null)
{
throw new ArgumentNullException("profiler");
}
Profiler = profiler;
if (!Profiler.IsActive)
{
return;
}
Profiler.IsActive = false;
_wasSuppressed = true;
}
开发者ID:CurufinweU,项目名称:dotnet,代码行数:20,代码来源:Suppression.cs
示例19: SaveProfiler
/// <summary>
/// Calls <see cref="MiniProfiler.Settings.EnsureStorageStrategy"/> to save the current
/// profiler using the current storage settings.
/// If <see cref="MiniProfiler.Storage"/> is set, this will be used.
/// </summary>
protected static void SaveProfiler(MiniProfiler current)
{
// because we fetch profiler results after the page loads, we have to put them somewhere in the meantime
// If the current MiniProfiler object has a custom IStorage set in the Storage property, use it. Else use the Global Storage.
var storage = current.Storage;
if (storage == null)
{
MiniProfiler.Settings.EnsureStorageStrategy();
storage = MiniProfiler.Settings.Storage;
}
storage.Save(current);
if (current.HasUserViewed == false)
{
storage.SetUnviewed(current.User, current.Id);
}
}
开发者ID:CurufinweU,项目名称:dotnet,代码行数:21,代码来源:BaseProfilerProvider.cs
示例20: GetConnection
public static DbConnection GetConnection(MiniProfiler profiler = null)
{
using (profiler.Step("GetOpenConnection"))
{
DbConnection cnn = new System.Data.SQLite.SQLiteConnection(MvcApplication.ConnectionString);
// to get profiling times, we have to wrap whatever connection we're using in a ProfiledDbConnection
// when MiniProfiler.Current is null, this connection will not record any database timings
if (MiniProfiler.Current != null)
{
cnn = new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);
}
cnn.Open();
return cnn;
}
}
开发者ID:shaileshpandey,项目名称:MiniProfiler,代码行数:17,代码来源:BaseController.cs
注:本文中的StackExchange.Profiling.MiniProfiler类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论