public static IEnumerable <IClrObjMappingModel> ExtractFromHeap(this IModelMapperFactory factory, IObjectEnumerationFacade objectEnumeration, ClrRuntime runtime)
 {
     foreach (var clrObject in objectEnumeration.ExtractFromRuntime(runtime))
     {
         yield return(factory.BuildModel(clrObject));
     }
 }
        /// <summary>
        /// Provides text statistics for pending <see cref="HttpContext"/> that wait for Redis commands.
        /// <para>Scans thread stacks for <see cref="HttpContext"/> instances, and <see cref="string"/>s that contain 'redis.call' text inside.</para>
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="connectionFactory"></param>
        /// <param name="threadFilter"></param>
        /// <param name="threadStackObjectsFilter"></param>
        /// <param name="factory"></param>
        /// <returns></returns>
        public virtual StringBuilder ExtractRedisPendingCommandsForRequests(IMemoryDumpConnectionPath connection, IClrRuntimeFactory connectionFactory = null,
                                                                            IModelMapperFactory factory = null)
        {
            var runtime = (connectionFactory ?? MDClrRuntimeFactory.Instance).BuildClrRuntime(connection);


            return(ExtractRedisPendingCommandsForRequests(runtime, factory ?? ModelMapperManager.NewMapperFactory));
        }
Ejemplo n.º 3
0
 public ConfigurationFactory(
     IModelMapperFactory modelMapperFactory,
     IDictionary <string, string> properties
     )
 {
     _modelMapperFactory = modelMapperFactory;
     _properties         = properties;
 }
        public static IEnumerable <IClrObjMappingModel> ExtractFromHeap(this IModelMapperFactory factory, IFilteredObjectsProvider clrObjectFilter, string pathToDumpFile, string pathToMsCord = null)
        {
            if (string.IsNullOrEmpty(pathToMsCord))
            {
                MDClrRuntimeFactory.TryGetMscordacPath(pathToDumpFile, out pathToMsCord);
            }
            var connectionDetails = new MDFileConnection(pathToDumpFile, pathToMsCord);

            return(ExtractFromHeap(factory, clrObjectFilter, connectionDetails));
        }
 protected virtual void ExtractCommandOrContext(ClrObject clrObj, IModelMapperFactory factory, ref string command, ref HttpContextMappingModel httpContext)
 {
     if (clrObj.Type?.IsString == true)
     {
         command = clrObj.GetStringSafeFromSelf();
     }
     else
     {
         httpContext = factory.BuildModel(clrObj) as HttpContextMappingModel;
     }
 }
        public static IEnumerable <IClrObjMappingModel> ExtractFromHeapByType(this IModelMapperFactory factory, string typeName, IMemoryDumpConnectionPath connectionDetails)
        {
            var clrObjectFilter = BuildFilterByTypeName(typeName);

            return(ExtractFromHeap(factory, clrObjectFilter, connectionDetails));
        }
        public virtual void ExtractContextAndRedisCommand(ClrThread thread, ThreadStackEnumerator threadStackObjectEnumerator, IModelMapperFactory factory, IDictionary <string, List <HttpContextMappingModel> > contextsByRedisCommands)
        {
            string command = null;
            HttpContextMappingModel httpContext = null;

            foreach (var clrObj in threadStackObjectEnumerator.Enumerate(thread))
            {
                ExtractCommandOrContext(clrObj, factory, ref command, ref httpContext);

                // already extracted both from the thread stack.
                if (!string.IsNullOrEmpty(command) && (httpContext != null))
                {
                    break;
                }
            }

            List <HttpContextMappingModel> httpContextsForGivenRedisCommand = null;

            if (!string.IsNullOrEmpty(command))
            {
                if (!contextsByRedisCommands.ContainsKey(command))
                {
                    httpContextsForGivenRedisCommand = new List <HttpContextMappingModel>();
                    contextsByRedisCommands.Add(command, httpContextsForGivenRedisCommand);
                }
                else
                {
                    httpContextsForGivenRedisCommand = contextsByRedisCommands[command];
                }
            }

            if (httpContext?.HasURL == true && httpContext?.Request != null)
            {
                if (httpContextsForGivenRedisCommand != null)
                {
                    httpContextsForGivenRedisCommand.Add(httpContext);
                }
                else
                {
                    if (!contextsByRedisCommands.ContainsKey("NoCommand"))
                    {
                        contextsByRedisCommands.Add("NoCommand", new List <HttpContextMappingModel>());
                    }

                    var noCommand = contextsByRedisCommands["NoCommand"];
                    noCommand.Add(httpContext);
                }
            }
        }
