예제 #1
0
        /// <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();
        }
예제 #2
0
        /// <summary>
        /// Returns a new <see cref="CustomTiming"/> that will automatically set its <see cref="Profiling.CustomTiming.StartMilliseconds"/>
        /// and <see cref="Profiling.CustomTiming.DurationMilliseconds"/>
        /// </summary>
        /// <remarks>
        /// Should be used like the <see cref="Step"/> extension method:
        ///
        /// <example>
        ///
        /// </example>
        /// </remarks>
        public static CustomTiming CustomTiming(this MiniProfiler profiler, string category, string commandString, string executeType = null)
        {
            if (profiler == null || profiler.Head == null)
            {
                return(null);
            }

            var result = new CustomTiming(profiler, commandString)
            {
                ExecuteType = executeType
            };

            // THREADING: revisit
            profiler.Head.AddCustomTiming(category, result);

            return(result);
        }
        /// <summary>
        /// Returns a new <see cref="CustomTiming"/> that will automatically set its <see cref="Profiling.CustomTiming.StartMilliseconds"/>
        /// and <see cref="Profiling.CustomTiming.DurationMilliseconds"/>. Will only save the new <see cref="Timing"/> if the total elapsed time
        /// takes more than <paramef name="minSaveMs" />.
        /// </summary>
        /// <param name="profiler">The current profiling session or null.</param>
        /// <param name="category">The category under which this timing will be recorded.</param>
        /// <param name="commandString">The command string that will be recorded along with this timing, for display in the MiniProfiler results.</param>
        /// <param name="minSaveMs">The minimum amount of time that needs to elapse in order for this result to be recorded.</param>
        /// <param name="executeType">Execute Type to be associated with the Custom Timing. Example: Get, Set, Insert, Delete</param>
        /// <param name="includeStackTrace">Whether to include the stack trace in this custom timing.</param>
        /// <remarks>
        /// Should be used like the <see cref="Step(MiniProfiler, string)"/> extension method
        /// </remarks>
        public static CustomTiming CustomTimingIf(this MiniProfiler profiler, string category, string commandString, decimal minSaveMs, string executeType = null, bool includeStackTrace = true)
        {
            if (profiler == null || profiler.Head == null || !profiler.IsActive)
            {
                return(null);
            }

            var result = new CustomTiming(profiler, commandString, minSaveMs, includeStackTrace: includeStackTrace)
            {
                ExecuteType = executeType,
                Category    = category
            };

            profiler.Head?.AddCustomTiming(category, result);

            return(result);
        }
        /// <summary>
        /// Returns a new <see cref="CustomTiming"/> that will automatically set its <see cref="Profiling.CustomTiming.StartMilliseconds"/>
        /// and <see cref="Profiling.CustomTiming.DurationMilliseconds"/>. Will only save the new <see cref="Timing"/> if the total elapsed time
        /// takes more than <paramef name="minSaveMs" />.
        /// </summary>
        /// <param name="profiler">The current profiling session or null.</param>
        /// <param name="category">The category under which this timing will be recorded.</param>
        /// <param name="commandString">The command string that will be recorded along with this timing, for display in the MiniProfiler results.</param>
        /// <param name="executeType">Execute Type to be associated with the Custom Timing. Example: Get, Set, Insert, Delete</param>
        /// <param name="minSaveMs">The minimum amount of time that needs to elapse in order for this result to be recorded.</param>
        /// <remarks>
        /// Should be used like the <see cref="Step(MiniProfiler, string)"/> extension method
        /// </remarks>
        public static CustomTiming CustomTimingIf(this MiniProfiler profiler, string category, string commandString, decimal minSaveMs, string executeType = null)
        {
            if (profiler == null || profiler.Head == null || !profiler.IsActive)
            {
                return(null);
            }

            var result = new CustomTiming(profiler, commandString, minSaveMs)
            {
                ExecuteType = executeType,
                Category    = category
            };

            // THREADING: revisit
            profiler.Head.AddCustomTiming(category, result);

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Initialises a new instance of the <see cref="SqlTiming"/> class.
        /// Creates a new <c>SqlTiming</c> to profile 'command'.
        /// </summary>
        /// <param name="command">The <see cref="DbCommand"/> to time.</param>
        /// <param name="type">The execution type.</param>
        /// <param name="profiler">The miniprofiler to attach the timing to.</param>
        /// <exception cref="ArgumentNullException">Throws when the <paramref name="profiler"/> is <c>null</c>.</exception>
        /// <exception cref="InvalidOperationException">Throw if the custom timing can't be created.</exception>
        public SqlTiming(IDbCommand command, SqlExecuteType type, MiniProfiler profiler)
        {
            _profiler = profiler ?? throw new ArgumentNullException(nameof(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();
            }
        }
예제 #6
0
 internal void RemoveCustomTiming(string category, CustomTiming customTiming)
 {
     GetCustomTimingList(category).Remove(customTiming);
 }
예제 #7
0
 /// <summary>
 /// Adds <paramref name="customTiming"/> to this <see cref="Timing"/> step's dictionary of
 /// custom timings, <see cref="CustomTimings"/>.  Ensures that <see cref="CustomTimings"/> is created,
 /// as well as the <paramref name="category"/>'s list.
 /// </summary>
 /// <param name="category">The kind of custom timing, e.g. "http", "redis", "memcache"</param>
 /// <param name="customTiming">Duration and command information</param>
 public void AddCustomTiming(string category, CustomTiming customTiming)
 {
     GetCustomTimingList(category).Add(customTiming);
 }
예제 #8
0
파일: Timing.cs 프로젝트: haroonxml/dotnet
 /// <summary>
 /// Adds <paramref name="customTiming"/> to this <see cref="Timing"/> step's dictionary of 
 /// custom timings, <see cref="CustomTimings"/>.  Ensures that <see cref="CustomTimings"/> is created, 
 /// as well as the <paramref name="category"/>'s list.
 /// </summary>
 /// <param name="category">The kind of custom timing, e.g. "http", "redis", "memcache"</param>
 /// <param name="customTiming">Duration and command information</param>
 public void AddCustomTiming(string category, CustomTiming customTiming)
 {
     GetCustomTimingList(category).Add(customTiming);
 }
예제 #9
0
파일: Timing.cs 프로젝트: jchenga/dotnet
 internal void RemoveCustomTiming(string category, CustomTiming customTiming)
 {
     GetCustomTimingList(category).Remove(customTiming);
 }