public void verify_IntPtr_value_on_creation_of_a_new_tree_node()
        {
            var         ipTest = new UIntPtr(10);
            ProfileNode node   = new ProfileNode(ipTest, 1, 0);

            Assert.AreEqual(new UIntPtr(10), node.FunctionId);
        }
        public void verify_PruneTrees_sets_IgnoreForReporting_flag_to_false_for_nodes_beyond_max_number()
        {
            IThreadProfilingProcessing service = new ThreadProfilingService(null, null, 3);
            ProfileNode node1 = new ProfileNode(new UIntPtr(10), 4, 2);

            service.AddNodeToPruningList(node1);

            ProfileNode node2 = new ProfileNode(new UIntPtr(12), 4, 6);

            service.AddNodeToPruningList(node2);

            ProfileNode node3 = new ProfileNode(new UIntPtr(16), 4, 1);

            service.AddNodeToPruningList(node3);

            ProfileNode node4 = new ProfileNode(new UIntPtr(16), 4, 3);

            service.AddNodeToPruningList(node4);

            service.SortPruningTree();

            Assert.IsFalse(((ProfileNode)service.PruningList[0]).IgnoreForReporting);
            Assert.IsFalse(((ProfileNode)service.PruningList[1]).IgnoreForReporting);
            Assert.IsFalse(((ProfileNode)service.PruningList[2]).IgnoreForReporting);
            Assert.IsTrue(((ProfileNode)service.PruningList[3]).IgnoreForReporting);
        }
Beispiel #3
0
        public int Compare(object x, object y)
        {
            int result = 0;

            ProfileNode left  = x as ProfileNode;
            ProfileNode right = y as ProfileNode;

            if (left.RunnableCount < right.RunnableCount)
            {
                result = 1;
            }
            else if (left.RunnableCount > right.RunnableCount)
            {
                result = -1;
            }
            else
            {
                if (left.Depth > right.Depth)
                {
                    result = 1;
                }
                else if (left.Depth < right.Depth)
                {
                    result = -1;
                }
            }

            return(result);
        }
        private void UpdateTree(ProfileNode parent, UIntPtr[] fids, int fidIndex, uint depth)
        {
            if (fidIndex < 0)
            {
                return;
            }

            var fid   = fids[fidIndex];
            var child = parent.Children
                        .Where(node => node != null)
                        .Where(node => node.FunctionId == fid)
                        .FirstOrDefault();

            if (child != null)
            {
                child.RunnableCount++;
            }
            else
            {
                // If no matching child found, create a new one to recurse into
                child = new ProfileNode(fid, 1, depth);
                parent.AddChild(child);

                // If we just added this node's only child, add it to the pruning list
                if (parent.Children.Count == 1)
                {
                    _service.AddNodeToPruningList(child);
                }
            }

            UpdateTree(child, fids, fidIndex - 1, ++depth);
        }
        public void verify_first_child_added()
        {
            var         ipTest = new UIntPtr(20);
            ProfileNode node   = new ProfileNode(new UIntPtr(), 1, 0);

            node.AddChild(new ProfileNode(ipTest, 1, 0));
            Assert.AreEqual(1, node.Children.Count);
        }
        public void verify_AddNodeToPruningList_really_adds_TreeNode()
        {
            IThreadProfilingProcessing service = new ThreadProfilingService(
                null, null);
            ProfileNode node = new ProfileNode(new UIntPtr(10), 1, 2);

            service.AddNodeToPruningList(node);
            Assert.AreEqual(1, service.PruningList.Count);
        }
        public void verify_first_child_added_has_correct_CallCount_value()
        {
            var         ipRoot = new UIntPtr(1);
            const int   EXPECTED_CALL_COUNT = 12;
            ProfileNode rootProfileNode     = new ProfileNode(ipRoot, 0, 0);

            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(1), EXPECTED_CALL_COUNT, 1));
            Assert.AreEqual(EXPECTED_CALL_COUNT, GetProfileNodeChildByIndex(rootProfileNode, 0).RunnableCount);
        }
        public void verify_first_child_added_has_correct_Depth_value()
        {
            var         ipRoot = new UIntPtr(1);
            const int   EXPECTED_DEPTH_VALUE = 2;
            ProfileNode rootProfileNode      = new ProfileNode(ipRoot, 1, 0);

            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(1), 1, EXPECTED_DEPTH_VALUE));
            Assert.AreEqual(EXPECTED_DEPTH_VALUE, GetProfileNodeChildByIndex(rootProfileNode, 0).Depth);
        }