Ejemplo n.º 8
0
 public SitecoreCacheEnumerator(IModelMapperFactory modelMapper) : base("Sitecore.Caching.CacheManager", "Instance")
 {
     this.modelMapper = modelMapper;
 }
 public static IEnumerable <IClrObjMappingModel> ExtractFromHeap(this IModelMapperFactory factory, IFilteredObjectsProvider clrObjectFilter, ClrRuntime runtime)
 {
     return(ExtractFromHeap(factory, new HeapBasedFacadeObjectEnumerator(clrObjectFilter), runtime));
 }
        public static IEnumerable <IClrObjMappingModel> ExtractFromHeap(this IModelMapperFactory factory, IFilteredObjectsProvider clrObjectFilter, IMemoryDumpConnectionPath connection)
        {
            var runtime = MDClrRuntimeFactory.Instance.BuildClrRuntime(connection);

            return(ExtractFromHeap(factory, clrObjectFilter, runtime));
        }
        public virtual StringBuilder ExtractRedisPendingCommandsForRequests(ClrRuntime runtime, IModelMapperFactory clrObjectToModelFactory)
        {
            var knownObjects = new HashSet <ulong>();

            var threadStackObjectEnumerator = new ThreadStackEnumerator(
                includePossiblyDead: true,
                filter: ThreadStackObjectFilter);

            List <string> commands = new List <string>();

            int totalContexts = 0;
            IDictionary <string, List <HttpContextMappingModel> > httpContextsMappedByRedisCommand = new Dictionary <string, List <HttpContextMappingModel> >();

            foreach (var contextThread in ThreadFilter.ExtactAliveUserThreads(runtime))
            {
                ExtractContextAndRedisCommand(contextThread, threadStackObjectEnumerator, clrObjectToModelFactory, httpContextsMappedByRedisCommand);
            }

            var differentRedisCommands = httpContextsMappedByRedisCommand.OrderByDescending(grouping => grouping.Value.Count);

            var aspNetIDs = (from requestGroup in httpContextsMappedByRedisCommand
                             let httpContexts = requestGroup.Value
                                                from httpContext in httpContexts
                                                let requestInfo = new { httpContext, httpContext?.Request?.AspNetSessionId }
                             group requestInfo by requestInfo.AspNetSessionId into sameSessions
                             select sameSessions).OrderByDescending(t => t.Count()).ToArray();

            var sb = new StringBuilder();

            sb.AppendLine($"Different Commands found: {differentRedisCommands.Count()}");

            totalContexts = httpContextsMappedByRedisCommand.Sum(elem => elem.Value.Count);

            sb.AppendLine($"Total requests {totalContexts} VS unique asp.net sessions {aspNetIDs.Length}");

            foreach (var cmd in differentRedisCommands)
            {
                sb.AppendLine($"Hits: {cmd.Value.Count}");

                sb.AppendLine();
                sb.AppendLine(cmd.Key);

                foreach (var context in cmd.Value.OrderByDescending(request => request.ExecutionDuration))
                {
                    sb.AppendLine(FormatLine(context));
                }
                sb.AppendLine("**************");
            }

            foreach (var session in aspNetIDs)
            {
                sb.AppendLine($"Session: {session.Key}:");
                foreach (var request in session)
                {
                    sb.AppendLine($"{request.httpContext.URL} executed for {request.httpContext.ExecutionDuration.TotalSeconds:F2} sec.");
                }
                sb.AppendLine("**************");
                sb.AppendLine();
            }
            return(sb);
        }
        public static IEnumerable <T> EnumerateObjectsFromHeap <T>(this IFilteredObjectsProvider filteredObjectProvider, IMemoryDumpConnectionPath connection, IModelMapperFactory factory, IClrRuntimeFactory runtimeFactory = null) where T : class, IClrObjMappingModel
        {
            runtimeFactory = runtimeFactory ?? MDClrRuntimeFactory.Instance;

            var runtime = MDClrRuntimeFactory.Instance.BuildClrRuntime(connection);

            var heapObjects = HeapBasedClrObjectEnumerator.Instance;

            var stream = filteredObjectProvider.ExtractFromRuntime(runtime, heapObjects);

            foreach (var matched in stream)
            {
                yield return(factory.BuildOfType <T>(matched));
            }
        }
        public static IEnumerable <TMappingType> ExtractFromHeap <TMappingType>(this IModelMapperFactory factory, IMemoryDumpConnectionPath connectionDetails) where TMappingType : IClrObjMappingModel
        {
            var typeName = ModelMappingAttribute.GetTypeToMapOn(typeof(TMappingType), assert: true);

            return(ExtractFromHeapByType(factory, typeName, connectionDetails).OfType <TMappingType>());
        }
        public static IEnumerable <IClrObjMappingModel> ExtractFromHeapByType(this IModelMapperFactory factory, string typeName, string pathToDumpFile, string pathToMsCord = null)
        {
            var clrObjectFilter = BuildFilterByTypeName(typeName);

            return(ExtractFromHeap(factory, clrObjectFilter, pathToDumpFile, pathToMsCord));
        }
 public static IEnumerable <IClrObjMappingModel> ExtractFromHeapByType(this IModelMapperFactory factory, Type type, string pathToDumpFile, string pathToMsCord = null)
 {
     return(ExtractFromHeapByType(factory, type.FullName, pathToDumpFile, pathToMsCord));
 }
