Beispiel #1
0
        private static XElement BuildReportXmlRec(Measurement measurement, /* int level,*/ long totalTime, long parentTime, bool parallel, string id)
        {
            long persentTotal = (measurement.TotalTime * 100) / totalTime;

            long ownTime = measurement.TotalTime - measurement.Nodes.Select(childNode => childNode.TotalTime).Sum();

            var entityToken = measurement.EntityTokenFactory != null ? measurement.EntityTokenFactory() : null;
            string serializedEntityToken = entityToken != null
                ? EntityTokenSerializer.Serialize(entityToken, true)
                : null;

            var result = new XElement("Measurement",
                                      new XAttribute("_id", id),
                                      new XAttribute("title", measurement.Name),
                                      new XAttribute("totalTime", measurement.TotalTime),
                                      new XAttribute("ownTime", ownTime),
                                      new XAttribute("persentFromTotal", persentTotal),
                                      new XAttribute("parallel", parallel.ToString().ToLowerInvariant()));

            if (serializedEntityToken != null)
            {
                result.Add(new XAttribute("entityToken", serializedEntityToken));
            }

            if (measurement.MemoryUsage != 0)
            {
                result.Add(new XAttribute("memoryUsageKb", measurement.MemoryUsage / 1024));
            }

            int index = 0;
            foreach (var childNode in measurement.Nodes)  // .OrderByDescending(c => c.TotalTime)
            {
                result.Add(BuildReportXmlRec(childNode, totalTime, measurement.TotalTime, false, (id + "|" + index)));
                index++;
            }

            foreach (var childNode in measurement.ParallelNodes) // .OrderByDescending(c => c.TotalTime)
            {
                result.Add(BuildReportXmlRec(childNode, totalTime, measurement.TotalTime, true, (id + "|" + index)));
                index++;
            }  

            return result;
        }
Beispiel #2
0
        /// <exclude />
        public static XElement BuildReportXml(Measurement measurement)
        {
            int index = 0;

            var result = new XElement("Measurements", new XAttribute("MemoryUsageKb", measurement.MemoryUsage / 1024));

            foreach (var node in measurement.Nodes)
            {
                result.Add(BuildReportXmlRec(node, node.TotalTime, node.TotalTime, false, index.ToString()));
                index++;
            }

            foreach (var node in measurement.ParallelNodes)
            {
                result.Add(BuildReportXmlRec(node, node.TotalTime, node.TotalTime, true, index.ToString()));
                index++;
            }

            return result;
        }
Beispiel #3
0
        internal static void AddSubMeasurement(Measurement measurement)
        {
            Verify.ArgumentNotNull(measurement, "measurement");

            Measurement currentNode;
            Stack<Measurement> stack;
            bool isInParallel;

            if (!GetCurrentNode(out currentNode, out stack, out isInParallel))
            {
                return;
            }

            if (isInParallel)
            {
                lock (currentNode.SyncRoot)
                {
                    currentNode.ParallelNodes.Add(measurement);
                }
            }
            else
            {
                currentNode.Nodes.Add(measurement);
            }
        }
Beispiel #4
0
        private static bool GetCurrentNode(
            out Measurement parentNode, 
            out Stack<Measurement> stack,
            out bool isInParallel)
        {
            if (Disabled)
            {
                parentNode = null;
                stack = null;
                isInParallel = false;
                return false;
            }

            ThreadDataManagerData currentThreadData = ThreadDataManager.Current;
            ThreadDataManagerData threadData = currentThreadData;

            isInParallel = false;
            while (threadData != null)
            {
                if (threadData.HasValue(ProfilerKey))
                {
                    stack = threadData[ProfilerKey] as Stack<Measurement>;

                    if (stack.Count > 0)
                    {
                        parentNode = stack.Peek();

                        return true;
                    }
                }

                // Going to parent thread
                threadData = threadData.Parent;
                isInParallel = true;
            }

            stack = null;
            parentNode = null;
            return false;
        }
Beispiel #5
0
            public InfoCollector(Measurement parentNode, string name, bool isInParallel, Stack<Measurement> stack, Func<EntityToken> entityTokenFactory)
            {
                _stack = stack;

                _node = new Measurement(name)
                {
                    EntityTokenFactory = entityTokenFactory,
#if ProfileMemory
                    MemoryUsage = GC.GetTotalMemory(false)
#endif
                };




                if (isInParallel)
                {
                    lock (parentNode.SyncRoot)
                    {
                        parentNode.ParallelNodes.Add(_node);
                    }
                }
                else
                {
                    parentNode.Nodes.Add(_node);
                }

                stack.Push(_node);
                
                _stopwatch = Stopwatch.StartNew();
            }