public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) { using (_profiler.Step(string.Format("{0}.FindView, {1}, {2}", _name, viewName, isMainPage))) { return(WrapResult(Inner.FindView(context, viewName, isMainPage))); } }
// internal - created by profiling logger internal DisposableTimer(ILogger logger, LogLevel level, IProfiler profiler, Type loggerType, string startMessage, string endMessage, string failMessage = null, int thresholdMilliseconds = 0) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _level = level; _loggerType = loggerType ?? throw new ArgumentNullException(nameof(loggerType)); _endMessage = endMessage; _failMessage = failMessage; _thresholdMilliseconds = thresholdMilliseconds < 0 ? 0 : thresholdMilliseconds; _timingId = Guid.NewGuid().ToString("N").Substring(0, 7); // keep it short-ish if (thresholdMilliseconds == 0) { switch (_level) { case LogLevel.Debug: logger.Debug <string, string>(loggerType, "{StartMessage} [Timing {TimingId}]", startMessage, _timingId); break; case LogLevel.Information: logger.Info <string, string>(loggerType, "{StartMessage} [Timing {TimingId}]", startMessage, _timingId); break; default: throw new ArgumentOutOfRangeException(nameof(level)); } } // else aren't logging the start message, this is output to the profiler but not the log, // we just want the log to contain the result if it's more than the minimum ms threshold. _profilerStep = profiler?.Step(loggerType, startMessage); }
public void Run() { using (_profiler.Step("Call Methods")) { _quick.DoTheQuickWork(); _slow.DoTheSlowWork(); } }
/// <summary> /// Writes out a step prefixed with the type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="profiler"></param> /// <param name="name"></param> /// <returns></returns> internal static IDisposable Step <T>(this IProfiler profiler, string name) { if (profiler == null) { throw new ArgumentNullException("profiler"); } return(profiler.Step(typeof(T), name)); }
internal DisposableTimer(ILogger logger, LogType logType, IProfiler profiler, Type loggerType, string startMessage, string endMessage) { if (logger == null) { throw new ArgumentNullException("logger"); } if (loggerType == null) { throw new ArgumentNullException("loggerType"); } _callback = x => { if (profiler != null) { profiler.DisposeIfDisposable(); } switch (logType) { case LogType.Debug: logger.Debug(loggerType, () => endMessage + " (took " + x + "ms)"); break; case LogType.Info: logger.Info(loggerType, () => endMessage + " (took " + x + "ms)"); break; default: throw new ArgumentOutOfRangeException("logType"); } }; switch (logType) { case LogType.Debug: logger.Debug(loggerType, startMessage); break; case LogType.Info: logger.Info(loggerType, startMessage); break; default: throw new ArgumentOutOfRangeException("logType"); } if (profiler != null) { profiler.Step(loggerType, startMessage); } }
/// <summary> /// Creates an <see cref="IProfilingStep"/> that will time the code between its creation and disposal. /// </summary> /// <param name="name">The name of the step.</param> /// <param name="tags">The tags of the step.</param> /// <returns></returns> internal IDisposable StepImpl(string name, string[] tags) { IProfilingStep step = null; try { step = _profiler.Step(name, tags == null || !tags.Any() ? null : new TagCollection(tags)); } catch (Exception ex) { HandleExceptionHandler(ex, this); } return(step); }
/// <summary> /// Writes out a step prefixed with the type /// </summary> /// <param name="profiler"></param> /// <param name="objectType"></param> /// <param name="name"></param> /// <returns></returns> internal static IDisposable Step(this IProfiler profiler, Type objectType, string name) { if (profiler == null) { throw new ArgumentNullException("profiler"); } if (objectType == null) { throw new ArgumentNullException("objectType"); } if (name == null) { throw new ArgumentNullException("name"); } return(profiler.Step(string.Format("[{0}] {1}", objectType.Name, name))); }
/// <summary> /// Gets an <see cref="IDisposable"/> that will time the code between its creation and disposal, /// prefixing the name of the step with a reporting type name. /// </summary> /// <param name="profiler">The profiler.</param> /// <param name="reporting">The reporting type.</param> /// <param name="name">The name of the step.</param> /// <returns>A step.</returns> /// <remarks>The returned <see cref="IDisposable"/> is meant to be used within a <c>using (...) {{ ... }}</c> block.</remarks> internal static IDisposable Step(this IProfiler profiler, Type reporting, string name) { if (profiler == null) { throw new ArgumentNullException(nameof(profiler)); } if (reporting == null) { throw new ArgumentNullException(nameof(reporting)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } return(profiler.Step($"[{reporting.Name}] {name}")); }
internal DisposableTimer(ILogger logger, LogType logType, IProfiler profiler, Type loggerType, string startMessage, string endMessage) { if (logger == null) { throw new ArgumentNullException("logger"); } if (loggerType == null) { throw new ArgumentNullException("loggerType"); } _logger = logger; _logType = logType; _profiler = profiler; _loggerType = loggerType; _endMessage = endMessage; switch (logType) { case LogType.Debug: logger.Debug(loggerType, startMessage); break; case LogType.Info: logger.Info(loggerType, startMessage); break; default: throw new ArgumentOutOfRangeException("logType"); } if (profiler != null) { _profilerStep = profiler.Step(loggerType, startMessage); } }
private IDisposable GetProcessStep(IProfiler profiler, string arguments, object[] args) { string formattedArgs = String.Format(arguments, args); string stepTitle = String.Format(@"Executing external process P(""{0}"", ""{1}"")", System.IO.Path.GetFileName(Path), formattedArgs); return profiler.Step(stepTitle); }
// internal - created by profiling logger internal DisposableTimer( ILogger logger, LogLevel level, IProfiler profiler, Type loggerType, string startMessage, string endMessage, string?failMessage = null, object[]?startMessageArgs = null, object[]?endMessageArgs = null, object[]?failMessageArgs = null, int thresholdMilliseconds = 0) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _level = level; _loggerType = loggerType ?? throw new ArgumentNullException(nameof(loggerType)); _endMessage = endMessage; _failMessage = failMessage; _endMessageArgs = endMessageArgs; _failMessageArgs = failMessageArgs; _thresholdMilliseconds = thresholdMilliseconds < 0 ? 0 : thresholdMilliseconds; _timingId = Guid.NewGuid().ToString("N").Substring(0, 7); // keep it short-ish if (thresholdMilliseconds == 0) { switch (_level) { case LogLevel.Debug: if (startMessageArgs == null) { logger.LogDebug("{StartMessage} [Timing {TimingId}]", startMessage, _timingId); } else { var args = new object[startMessageArgs.Length + 1]; startMessageArgs.CopyTo(args, 0); args[startMessageArgs.Length] = _timingId; logger.LogDebug(startMessage + " [Timing {TimingId}]", args); } break; case LogLevel.Information: if (startMessageArgs == null) { logger.LogInformation("{StartMessage} [Timing {TimingId}]", startMessage, _timingId); } else { var args = new object[startMessageArgs.Length + 1]; startMessageArgs.CopyTo(args, 0); args[startMessageArgs.Length] = _timingId; logger.LogInformation(startMessage + " [Timing {TimingId}]", args); } break; default: throw new ArgumentOutOfRangeException(nameof(level)); } } // else aren't logging the start message, this is output to the profiler but not the log, // we just want the log to contain the result if it's more than the minimum ms threshold. _profilerStep = profiler?.Step(loggerType, startMessage); }
/// <summary> /// Copy the repository from the temp repository path to the repository path. /// Only happens on first deployment. /// </summary> private void CopyRepository(string id, IProfiler profiler) { ILogger logger = null; DeploymentStatusFile trackingFile = null; try { logger = GetLogger(id); trackingFile = OpenTrackingFile(id); // The repository has already been copied if (_environment.RepositoryType != RepositoryType.None) { return; } using (profiler.Step("Copying files to repository")) { // Copy the repository from the temporary path to the repository target path FileSystemHelpers.Copy(_environment.DeploymentRepositoryPath, _environment.DeploymentRepositoryTargetPath, skipScmFolder: false); } } catch (Exception ex) { if (logger != null) { logger.Log(ex); } } finally { if (trackingFile != null) { trackingFile.Complete = true; trackingFile.Save(_fileSystem); } ReportStatus(id); } }
/// <summary> /// Builds and deploys a particular changeset. Puts all build artifacts in a deployments/{id} /// </summary> private void Build(string id, IProfiler profiler, IDisposable deployStep) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException(); } // TODO: Make sure if the if is a valid changeset ILogger logger = null; DeploymentStatusFile trackingFile = null; ILogger innerLogger = null; IDisposable buildStep = null; try { // Get the logger for this id string logPath = GetLogPath(id); FileSystemHelpers.DeleteFileSafe(logPath); ReportStatus(id); logger = GetLogger(id); innerLogger = logger.Log("Preparing deployment for {0}.", id); trackingFile = OpenTrackingFile(id); trackingFile.Complete = false; trackingFile.Status = DeployStatus.Building; trackingFile.StatusText = String.Format("Building and Deploying {0}...", id); trackingFile.Save(_fileSystem); ReportStatus(id); // Create a deployer ISiteBuilder builder = _builderFactory.CreateBuilder(innerLogger); buildStep = profiler.Step("Building"); var context = new DeploymentContext { ManifestWriter = GetDeploymentManifestWriter(id), PreviousMainfest = GetActiveDeploymentManifestReader(), Profiler = profiler, Logger = logger, OutputPath = _environment.DeploymentTargetPath, }; builder.Build(context) .Then(() => { // End the build step buildStep.Dispose(); // Set the deployment percent to 50% and report status trackingFile.Percentage = 50; trackingFile.Save(_fileSystem); ReportStatus(id); // Run post deployment steps RunPostDeploymentSteps(id, profiler, deployStep); // Copy repository (if this is the first push) CopyRepository(id, profiler); }) .Catch(ex => { NotifyError(logger, trackingFile, ex); ReportStatus(id); // End the deploy step deployStep.Dispose(); }); } catch (Exception e) { if (innerLogger != null) { NotifyError(innerLogger, trackingFile, e); innerLogger.Log(e); ReportStatus(id); } if (buildStep != null) { buildStep.Dispose(); } deployStep.Dispose(); } }