diff --git a/MiniProfiler.sln b/MiniProfiler.sln index cdd10aef..9aadf303 100644 --- a/MiniProfiler.sln +++ b/MiniProfiler.sln @@ -94,6 +94,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.AspNet", "samples\Samples.AspNet\Samples.AspNet.csproj", "{9C7822CD-BE8E-424F-A0C6-86CC986ABB42}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiniProfiler.Minimal", "src\MiniProfiler.Minimal\MiniProfiler.Minimal.csproj", "{A1DCACC2-0D9A-401E-B6A4-856E5DD00541}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -204,6 +206,10 @@ Global {9C7822CD-BE8E-424F-A0C6-86CC986ABB42}.Debug|Any CPU.Build.0 = Debug|Any CPU {9C7822CD-BE8E-424F-A0C6-86CC986ABB42}.Release|Any CPU.ActiveCfg = Release|Any CPU {9C7822CD-BE8E-424F-A0C6-86CC986ABB42}.Release|Any CPU.Build.0 = Release|Any CPU + {A1DCACC2-0D9A-401E-B6A4-856E5DD00541}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1DCACC2-0D9A-401E-B6A4-856E5DD00541}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1DCACC2-0D9A-401E-B6A4-856E5DD00541}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1DCACC2-0D9A-401E-B6A4-856E5DD00541}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -236,6 +242,7 @@ Global {BD7A4E74-ECFE-4BBE-86D9-D6DC2BED86DB} = {6A510DBF-E85F-4D2C-B8F7-006DA31B3418} {A14EA029-60E2-485A-B757-3626511CF2C4} = {5C8ED0C0-7DBB-4660-836E-A760E25160A0} {9C7822CD-BE8E-424F-A0C6-86CC986ABB42} = {E0DA4035-4D64-4BB8-8EA1-42197DE62519} + {A1DCACC2-0D9A-401E-B6A4-856E5DD00541} = {6A510DBF-E85F-4D2C-B8F7-006DA31B3418} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution LessCompiler = 6a2b5b70-1c32-482f-b5c6-0597e2d4e376 diff --git a/src/MiniProfiler.Minimal/MiniProfiler.Minimal.csproj b/src/MiniProfiler.Minimal/MiniProfiler.Minimal.csproj new file mode 100644 index 00000000..1565f7c4 --- /dev/null +++ b/src/MiniProfiler.Minimal/MiniProfiler.Minimal.csproj @@ -0,0 +1,25 @@ + + + MiniProfiler.Minimal + MiniProfiler.Minimal + Nick Craver + MiniProfiler's no-frills headless build for no-UI applications. + netstandard2.0 + MINIMAL + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs b/src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs index bc5165f6..185dae42 100644 --- a/src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs +++ b/src/MiniProfiler.Shared/Data/ProfiledDbCommand.cs @@ -2,10 +2,12 @@ using System.ComponentModel; using System.Data; using System.Data.Common; -using System.Reflection; -using System.Reflection.Emit; using System.Threading; using System.Threading.Tasks; +#if !MINIMAL +using System.Reflection; +using System.Reflection.Emit; +#endif namespace StackExchange.Profiling.Data { @@ -15,12 +17,10 @@ namespace StackExchange.Profiling.Data [System.ComponentModel.DesignerCategory("")] public partial class ProfiledDbCommand : DbCommand { - private static Link> bindByNameCache; private DbCommand _command; private DbConnection _connection; private DbTransaction _transaction; private IDbProfiler _profiler; - private bool _bindByName; /// /// Whether to always wrap data readers, even if there isn't an active profiler on this connect. @@ -28,6 +28,10 @@ public partial class ProfiledDbCommand : DbCommand /// protected virtual bool AlwaysWrapReaders => false; +#if !MINIMAL + private static Link> bindByNameCache; + private bool _bindByName; + /// /// Gets or sets a value indicating whether or not to bind by name. /// If the underlying command supports BindByName, this sets/clears the underlying @@ -49,6 +53,7 @@ public bool BindByName } } } +#endif /// /// Initializes a new instance of the class. @@ -73,6 +78,7 @@ public ProfiledDbCommand(DbCommand command, DbConnection connection, IDbProfiler } } +#if !MINIMAL /// /// Get the binding name. /// @@ -108,6 +114,7 @@ private static Action GetBindByName(Type commandType) Link>.TryAdd(ref bindByNameCache, commandType, ref action); return action; } +#endif /// /// Gets or sets the text command to run against the data source. diff --git a/src/MiniProfiler.Shared/Internal/ExtensionMethods.cs b/src/MiniProfiler.Shared/Internal/ExtensionMethods.cs index 937f4d4d..9c5ad953 100644 --- a/src/MiniProfiler.Shared/Internal/ExtensionMethods.cs +++ b/src/MiniProfiler.Shared/Internal/ExtensionMethods.cs @@ -2,8 +2,10 @@ using System.Text; using System; using System.Collections.Generic; +#if !MINIMAL using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +#endif namespace StackExchange.Profiling.Internal { @@ -76,6 +78,7 @@ public static string ToJson(this List guids) return sb.ToString(); } +#if !MINIMAL private static readonly JsonSerializerSettings defaultSettings = new() { NullValueHandling = NullValueHandling.Ignore, @@ -122,6 +125,8 @@ public static string ToJson(this object o) => public static T FromJson(this string s) where T : class => !string.IsNullOrEmpty(s) ? JsonConvert.DeserializeObject(s, defaultSettings) : null; +#endif + /// /// equivalent of ConcurrentDictionary's .TryRemove(); /// diff --git a/src/MiniProfiler.Shared/Internal/MiniProfilerBaseOptions.cs b/src/MiniProfiler.Shared/Internal/MiniProfilerBaseOptions.cs index e486fb7b..82bea1b7 100644 --- a/src/MiniProfiler.Shared/Internal/MiniProfilerBaseOptions.cs +++ b/src/MiniProfiler.Shared/Internal/MiniProfilerBaseOptions.cs @@ -103,6 +103,7 @@ public class MiniProfilerBaseOptions /// public decimal TrivialDurationThresholdMilliseconds { get; set; } = 2.0M; +#if !MINIMAL /// /// Dictates if the "time with children" column is displayed by default, defaults to false. /// For a per-page override you can use .RenderIncludes(showTimeWithChildren: true/false) @@ -164,6 +165,7 @@ public class MiniProfilerBaseOptions nameof(ProfiledDbConnection.Close), "CloseAsync" // RelationalDiagnosticListener }; +#endif /// /// By default, s created by this assembly will grab a stack trace to help diff --git a/src/MiniProfiler.Shared/MiniProfiler.cs b/src/MiniProfiler.Shared/MiniProfiler.cs index 68104218..7d925613 100644 --- a/src/MiniProfiler.Shared/MiniProfiler.cs +++ b/src/MiniProfiler.Shared/MiniProfiler.cs @@ -89,6 +89,7 @@ public MiniProfiler(string name, MiniProfilerBaseOptions options) [DataMember(Order = 5)] public string MachineName { get; set; } +#if !MINIMAL /// /// Keys are names, values are URLs, allowing additional links to be added to a profiler result, e.g. perhaps a deeper /// diagnostic page for the current request. @@ -113,6 +114,7 @@ public string CustomLinksJson } } } +#endif private Timing _root; @@ -137,6 +139,7 @@ public Timing Root /// public Guid? RootTimingId { get; set; } +#if !MINIMAL /// /// Gets or sets timings collected from the client /// @@ -147,6 +150,7 @@ public Timing Root /// RedirectCount in ClientTimings. Used for sql storage. /// public int? ClientTimingsRedirectCount { get; set; } +#endif /// /// Gets or sets a string identifying the user/client that is profiling this request. @@ -283,11 +287,13 @@ private bool InnerStop() return true; } +#if !MINIMAL /// /// Deserializes the JSON string parameter to a . /// /// The string to deserialize into a . public static MiniProfiler FromJson(string json) => json.FromJson(); +#endif /// /// Returns the 's and this profiler recorded. diff --git a/src/MiniProfiler.Shared/MiniProfilerExtensions.cs b/src/MiniProfiler.Shared/MiniProfilerExtensions.cs index 3cd25d17..7735505e 100644 --- a/src/MiniProfiler.Shared/MiniProfilerExtensions.cs +++ b/src/MiniProfiler.Shared/MiniProfilerExtensions.cs @@ -128,6 +128,7 @@ public static void AddProfilerResults(this MiniProfiler profiler, MiniProfiler e profiler.Head.AddChild(externalProfiler.Root); } +#if !MINIMAL /// /// Adds the and pair to 's /// dictionary; will be displayed on the client in the bottom of the profiler popup. @@ -213,5 +214,6 @@ public static string RenderPlainText(this MiniProfiler profiler, bool htmlEncode return text.ToStringRecycle(); } +#endif } } diff --git a/src/MiniProfiler.Shared/Timing.cs b/src/MiniProfiler.Shared/Timing.cs index dd515f12..461ce415 100644 --- a/src/MiniProfiler.Shared/Timing.cs +++ b/src/MiniProfiler.Shared/Timing.cs @@ -137,6 +137,7 @@ public List Children [DataMember(Order = 7)] public TimingDebugInfo DebugInfo { get; set; } +#if !MINIMAL /// /// JSON representing the Custom Timings associated with this timing. /// @@ -144,6 +145,7 @@ public string CustomTimingsJson { get => CustomTimings?.ToJson(); set => CustomTimings = value.FromJson>>(); } +#endif /// /// Returns true when there exists any objects in this .