2020-12-19 08:17:35 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-07-01 18:07:00 +10:00
|
|
|
using StackExchange.Profiling;
|
|
|
|
|
using StackExchange.Profiling.SqlFormatters;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Logging;
|
2014-07-01 18:07:00 +10:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.Common.TestHelpers.Stubs
|
2014-07-01 18:07:00 +10:00
|
|
|
{
|
|
|
|
|
public class TestProfiler : IProfiler
|
|
|
|
|
{
|
2020-12-19 08:17:35 +01:00
|
|
|
public static void Enable() => s_enabled = true;
|
2014-07-01 18:07:00 +10:00
|
|
|
|
2020-12-19 08:17:35 +01:00
|
|
|
public static void Disable() => s_enabled = false;
|
2014-07-01 18:07:00 +10:00
|
|
|
|
2020-12-19 08:17:35 +01:00
|
|
|
private static bool s_enabled;
|
2014-07-01 18:07:00 +10:00
|
|
|
|
2020-12-19 08:17:35 +01:00
|
|
|
public IDisposable Step(string name) => s_enabled ? MiniProfiler.Current.Step(name) : null;
|
2014-07-01 18:07:00 +10:00
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2020-12-19 08:17:35 +01:00
|
|
|
if (s_enabled == false)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-11 19:57:33 +02:00
|
|
|
|
2020-12-19 08:17:35 +01:00
|
|
|
// See https://miniprofiler.com/dotnet/AspDotNet
|
2019-02-06 19:04:52 +11:00
|
|
|
MiniProfiler.Configure(new MiniProfilerOptions
|
|
|
|
|
{
|
|
|
|
|
SqlFormatter = new SqlServerFormatter(),
|
|
|
|
|
StackMaxLength = 5000,
|
|
|
|
|
});
|
2020-12-19 08:17:35 +01:00
|
|
|
|
2019-02-06 19:04:52 +11:00
|
|
|
MiniProfiler.StartNew();
|
2014-07-01 18:07:00 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop(bool discardResults = false)
|
|
|
|
|
{
|
2020-12-19 08:17:35 +01:00
|
|
|
if (s_enabled)
|
|
|
|
|
{
|
2019-02-06 19:04:52 +11:00
|
|
|
MiniProfiler.Current.Stop(discardResults);
|
2020-12-19 08:17:35 +01:00
|
|
|
}
|
2014-07-01 18:07:00 +10:00
|
|
|
}
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|