Beispiel #9
0
        private static void UpdateRunnableCountsForLeafNode(ProfileNode node, IEnumerable <string> nonRunnableLeafNodes)
        {
            var combinedClassMethodName = node.Details.ClassName + ":" + node.Details.MethodName;

            if (!nonRunnableLeafNodes.Contains(combinedClassMethodName))
            {
                return;
            }

            node.NonRunnableCount = node.RunnableCount;
            node.RunnableCount    = 0;
        }
        public void verify_AddNodeToPruningList_adds_correct_number_of_multiple_TreeNodes()
        {
            IThreadProfilingProcessing service = new ThreadProfilingService(null, null);
            uint expectedCount = 5;

            for (uint i = 0; i < expectedCount; i++)
            {
                ProfileNode node = new ProfileNode(new UIntPtr(i), 1, 2);
                service.AddNodeToPruningList(node);
            }
            Assert.AreEqual(expectedCount, service.PruningList.Count);
        }
        public void verify_second_child_added()
        {
            var         ipRoot          = new UIntPtr(1);
            ProfileNode rootProfileNode = new ProfileNode(ipRoot, 1, 0);

            // Add first child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(2), 1, 1));

            // Add second child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(3), 1, 1));
            Assert.AreEqual(2, rootProfileNode.Children.Count);
        }
        public void verify_first_child_added_has_correct_FunctionId()
        {
            var         ipRoot          = new UIntPtr(1);
            ProfileNode rootProfileNode = new ProfileNode(ipRoot, 1, 0);

            const ulong IP_CHILD_VALUE = 175275300;
            var         ipExpected     = new UIntPtr(IP_CHILD_VALUE);
            var         ipChild        = new UIntPtr(IP_CHILD_VALUE);

            rootProfileNode.AddChild(new ProfileNode(ipChild, 1, 1));
            Assert.AreEqual(ipExpected, GetProfileNodeChildByIndex(rootProfileNode, 0).FunctionId);
        }
        private static int GetDepth(ProfileNode node, int currentDepth)
        {
            currentDepth++;

            if (node.Children.Count < 1)
            {
                return(currentDepth);
            }

            return(node.Children
                   .Where(child => child != null)
                   .Select(child => GetDepth(child, currentDepth))
                   .Max());
        }
        public void verify_second_child_added_has_correct_Depth()
        {
            var         ipRoot          = new UIntPtr(1);
            ProfileNode rootProfileNode = new ProfileNode(ipRoot, 1, 0);

            // Add first child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(2), 1, 1));

            const int EXPECTED_DEPTH = 6;

            // Add second child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(11), 1, EXPECTED_DEPTH));
            Assert.AreEqual(EXPECTED_DEPTH, GetProfileNodeChildByIndex(rootProfileNode, 1).Depth);
        }
        public void verify_ResetCache_clears_pruning_list()
        {
            IThreadProfilingProcessing service = new ThreadProfilingService(null, null);
            uint expectedCount = 5;

            for (uint i = 0; i < expectedCount; i++)
            {
                ProfileNode node = new ProfileNode(new UIntPtr(i), 1, 2);
                service.AddNodeToPruningList(node);
            }

            service.ResetCache();
            Assert.AreEqual(0, service.PruningList.Count);
        }
Beispiel #16
0
        public void serializes_correctly_without_children()
        {
            var profileNode = new ProfileNode(new UIntPtr(1), 2, 3);

            profileNode.Details.ClassName  = "myClass";
            profileNode.Details.MethodName = "myMethod";
            profileNode.Details.LineNumber = 4;

            var json = JsonConvert.SerializeObject(profileNode);

            const string expectedJson = @"[[""myClass"",""myMethod"",4],2,0,[]]";

            Assert.AreEqual(expectedJson, json);
        }
        public void verify_second_child_added_has_correct_CallCount()
        {
            var         ipRoot          = new UIntPtr(1);
            ProfileNode rootProfileNode = new ProfileNode(ipRoot, 1, 0);

            // Add first child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(2), 1, 1));

            const int EXPECTED_CALL_COUNT = 12;

            // Add second child.
            rootProfileNode.AddChild(new ProfileNode(new UIntPtr(11), EXPECTED_CALL_COUNT, 1));
            Assert.AreEqual(EXPECTED_CALL_COUNT, GetProfileNodeChildByIndex(rootProfileNode, 1).RunnableCount);
        }
        public void verify_grandchild_added()
        {
            var         ipRoot          = new UIntPtr(1);
            ProfileNode rootProfileNode = new ProfileNode(ipRoot, 1, 0);

            // Add first child.
            ProfileNode child = new ProfileNode(new UIntPtr(2), 1, 1);

            rootProfileNode.AddChild(child);

            // Add grandchild.
            child.AddChild(new ProfileNode(new UIntPtr(3), 1, 1));
            Assert.AreEqual(1, GetProfileNodeChildByIndex(rootProfileNode, 0).Children.Count);
        }
        public void verify_PruneTrees_sorts_two_nodes_with_different_call_counts()
        {
            // Set the max aggregated nodes to 1 so that pruning is triggered.
            IThreadProfilingProcessing service = new ThreadProfilingService(null, null, 1);
            ProfileNode node1 = new ProfileNode(new UIntPtr(10), 4, 1);

            service.AddNodeToPruningList(node1);

            ProfileNode node2 = new ProfileNode(new UIntPtr(12), 5, 1);

            service.AddNodeToPruningList(node2);

            service.SortPruningTree();
            Assert.IsTrue(((ProfileNode)service.PruningList[0]).RunnableCount > ((ProfileNode)service.PruningList[1]).RunnableCount);
        }
