/// <summary> /// Add a custom data field to current profiling session. /// </summary> /// <param name="profilingSession"></param> /// <param name="key"></param> /// <param name="value"></param> public static void AddField(this ProfilingSession profilingSession, string key, string value) { if (profilingSession == null) { return; } profilingSession.AddFieldImpl(key, value); }
/// <summary> /// Add a tag to current profiling session. /// </summary> /// <param name="profilingSession"></param> /// <param name="tag"></param> public static void AddTag(this ProfilingSession profilingSession, string tag) { if (profilingSession == null) { return; } profilingSession.AddTagImpl(tag); }
/// <summary> /// Returns an <see cref="System.IDisposable"/> that will ignore the profiling between its creation and disposal. /// </summary> /// <param name="profilingSession">The profiling session.</param> /// <returns>Returns the created <see cref="System.IDisposable"/> as the ignored step.</returns> public static IDisposable Ignore(this ProfilingSession profilingSession) { if (profilingSession == null) { return(null); } return(profilingSession.IgnoreImpl()); }
/// <summary> /// Creates an <see cref="IProfilingStep"/> that will time the code between its creation and disposal. /// </summary> /// <param name="profilingSession">The profiling session.</param> /// <param name="getName">The delegate to get the name of the step.</param> /// <param name="tags">The tags of the step.</param> /// <returns></returns> public static IDisposable Step(this ProfilingSession profilingSession, Func <string> getName, params string[] tags) { if (getName == null) { return(null); } return(profilingSession.Step(getName(), tags)); }
/// <summary> /// Creates an <see cref="IProfilingStep"/> that will time the code between its creation and disposal. /// </summary> /// <param name="profilingSession">The profiling session.</param> /// <param name="name">The name of the step.</param> /// <param name="tags">The tags of the step.</param> /// <returns></returns> public static IDisposable Step(this ProfilingSession profilingSession, string name, params string[] tags) { if (profilingSession == null || string.IsNullOrEmpty(name)) { return(null); } return(profilingSession.StepImpl(name, tags)); }
/// <summary> /// Sets current profiling session as specified session and sets the parent step as specified. /// </summary> /// <param name="session"></param> /// <param name="parentStepId">if parentStepId not specified, use the root step of session as parent step by default.</param> public static void SetCurrentProfilingSession( ProfilingSession session, Guid?parentStepId = null) { ProfilingSessionContainer.CurrentSession = null; ProfilingSessionContainer.CurrentSessionStepId = null; if (session == null || session.Profiler == null) { return; } var timingSession = session.Profiler.GetTimingSession(); if (timingSession == null || timingSession.Timings == null || timingSession.Timings.All(t => t.ParentId != timingSession.Id)) { return; } ProfilingSessionContainer.CurrentSession = session; if (parentStepId.HasValue && timingSession.Timings.Any(t => t.Id == parentStepId.Value && string.Equals(t.Type, "step"))) { ProfilingSessionContainer.CurrentSessionStepId = parentStepId.Value; } else // if parentStepId not specified, use the root step of session as parent step by default { var rootStep = timingSession.Timings.FirstOrDefault(t => t.ParentId == timingSession.Id); if (rootStep == null) { return; } ProfilingSessionContainer.CurrentSessionStepId = rootStep.Id; } }