Ejemplo n.º 1
0
        static void Time(string description, Action action)
        {
            const int logCount = 2000;

            var timerResult = new TimerResult(description);

            // Warm up
            action();
            var listener = MemoryTraceListener.Instance;

            if (listener != null)
            {
                listener.ClearEvents();
            }
            using (new Timer(timerResult))
            {
                for (var i = 0; i < 2000; i++)
                {
                    action();
                }
            }

            Console.WriteLine(timerResult.Result);
            listener = MemoryTraceListener.Instance;
            Debug.Assert(listener.Events.Count() == logCount);
            listener.ClearEvents();
        }
Ejemplo n.º 2
0
 public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
 {
     context.MessageBroker.Publish(new Message(
                                       new Arguments(context.Arguments), context.InvocationTarget, (System.Web.Routing.VirtualPathData)context.ReturnValue)
                                   .AsTimedMessage(timerResult)
                                   .AsSourceMessage(context.InvocationTarget.GetType(), context.MethodInvocationTarget));
 }
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var displayInfo = context.ReturnValue as DisplayInfo;
                var message     = new Message(displayInfo.DisplayMode.DisplayModeId, displayInfo.FilePath);

                context.MessageBroker.Publish(message);
            }
Ejemplo n.º 4
0
 public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
 {
     context.MessageBroker.Publish(
         new Message(new Arguments(context.Arguments), context.InvocationTarget.GetHashCode(), (bool)context.ReturnValue)
         .AsTimedMessage(timerResult)
         .AsSourceMessage(context.InvocationTarget.GetType(), context.MethodInvocationTarget));
 }
Ejemplo n.º 5
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var original = context.ReturnValue as IValueProvider;

                if (original == null)
                {
                    return;
                }

                var originalUnvalidatedValueProvider = original as IUnvalidatedValueProvider;

                if (originalUnvalidatedValueProvider != null)
                {
                    IUnvalidatedValueProvider newUnvalidatedValueProvider;
                    if (AlternateUnvalidatedValueProvider.TryCreate(originalUnvalidatedValueProvider, out newUnvalidatedValueProvider))
                    {
                        context.ReturnValue = newUnvalidatedValueProvider;
                        return;
                    }
                }

                IValueProvider newValueProvider;

                if (AlternateValidatedValueProvider.TryCreate(original, out newValueProvider))
                {
                    context.ReturnValue = newValueProvider;
                }
            }
Ejemplo n.º 6
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var message = new Message((string)context.Arguments[0], (bool)context.ReturnValue, context.TargetType)
                              .AsSourceMessage(context.TargetType, context.MethodInvocationTarget);

                context.MessageBroker.Publish(message);
            }
        public override void ProcessMessage(SoapMessage message)
        {
            if (GlimpseManager.IsGlimpseActive() == false)
            {
                return;
            }

            switch (message.Stage)
            {
            case SoapMessageStage.BeforeSerialize:
                _result.RequestArgs = GetRequestArgs(message);
                break;

            case SoapMessageStage.AfterSerialize:
                _result.RequestXml = GetXml(_newStream);

                CopyStream(_newStream, _oldStream);
                break;

            case SoapMessageStage.BeforeDeserialize:
                CopyStream(_oldStream, _newStream);
                _result.ResponseXml = GetXml(_newStream);
                break;

            case SoapMessageStage.AfterDeserialize:
                TimerResult dt = GlimpseManager.GetExecutionTimer().Stop(_timer);

                bool   hasError = (message.Exception != null);
                object retVal;
                if (hasError)
                {
                    retVal = message.Exception;
                }
                else if (message.MethodInfo.IsVoid)
                {
                    retVal = "The SOAP call is to a void method";
                }
                else
                {
                    retVal = message.GetReturnValue();
                }

                _result.Url            = message.Url;
                _result.Method         = message.MethodInfo.Name + (hasError ? " - ERROR" : "");
                _result.ResponseResult = retVal;
                _result.Duration       = dt.Duration.Milliseconds + "ms";
                _result.Stacktrace     = new StackTrace(4, true).ToString();
                GlimpseManager.LogMessage(_result);

                var timeline = new SoapTimelineMessage();
                timeline.EventName     = message.MethodInfo.Name + (hasError ? " - ERROR" : "");
                timeline.EventSubText  = message.Url + "\n" + retVal;
                timeline.Offset        = dt.Offset;
                timeline.Duration      = dt.Duration;
                timeline.StartTime     = dt.StartTime;
                timeline.EventCategory = SoapTimelineCategory;
                GlimpseManager.LogMessage(timeline);
                break;
            }
        }