Beispiel #20
0
        private static void UpdateRunnableCounts(ProfileNode node, IEnumerable <string> nonRunnableLeafNodes)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Children.Count == 0)
            {
                UpdateRunnableCountsForLeafNode(node, nonRunnableLeafNodes);
            }
            else
            {
                UpdateRunnableCountsForNodeChildren(node, nonRunnableLeafNodes);
            }
        }
        private static void PruneTree(ProfileNode node)
        {
            if (node.Children.Count <= 0)
            {
                return;
            }

            node.Children
            .Where(child => child != null)
            .Where(child => child.IgnoreForReporting)
            .ToList()
            .ForEach(child => node.Children.Remove(child));

            foreach (var kid in node.Children)
            {
                PruneTree(kid);
            }
        }
        private ProfileNode GetProfileNodeChildByIndex(ProfileNode parent, int index)
        {
            ProfileNode node = null;

            if (index < parent.Children.Count)
            {
                int count = 0;
                foreach (ProfileNode n in parent.Children)
                {
                    if (count++ == index)
                    {
                        node = n;
                        break;
                    }
                }
            }
            return(node);
        }
Beispiel #23
0
        public void serializes_correctly_with_children()
        {
            var profileNode1 = new ProfileNode(new UIntPtr(1), 2, 3);

            profileNode1.Details.ClassName  = "myClass1";
            profileNode1.Details.MethodName = "myMethod1";
            profileNode1.Details.LineNumber = 4;

            var profileNode2 = new ProfileNode(new UIntPtr(11), 12, 13);

            profileNode2.Details.ClassName  = "myClass2";
            profileNode2.Details.MethodName = "myMethod2";
            profileNode2.Details.LineNumber = 14;
            profileNode1.Children.Add(profileNode2);

            var json = JsonConvert.SerializeObject(profileNode1);

            const string expectedJson = @"[[""myClass1"",""myMethod1"",4],2,0,[[[""myClass2"",""myMethod2"",14],12,0,[]]]]";

            Assert.AreEqual(expectedJson, json);
        }
        public void verify_PruneTrees_sorts_three_nodes_with_same_call_counts_but_different_depths()
        {
            // Set the max aggregated nodes to 1 so that pruning is triggered.
            IThreadProfilingProcessing service = new ThreadProfilingService(null, null, 1);
            ProfileNode node1 = new ProfileNode(new UIntPtr(10), 4, 2);

            service.AddNodeToPruningList(node1);

            ProfileNode node2 = new ProfileNode(new UIntPtr(12), 4, 6);

            service.AddNodeToPruningList(node2);

            ProfileNode node3 = new ProfileNode(new UIntPtr(16), 4, 1);

            service.AddNodeToPruningList(node3);

            service.SortPruningTree();
            Assert.IsTrue(
                (((ProfileNode)service.PruningList[0]).Depth < ((ProfileNode)service.PruningList[1]).Depth) &&
                (((ProfileNode)service.PruningList[1]).Depth < ((ProfileNode)service.PruningList[2]).Depth));
        }
Beispiel #25
0
        private static void UpdateRunnableCountsForNodeChildren(ProfileNode node, IEnumerable <string> nonRunnableLeafNodes)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            nonRunnableLeafNodes = nonRunnableLeafNodes.ToList();

            foreach (var child in node.Children)
            {
                if (child == null)
                {
                    continue;
                }

                UpdateRunnableCounts(child, nonRunnableLeafNodes);

                node.RunnableCount    -= child.NonRunnableCount;
                node.NonRunnableCount += child.NonRunnableCount;
            }
        }
 private void PopulateNames(ProfileNode node, IDictionary <UIntPtr, ClassMethodNames> namesSource)
 {
     if (node.FunctionId == UIntPtr.Zero)
     {
         node.Details.ClassName  = NativeClassDescriptiveName;
         node.Details.MethodName = NativeFunctionDescriptiveName;
     }
     else
     {
         var id = node.FunctionId;
         if (namesSource.ContainsKey(id) && namesSource[id] != null)
         {
             node.Details.ClassName  = namesSource[id].Class;
             node.Details.MethodName = namesSource[id].Method;
         }
         else
         {
             node.Details.ClassName  = UnknownClassName;
             node.Details.MethodName = UnknownMethodName + '(' + id + ')';
         }
     }
 }
        public void verify_CallCount_value_on_creation_of_a_new_tree_node()
        {
            ProfileNode node = new ProfileNode(new UIntPtr(10), 35, 0);

            Assert.AreEqual(35, node.RunnableCount);
        }
Beispiel #28
0
 public void AddChild(ProfileNode node)
 {
     Children.Add(node);
 }
 public void AddNodeToPruningList(ProfileNode node)
 {
 }
Beispiel #30
0
 public void AddNodeToPruningList(ProfileNode node)
 {
     PruningList.Add(node);
 }