Example #1
0
        public void TestProfilingStepTiming_Discard()
        {
            var name = "test";
            var stepId = Guid.NewGuid();
            ProfilingSession.ProfilingSessionContainer.CurrentSessionStepId = stepId;
            var profilerAddStepTimingCalled = false;
            var profilerDurationMilliseconds = 10;
            var mockProfiler = new Mock<IProfiler>();
            mockProfiler.Setup(profiler => profiler.DurationMilliseconds).Returns(() => profilerDurationMilliseconds++);

            var target = new StepTiming(mockProfiler.Object, name);
            mockProfiler.Setup(profiler => profiler.AddStepTiming(It.IsAny<StepTiming>()))
                .Callback<StepTiming>(a =>
                {
                    Assert.AreEqual(target, a);
                    profilerAddStepTimingCalled = true;
                });

            (target as IProfilingStep).Discard();
            target.Dispose();

            Assert.AreNotEqual(default(Guid), target.Id);
            Assert.AreEqual(name, target.Name);
            Assert.AreEqual(stepId, target.ParentId);
            Assert.AreEqual(10, target.StartMilliseconds);
            Assert.AreEqual(0, target.DurationMilliseconds);
            Assert.IsFalse(profilerAddStepTimingCalled);
        }
 void IProfiler.AddStepTiming(StepTiming stepTiming)
 {
     throw new NotImplementedException();
 }
        private StepTiming CreateStepTiming(SerializableStepTiming sourceStepTiming)
        {
            // ensure parentId
            ProfilingSession.ProfilingSessionContainer.CurrentSessionStepId = sourceStepTiming.ParentId;

            var stepTiming = new StepTiming(this, sourceStepTiming.Name)
            {
                DurationMilliseconds = sourceStepTiming.DurationMilliseconds,
                ExecuteType = sourceStepTiming.ExecuteType,
                StartMilliseconds = sourceStepTiming.StartMilliseconds,
                Sort = sourceStepTiming.Sort,
                Tags = sourceStepTiming.Tags == null ? null : new TagCollection(sourceStepTiming.Tags)
            };

            // fix Id
            if (CustomTimings != null)
            {
                for (var i = 0; i < CustomTimings.Count; ++i)
                {
                    if (CustomTimings[i].ParentId == sourceStepTiming.Id)
                    {
                        CustomTimings[i].ParentId = stepTiming.Id;
                    }
                }
            }
            for (var i = 0; i < StepTimings.Count; ++i)
            {
                if (StepTimings[i].ParentId == sourceStepTiming.Id)
                {
                    StepTimings[i].ParentId = stepTiming.Id;
                }
            }
            sourceStepTiming.Id = stepTiming.Id;

            ProfilingSession.ProfilingSessionContainer.CurrentSessionStepId = null;

            return stepTiming;
        }
        /// <summary>
        /// Saves a step timing.
        /// </summary>
        /// <param name="profiler">The profiler.</param>
        /// <param name="stepTiming">The step timing.</param>
        protected virtual void SaveStepTiming(IProfiler profiler, StepTiming stepTiming)
        {
            if (profiler == null || stepTiming == null)
            {
                return;
            }

            try
            {
                var stepData = new StepTimingData();
                SetBasicTimingProperties(stepTiming, stepData);

                stepData.SessionId = profiler.Id;

                LogTimingData(stepData);
            }
            catch (Exception ex)
            {
                _logger.Value.Error(ex, ex.Message);
            }
        }
Example #5
0
        /// <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>
        /// <param name="executeType">The executeType of this step.</param>
        /// <returns>Returns the created <see cref="IProfilingStep"/>.</returns>
        public IProfilingStep Step(string name, IEnumerable<string> tags, string executeType)
        {
            var step = new StepTiming(this, name) { ExecuteType = executeType };
            if (tags != null && tags.Any())
            {
                step.Tags = new TagCollection(tags);
            }

            return step;
        }
Example #6
0
 void IProfiler.AddStepTiming(StepTiming stepTiming)
 {
     AddStepTiming(stepTiming);
 }
Example #7
0
 /// <summary>
 /// Returns an <see cref="System.IDisposable"/> that will ignore the profiling between its creation and disposal.
 /// </summary>
 /// <returns>Returns the created <see cref="System.IDisposable"/> as the ignored step.</returns>
 public IDisposable Ignore()
 {
     IProfilingStep ignoredStep = new StepTiming(this, "ignored step");
     ignoredStep.Discard();
     return ignoredStep;
 }
Example #8
0
 /// <summary>
 /// Adds a step timing to the raw step timing collection.
 /// </summary>
 /// <param name="stepTiming">The step timing to be added.</param>
 public virtual void AddStepTiming(StepTiming stepTiming)
 {
     if (stepTiming != null && _stopwatch.IsRunning)
     {
         _stepTimings.Enqueue(stepTiming);
     }
 }