Ejemplo n.º 8
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var args = new Arguments(IsPartial, context.Arguments);
                var id   = Guid.NewGuid();

                var output = context.ReturnValue as ViewEngineResult;

                output = ProxyOutput(output, context, args.ViewName, IsPartial, id);

                string displayModeId   = null;
                Type   displayModeType = null;

#if MVC4
                var displayMode = args.ControllerContext.DisplayMode;
                if (displayMode != null)
                {
                    displayModeId   = displayMode.DisplayModeId;
                    displayModeType = displayMode.GetType();
                }
#endif

                var message = new Message(id, args.ViewName, args.MasterName, args.UseCache, output.SearchedLocations, context.TargetType, IsPartial, output.View != null, displayModeId, displayModeType)
                              .AsActionMessage(args.ControllerContext)
                              .AsChildActionMessage(args.ControllerContext)
                              .AsSourceMessage(context.InvocationTarget.GetType(), context.MethodInvocationTarget)
                              .AsTimedMessage(timerResult);

                context.MessageBroker.Publish(message);
            }
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var displayInfo = context.Arguments[0] as DisplayInfo;
                var master      = context.ReturnValue as string;
                var message     = new Message(displayInfo.DisplayMode.DisplayModeId, master);

                context.MessageBroker.Publish(message);
            }
Ejemplo n.º 10
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var args    = new Arguments(context.Arguments);
                var message = new Message(args.Key, context.ReturnValue as ValueProviderResult, context.TargetType)
                              .AsSourceMessage(context.TargetType, context.MethodInvocationTarget);

                context.MessageBroker.Publish(message);
            }
Ejemplo n.º 11
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var args     = new Arguments(context.Arguments);
                var messages = new Message(args.PropertyDescriptor, context.TargetType)
                               .AsSourceMessage(context.TargetType, context.MethodInvocationTarget);

                context.MessageBroker.Publish(messages);
            }
Ejemplo n.º 12
0
        public static T AsTimedMessage <T>(this T message, TimerResult result) where T : ITimedPerfMonMessage
        {
            message.Duration  = result.Duration;
            message.Offset    = result.Offset;
            message.StartTime = result.StartTime;

            return(message);
        }
Ejemplo n.º 13
0
        public void ShouldBeAbleToBuildWithFactory(TimerResult timerResult, string eventName, TimelineCategoryItem eventCategory, string eventSubText)
        {
            var testMessage = new TestMessage().AsTimelineMessage(eventName, eventCategory, eventSubText);

            Assert.Equal(eventName, testMessage.EventName);
            Assert.Equal(eventCategory, testMessage.EventCategory);
            Assert.Equal(eventSubText, testMessage.EventSubText);
        }
Ejemplo n.º 14
0
        public void ShouldBeAbleToBuildWithFactory(TimerResult timerResult)
        {
            var testMessage = new TestMessage().AsTimedMessage(timerResult);

            Assert.Equal(timerResult.Offset, testMessage.Offset);
            Assert.Equal(timerResult.Duration, testMessage.Duration);
            Assert.Equal(timerResult.StartTime, testMessage.StartTime);
        }
 protected void PublishTimingMessage(TimerResult timed, ITimelineMessage message, ITabSetupContext context)
 {
     context.MessageBroker.Publish(new StatsdNetMessage()
     {
         Id            = Guid.NewGuid(),
         EventName     = "GlimpseStatsdNetTiming: " + message.EventName,
         EventCategory = new TimelineCategoryItem("StatsdNet", "black", "grey")
     }.AsTimedMessage(timed));
 }
