本文整理汇总了C#中StackExchange.Profiling.MiniProfiler类的典型用法代码示例。如果您正苦于以下问题:C# MiniProfiler类的具体用法?C# MiniProfiler怎么用?C# MiniProfiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MiniProfiler类属于StackExchange.Profiling命名空间,在下文中一共展示了MiniProfiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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)
{
}
}
}
示例3: HomeController
public HomeController()
{
DbInitializer.Initialize();
profiler = MiniProfiler.Current;
EasternStandardTimeId = "Eastern Standard Time";
ESTTimeZone = TimeZoneInfo.FindSystemTimeZoneById(EasternStandardTimeId);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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());
}
示例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;
}