Ejemplo n.º 16
0
        public virtual IOrderedEnumerable <ContactInfo> ExtractRequestsByContact(ClrRuntime runtime, IModelMapperFactory modelMapperFactory)
        {
            var httpContextStreamClrObject = ObjectFilter.ExtractFromRuntime(runtime, ObjectEnumerator);


            var requestsGroupedByContactID = from clrObject in httpContextStreamClrObject
                                             let context = modelMapperFactory.BuildModel(clrObject) as HttpContextMappingModel
                                                           where IsValid(context)

                                                           let request = context._request as HttpRequestMappingModel
                                                                         where request != null

                                                                         let cookies = request._cookies.Value as HashtableMappingModel
                                                                                       where cookies != null

                                                                                       where cookies.Elements.ContainsKey(TextConstants.CookieNames.SitecoreAnalyticsGlobal)
                                                                                       // where cookies.Elements.ContainsKey(TextConstants.CookieNames.AspNetSession)

                                                                                       let analyticsCookie = cookies[TextConstants.CookieNames.SitecoreAnalyticsGlobal] as HttpCookieModel

                                                                                                             let sessionCookie = cookies[TextConstants.CookieNames.AspNetSession] as HttpCookieModel

                                                                                                                                 where !string.IsNullOrEmpty(analyticsCookie.Value)
                                                                                                                                 // where !string.IsNullOrEmpty(sessionCookie.Value)

                                                                                                                                 let workerRequest = context._wr as IIS7WorkerRequestModel

                                                                                                                                                     where workerRequest != null

                                                                                                                                                     let metadata = new
            {
                context.URL,
                TotalSeconds = Math.Round(context.ExecutionDuration.TotalSeconds, 2),
                analyticsId  = analyticsCookie.Value,
                aspSession   = sessionCookie?.Value ?? "[NoSession]",
                context      = context.HexAddress,
                request      = request.HexAddress
            }

            where metadata.TotalSeconds > 0

            group metadata by metadata.request into uniqueRequests

            let uniqueRequest = uniqueRequests.First()

                                group uniqueRequest by uniqueRequest.analyticsId into grouped

                                orderby grouped.Count() descending

                                let contactInfo = new ContactInfo
            {
                ContactId      = grouped.Key,
                Count          = grouped.Count(),
                DistinctAspNet = grouped.Select(g => g.aspSession).Distinct().Count(),
                Requests       = grouped.Select(requestInfo => new RequestInfo
                {
                    URL          = requestInfo.URL,
                    TotalSeconds = requestInfo.TotalSeconds,
                    aspSession   = requestInfo.aspSession,
                    context      = requestInfo.context,
                    request      = requestInfo.request
                }).OrderByDescending(g => g.TotalSeconds),
            }

            select contactInfo;

            return(requestsGroupedByContactID.OrderByDescending(t => t.Count));
        }
Ejemplo n.º 17
0
 public PrintStringBuilders(int minimumTimeMetToPrint = 3, IClrRuntimeFactory runtimeFactory = null, IModelMapperFactory modelMapperFactory = null)
 {
     _minimumTimeMetToPrint = minimumTimeMetToPrint;
     _runtimeFactory        = runtimeFactory ?? MDClrRuntimeFactory.Instance;
     _modelMapperFactory    = modelMapperFactory;
 }
 public static T BuildOfType <T>(this IModelMapperFactory factory, [CanBeNullObject] ClrObject obj) where T : class, IClrObjMappingModel
 {
     return(factory.BuildModel(obj) as T);
 }
 public static IEnumerable <IClrObjMappingModel> ExtractFromHeapByTypeName(this IModelMapperFactory factory, string typeName, ClrRuntime runtime)
 {
     return(ExtractFromHeap(factory, new HeapBasedFacadeObjectEnumerator(typeName), runtime));
 }