예제 #1
0
        public void ContextBatchTest(ExpressionEvaluationContext contextSource,
                                     ExpressionEvaluation.Types.Context contextExpected)
        {
            _expressionEvaluationBatch.Add(new ExpressionEvaluationBatchParams(
                                               ExpressionEvaluationStrategy.LLDB, contextSource,
                                               new List <ExpressionEvaluationStepBatchParams>(), 500,
                                               2000, null));

            var batchSummary = _expressionEvaluationBatch.GetSummary();

            Assert.NotNull(batchSummary.Proto.ExpressionEvaluations);
            Assert.AreEqual(1, batchSummary.Proto.ExpressionEvaluations.Count);

            var expressionEvaluation = batchSummary.Proto.ExpressionEvaluations[0];

            Assert.AreEqual(contextExpected, expressionEvaluation.Context);
        }
        public void RecordSingleEventWithTwoStepsTest()
        {
            const ExpressionEvaluationStrategy strategySource = ExpressionEvaluationStrategy.LLDB;
            const ExpressionEvaluationContext  contextSource  = ExpressionEvaluationContext.FRAME;

            var stepsRecorder = new ExpressionEvaluationRecorder.StepsRecorder(_timeSource);

            using (Step step = stepsRecorder.NewStep(ExpressionEvaluationEngine.LLDB_VARIABLE_PATH))
            {
                step.Finalize(LLDBErrorCode.ERROR);
            }

            using (Step step = stepsRecorder.NewStep(ExpressionEvaluationEngine.LLDB))
            {
                step.Finalize(LLDBErrorCode.OK);
            }

            const long startTimestampUs = 750;
            const long endTimestampUs   = 21562;

            _expressionEvaluationRecorder.Record(strategySource, contextSource, stepsRecorder,
                                                 startTimestampUs, endTimestampUs);

            // Get a copy of the batch summary sent to batchEventAggregator so we can verify
            // that it matches the one being sent to metrics.
            ExpressionEvaluationBatchSummary batchSummary = null;

            _batchEventAggregator.BatchSummaryReady += (_, newSummary) => batchSummary = newSummary;

            _timer.Increment(_minimumBatchSeparationMilliseconds);
            _eventScheduler.Increment(_minimumBatchSeparationMilliseconds);

            const ExpressionEvaluation.Types.Strategy strategyExpected =
                ExpressionEvaluation.Types.Strategy.Lldb;
            const ExpressionEvaluation.Types.Context contextExpected = ExpressionEvaluation.Types
                                                                       .Context.Frame;

            Assert.AreEqual(1, batchSummary.Proto.ExpressionEvaluations.Count);
            ExpressionEvaluation received = batchSummary.Proto.ExpressionEvaluations[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(strategyExpected, received.Strategy);
                Assert.AreEqual(contextExpected, received.Context);
                Assert.NotNull(received.EvaluationSteps);
                Assert.AreEqual(2, received.EvaluationSteps.Count);
                Assert.AreEqual(startTimestampUs, received.StartTimestampMicroseconds);
                Assert.AreEqual(endTimestampUs, received.EndTimestampMicroseconds);
                Assert.Null(received.NatvisValueId);
            });

            const ExpressionEvaluationStep.Types.Engine firstStepEngineExpected =
                ExpressionEvaluationStep.Types.Engine.LldbVariablePath;
            const ExpressionEvaluationStep.Types.EngineResult firstStepEngineResultExpected =
                ExpressionEvaluationStep.Types.EngineResult.LldbError;
            const ExpressionEvaluationStep.Types.Engine secondStepEngineExpected =
                ExpressionEvaluationStep.Types.Engine.Lldb;
            const ExpressionEvaluationStep.Types.EngineResult secondStepEngineResultExpected =
                ExpressionEvaluationStep.Types.EngineResult.LldbOk;

            ExpressionEvaluationStep firstStep  = received.EvaluationSteps[0];
            ExpressionEvaluationStep secondStep = received.EvaluationSteps[1];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(firstStepEngineExpected, firstStep.Engine);
                Assert.AreEqual(firstStepEngineResultExpected, firstStep.Result);
                Assert.AreEqual(1, firstStep.DurationMicroseconds);
                Assert.AreEqual(secondStepEngineExpected, secondStep.Engine);
                Assert.AreEqual(secondStepEngineResultExpected, secondStep.Result);
                Assert.AreEqual(1, secondStep.DurationMicroseconds);
            });

            _metrics.Received(1)
            .RecordEvent(DeveloperEventType.Types.Type.VsiDebugExpressionEvaluationBatch,
                         new DeveloperLogEvent
            {
                DebugExpressionEvaluationBatch = batchSummary.Proto,
                StatusCode = DeveloperEventStatus.Types.Code.Success
            });
        }
        public void RecordSingleEventWithValueContextTest()
        {
            const ExpressionEvaluationStrategy strategySource =
                ExpressionEvaluationStrategy.LLDB_EVAL;
            const ExpressionEvaluationContext contextSource = ExpressionEvaluationContext.VALUE;

            var stepsRecorder = new ExpressionEvaluationRecorder.StepsRecorder(_timeSource);

            using (Step step = stepsRecorder.NewStep(ExpressionEvaluationEngine.LLDB_EVAL))
            {
                step.Finalize(LldbEvalErrorCode.Ok);
            }

            const long startTimestampUs = 750;
            const long endTimestampUs   = 21562;

            // Attempt to record expression evaluation with context Value, without natvisValueId
            // should throw an exception.
            Assert.Throws <ArgumentException>(() =>
            {
                _expressionEvaluationRecorder.Record(
                    strategySource, contextSource, stepsRecorder,
                    startTimestampUs, endTimestampUs);
            });

            const string natvisValueId = "TestId";

            _expressionEvaluationRecorder.Record(strategySource, contextSource, stepsRecorder,
                                                 startTimestampUs, endTimestampUs, natvisValueId);

            // Get a copy of the batch summary sent to batchEventAggregator so we can verify
            // that it matches the one being sent to metrics.
            ExpressionEvaluationBatchSummary batchSummary = null;

            _batchEventAggregator.BatchSummaryReady += (_, newSummary) => batchSummary = newSummary;

            _timer.Increment(_minimumBatchSeparationMilliseconds);
            _eventScheduler.Increment(_minimumBatchSeparationMilliseconds);

            const ExpressionEvaluation.Types.Strategy strategyExpected =
                ExpressionEvaluation.Types.Strategy.LldbEval;
            const ExpressionEvaluation.Types.Context contextExpected =
                ExpressionEvaluation.Types.Context.Value;

            Assert.AreEqual(1, batchSummary.Proto.ExpressionEvaluations.Count);
            ExpressionEvaluation received = batchSummary.Proto.ExpressionEvaluations[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(strategyExpected, received.Strategy);
                Assert.AreEqual(contextExpected, received.Context);
                Assert.NotNull(received.EvaluationSteps);
                Assert.AreEqual(1, received.EvaluationSteps.Count);
                Assert.AreEqual(startTimestampUs, received.StartTimestampMicroseconds);
                Assert.AreEqual(endTimestampUs, received.EndTimestampMicroseconds);
                Assert.AreEqual(natvisValueId, received.NatvisValueId);
            });

            const ExpressionEvaluationStep.Types.Engine stepEngineExpected =
                ExpressionEvaluationStep.Types.Engine.LldbEval;
            const ExpressionEvaluationStep.Types.EngineResult stepEngineResultExpected =
                ExpressionEvaluationStep.Types.EngineResult.LldbEvalOk;

            ExpressionEvaluationStep receivedEvaluationStep = received.EvaluationSteps[0];

            Assert.Multiple(() =>
            {
                Assert.AreEqual(stepEngineExpected, receivedEvaluationStep.Engine);
                Assert.AreEqual(stepEngineResultExpected, receivedEvaluationStep.Result);
                Assert.AreEqual(1, receivedEvaluationStep.DurationMicroseconds);
            });

            _metrics.Received(1)
            .RecordEvent(DeveloperEventType.Types.Type.VsiDebugExpressionEvaluationBatch,
                         new DeveloperLogEvent
            {
                DebugExpressionEvaluationBatch = batchSummary.Proto,
                StatusCode = DeveloperEventStatus.Types.Code.Success
            });
        }