Ejemplo n.º 16
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                IModelBinder newModelBinder;

                if (AlternateModelBinder.TryCreate(context.ReturnValue as IModelBinder, out newModelBinder))
                {
                    context.ReturnValue = newModelBinder;
                }
            }
        protected TimerResult InitializeTimer(ITimelineMessage message)
        {
            var timer = new TimerResult();

            timer.StartTime = DateTime.Now;
            timer.Offset    = message.Offset + (timer.StartTime.Subtract(message.StartTime));

            return(timer);
        }
Ejemplo n.º 18
0
 private static void PublishToTimeline(TimerResult result, string category, string message)
 {
     GlimpseRuntime.Instance.Configuration.MessageBroker.Publish(new PipelineMessage {
         Id = Guid.NewGuid()
     }
                                                                 .AsTimedMessage(result)
                                                                 .AsTimelineMessage(message, new TimelineCategoryItem(category, "#999", "#bbb"))
                                                                 );
 }
Ejemplo n.º 19
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var mixin = (IRouteNameMixin)context.Proxy;

                context.MessageBroker.Publish(
                    new Message(context.Proxy.GetHashCode(), (System.Web.Routing.RouteData)context.ReturnValue, mixin.Name)
                    .AsTimedMessage(timerResult)
                    .AsSourceMessage(context.InvocationTarget.GetType(), context.MethodInvocationTarget));
            }
        public void BuildDetails(TimerResult timerResult, string controllerName, string actionName, FilterBounds bounds, FilterCategory filterCategory, Type resultType, bool isChildAction, Type executedType, MethodInfo method, string eventName, Core.Message.TimelineCategory eventCategory)
        {
            var message = new BoundedFilterMessage(timerResult, controllerName, actionName, bounds, filterCategory, resultType, isChildAction, executedType, method, eventName, eventCategory);

            var dictionary = new Dictionary <string, object>();

            message.BuildDetails(dictionary);

            Assert.Equal(4, dictionary.Count);
        }
Ejemplo n.º 21
0
 private static void Timeline(string message, TimerResult timer)
 {
     if (!Enabled)
     {
         return;
     }
     Publish(new RavenDbTimelineMessage()
             .AsTimelineMessage(message, RavenDbTimelineMessage.RavenDbTimelineCategory)
             .AsTimedMessage(timer));
 }
Ejemplo n.º 22
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var dataBindParameterModel = (DataBindParameterModel)HttpContext.Current.Items["_GlimpseWebFormModelBinding"];

                if (dataBindParameterModel != null)
                {
                    var bindingContext = (ModelBindingContext)context.Arguments[1];
                    dataBindParameterModel.DataBindParameters.Add(new ModelBindParameter(bindingContext.ModelName, bindingContext.ValueProvider.GetType().Name.Replace("ValueProvider", null), bindingContext.Model));
                }
            }
Ejemplo n.º 23
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timing)
            {
                var mixin   = context.Proxy as IViewCorrelationMixin;
                var args    = new Arguments(context.Arguments);
                var message = new Message(args.ViewContext.ViewData.Model.GetTypeOrNull(), args.ViewContext.ViewData.ModelState.IsValid, args.ViewContext.TempData, args.ViewContext.ViewData, args.ViewContext.ViewData.ModelMetadata, context.TargetType, mixin)
                              .AsActionMessage(args.ViewContext.Controller)
                              .AsTimedMessage(timing)
                              .AsMvcTimelineMessage(MvcTimelineCategory.View);

                context.MessageBroker.Publish(message);
            }
        private static void Timeline(string message, TimerResult timer)
        {
            if (!ProfilingEnabled)
            {
                return;
            }

            InspectorContext.MessageBroker.Publish(
                new Messages.ConnectionActivityTimeline()
                .AsTimelineMessage(message, Messages.ConnectionActivityTimeline.TimelineCategory)
                .AsTimedMessage(timer));
        }
