Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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());
        }
Example #4
0
        /// <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));
        }
Example #5
0
        /// <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));
        }
Example #6
0
        /// <summary>
        /// Starts the profiling.
        /// </summary>
        /// <param name="name">The name of the profiling session.</param>
        /// <param name="tags">The tags of the profiling session.</param>
        public static void Start(string name, params string[] tags)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            // set null the current profiling session if exists
            ProfilingSession.SetCurrentProfilingSession(null);

            if (ProfilingFilters.Count > 0)
            {
                foreach (var filter in ProfilingFilters)
                {
                    if (filter == null)
                    {
                        continue;
                    }
                    if (filter.ShouldBeExculded(name, tags))
                    {
                        return;
                    }
                }
            }

            IProfiler profiler = null;

            try
            {
                profiler = CreateProfilerHandler(name, _profilingStorage, tags == null || !tags.Any() ? null : new TagCollection(tags));
            }
            catch (Exception ex)
            {
                HandleExceptionHandler(ex, typeof(ProfilingSession));
            }

            if (profiler != null)
            {
                // Create the current ProfilingSession
                _profilingSessionContainer.CurrentSession = new ProfilingSession(profiler);
            }
        }
Example #7
0
        /// <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;
            }
        }