Example #1
0
        private void debugTreeView_SelectionChanged(object sender, EventArgs e)
        {
            // Color the value according to profiling times.
            if (!MyExecutionBlock.IsProfiling)
            {
                return;
            }

            TreeNodeAdv selectedTreeNode = GetSelectedTreeNode();

            if (selectedTreeNode == null)
            {
                return;
            }

            // Get the relevant children of the current node.
            List <MyDebugNode> children = selectedTreeNode.Children
                                          .Select(child => child.Tag as MyDebugNode)
                                          .Where(childDebugNode => childDebugNode != null && childDebugNode.ProfilerTime != null)
                                          .ToList();

            // Calculate total time of the individual components.
            double totalTime = children.Sum(childDebugNode => childDebugNode.ProfilerTime.Value.TotalMilliseconds);

            // Calculate the colors of the children nodes.
            foreach (MyDebugNode debugNodeChild in children)
            {
                double factor = debugNodeChild.ProfilerTime.Value.TotalMilliseconds / totalTime;

                debugNodeChild.BackgroundColor = Profiling.ItemColor(factor);
            }
        }
Example #2
0
        private void RefreshProfiling()
        {
            if (MyExecutionBlock.IsProfiling)
            {
                m_wasProfiling = true;

                // Maps IMyExecutable to an object that holds both node and its view.
                Dictionary <IMyExecutable, MyNodeView> nodes = Desktop.Nodes.Cast <MyNodeView>()
                                                               .Select(view => new { View = view, Node = view.Node as MyWorkingNode })
                                                               .Where(nodeInfo => nodeInfo.Node != null)
                                                               .ToDictionary(nodeInfo => nodeInfo.Node.ExecutionBlock as IMyExecutable, nodeInfo => nodeInfo.View);

                IDictionary <IMyExecutable, TimeSpan> profilingInfo          = Target.ExecutionBlock.ProfilingInfo;
                Dictionary <IMyExecutable, TimeSpan>  profilingInfoWithTasks = GetProfilingInfoWithTasks(profilingInfo);

                // The total duration of the displayed nodes.
                double sum = profilingInfo.Values.Sum(value => value.TotalMilliseconds);

                foreach (KeyValuePair <IMyExecutable, TimeSpan> profiling in profilingInfoWithTasks)
                {
                    // Find the node that corresponds to the executable.
                    MyNodeView nodeView;
                    if (!nodes.TryGetValue(profiling.Key, out nodeView))
                    {
                        continue;
                    }

                    // Calculate and assign the color to the node.
                    double factor = profiling.Value.TotalMilliseconds / sum;

                    nodeView.BackgroundColor = Profiling.ItemColor(factor);
                }
            }
            else if (m_wasProfiling)
            {
                m_wasProfiling = false;
                ResetNodeColours();
            }
        }