Ejemplo n.º 25
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var args    = new Arguments(context.Arguments);
                var message = new Message()
                              .AsTimedMessage(timerResult)
                              .AsSourceMessage(args.ActionResult.GetType(), executedMethod)
                              .AsChildActionMessage(args.ControllerContext)
                              .AsActionMessage(args.ControllerContext)
                              .AsMvcTimelineMessage(MvcTimelineCategory.Controller);

                context.MessageBroker.Publish(message);
            }
Ejemplo n.º 26
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var controller = context.ReturnValue as Controller;

                var args    = new Arguments(context.Arguments);
                var message = new Message(args.ControllerName, controller)
                              .AsSourceMessage(context.TargetType, context.MethodInvocationTarget);

                context.MessageBroker.Publish(message);

                ProxyActionInvoker(controller);
            }
Ejemplo n.º 27
0
            public override void PostImplementation(IAlternateMethodContext context, TimerResult timerResult)
            {
                var authorizationContext = (AuthorizationContext)context.Arguments[0];
                var message = new Message()
                              .AsTimedMessage(timerResult)
                              .AsSourceMessage(context.InvocationTarget.GetType(), context.MethodInvocationTarget)
                              .AsActionMessage(authorizationContext.ActionDescriptor)
                              .AsChildActionMessage(authorizationContext.Controller)
                              .AsFilterMessage(FilterCategory.Authorization, authorizationContext.GetTypeOrNull())
                              .AsMvcTimelineMessage(MvcTimelineCategory.Filter);

                context.MessageBroker.Publish(message);
            }
Ejemplo n.º 28
0
        public void Construct(TimerResult timerResult, string controllerName, string actionName, bool isChildAction, Type executedType, MethodInfo method)
        {
            var message = new ActionMessage(timerResult, controllerName, actionName, isChildAction, executedType, method);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod);
            Assert.Equal(controllerName, message.ControllerName);
            Assert.Equal(actionName, message.ActionName);
            Assert.Equal(string.Format("{0}:{1}", controllerName, actionName), message.EventName);
        }
Ejemplo n.º 29
0
        public void BuildDetails(TimerResult timerResult, bool isChildAction, Type executedType, MethodInfo method, string eventName, TimelineCategory eventCategory)
        {
            var message = new ActionBaseMessage(timerResult, isChildAction, executedType, method, eventName, eventCategory);

            var dictionary = new Dictionary <string, object>();

            message.BuildDetails(dictionary);

            Assert.Equal(3, dictionary.Count);
            Assert.Equal(isChildAction, dictionary["IsChildAction"]);
            Assert.Equal(method.Name, dictionary["ExecutionMethod"]);
            Assert.Equal(executedType, dictionary["ExecutedType"]);
        }
Ejemplo n.º 30
0
        public void Construct(TimerResult timerResult, bool isChildAction, Type executedType, MethodInfo method, string eventName, TimelineCategory eventCategory)
        {
            var message = new ActionBaseMessage(timerResult, isChildAction, executedType, method, eventName, eventCategory);

            Assert.Equal(timerResult.Duration, message.Duration);
            Assert.Equal(timerResult.Offset, message.Offset);
            Assert.Equal(timerResult.StartTime, message.StartTime);
            Assert.Equal(eventName, message.EventName);
            Assert.Equal(eventCategory, message.EventCategory);
            Assert.Equal(eventCategory, message.EventCategory);
            Assert.Equal(executedType, message.ExecutedType);
            Assert.Equal(method, message.ExecutedMethod);
        }