Ejemplo n.º 1
0
        CallTreeNodeViewModel GetViewModelFromPath(IEnumerable <NodePath> paths, SearchInfo info)
        {
            CallTreeNodeViewModel result = null;
            var parent = list.Roots.FirstOrDefault(i => i.Node.Equals(info.ResultRoot));

            foreach (var path in paths)
            {
                var items = parent.Children;
                foreach (var pathId in path.Skip(1))
                {
                    foreach (var item in items)
                    {
                        if (item.Node.NameMapping.Id == pathId)
                        {
                            items  = item.Children;
                            result = item;
                            break;
                        }
                    }
                    if (result == null)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        void ExpandHotPathItems(CallTreeNodeViewModel parent, CallTreeNodeViewModel selectedRoot)
        {
            if ((parent.CpuCyclesSpent / (double)selectedRoot.CpuCyclesSpent) >= 0.2)
            {
                parent.IsExpanded = true;

                foreach (CallTreeNodeViewModel node in parent.Children)
                {
                    ExpandHotPathItems(node, selectedRoot);
                }
            }
        }
Ejemplo n.º 3
0
        void SearchCompleted(SearchInfo?result, AdornerLayer layer, OverlayAdorner ad)
        {
            if (!result.HasValue)
            {
                return;
            }

            CallTreeNodeViewModel item = GetViewModelFromPath(result.Value.Result.GetPathRelativeTo(result.Value.ResultRoot), result.Value);

            if (item != null)
            {
                item.IsSelected = true;
                if (oldSearchResult != null)
                {
                    oldSearchResult.IsSelected = false;
                }
                oldSearchResult = item;
            }
            layer.Remove(ad);
        }
Ejemplo n.º 4
0
        private void CreateTree(List <PiePieceDescriptor> list, CallTreeNodeViewModel parent, double rotation, long totalCycles, int level)
        {
            if (level == 10 || Task.Current.IsCancelled)
            {
                return;
            }

            level++;

            int i = 0;

            foreach (CallTreeNodeViewModel child in parent.Children)
            {
                if (Task.Current.IsCancelled)
                {
                    return;
                }

                double childWedgeAngle;
                childWedgeAngle = child.CpuCyclesSpent * 360.0 / totalCycles;
                if (childWedgeAngle >= 360)
                {
                    childWedgeAngle = 359.9999;
                }
                if (childWedgeAngle > 0.5)
                {
                    PiePieceDescriptor piePiece = new PiePieceDescriptor {
                        Radius = 20, WedgeAngle = childWedgeAngle, RotationAngle = rotation, Level = level, Node = child
                    };
                    list.Add(piePiece);

                    // create pie pieces for children
                    CreateTree(list, child, rotation, totalCycles, level);

                    rotation += childWedgeAngle;

                    i++;
                }
            }
        }
Ejemplo n.º 5
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (SelectedItem is CallTreeNodeViewModel)
            {
                CallTreeNodeViewModel item = SelectedItem as CallTreeNodeViewModel;
                if (e.Key == Key.Right)
                {
                    if (item.IsExpanded)
                    {
                        if (item.Children.Count > 0)
                        {
                            SelectedItem = item.Children.First();
                        }
                    }
                    else
                    {
                        item.IsExpanded = true;
                    }
                    e.Handled = true;
                }
                else if (e.Key == Key.Left)
                {
                    if (item.IsExpanded)
                    {
                        item.IsExpanded = false;
                    }
                    else
                    {
                        SelectedItem = item.Parent;
                    }
                    e.Handled = true;
                }
            }

            if (!e.Handled)
            {
                base.OnKeyDown(e);
            }
        }
Ejemplo n.º 6
0
        void Update(CallTreeNodeViewModel item)
        {
            Debug.WriteLine("RingDiagram.Update: new root = " + item);

            this.task.Cancel();

            Debug.WriteLine("hierarchyStack count: " + this.hierarchyStack.Count);

            while (this.hierarchyStack.Count > 0 && !hierarchyStack.Peek().IsAncestorOf(item))
            {
                this.hierarchyStack.Pop();
            }

            Debug.Assert(hierarchyStack.Count == 0 || hierarchyStack.Peek().IsAncestorOf(item));

            this.Children.Clear();

            if (item == null)
            {
                return;
            }

            List <Shape> newItems = new List <Shape>();

            Ellipse ell = new Ellipse();

            ell.Width               = 40;
            ell.Height              = 40;
            ell.VerticalAlignment   = VerticalAlignment.Center;
            ell.HorizontalAlignment = HorizontalAlignment.Center;
            ell.Fill    = Brushes.Gray;
            ell.Stroke  = Brushes.Black;
            ell.ToolTip = item.CreateToolTip(Translation);
            ell.Tag     = item;

            ell.MouseLeftButtonDown += (sender, e) =>
            {
                if (this.hierarchyStack.Count > 1 && this.hierarchyStack.Peek().Level > 1)
                {
                    var oldItem = this.hierarchyStack.Pop();
                    this.SelectedRoot            = this.hierarchyStack.Peek();
                    this.SelectedRoot.IsSelected = true;
                    this.SelectedRoot.IsExpanded = true;
                    oldItem.IsSelected           = false;
                }
            };

            if (hierarchyStack.Count == 0 || hierarchyStack.Peek() != item)
            {
                this.hierarchyStack.Push(item);
            }

            List <PiePieceDescriptor> pieces = new List <PiePieceDescriptor>();

            this.task.Execute(
                () => {
                if (item.CpuCyclesSpent > 0)
                {
                    CreateTree(pieces, item, 0, item.CpuCyclesSpent, 0);
                }
            },
                () => {
                this.Children.Add(ell);
                this.Children.AddRange(pieces.Select(p => CreatePiePiece(p.Radius, p.WedgeAngle, p.RotationAngle, p.Level, p.Node)));
                item.BringIntoView();
            },
                delegate { }
                );
        }
Ejemplo n.º 7
0
        private PiePiece CreatePiePiece(int rad, double wedgeAngle, double rotationAngle, int level, CallTreeNodeViewModel node)
        {
            // prevent exception when ProfilerHook screws up and children are larger than their parent (e.g. when process is killed)
            if (rotationAngle > 360)
            {
                rotationAngle %= 360;
            }

            PiePiece p = new PiePiece();

            p.Radius              = 20 + level * rad;
            p.InnerRadius         = level * rad;
            p.WedgeAngle          = wedgeAngle;
            p.RotationAngle       = rotationAngle;
            p.Stroke              = Brushes.Black;
            p.ToolTip             = node.CreateToolTip(Translation);
            p.VerticalAlignment   = VerticalAlignment.Center;
            p.HorizontalAlignment = HorizontalAlignment.Center;
            p.Tag = node;

            p.MouseLeftButtonDown += new MouseButtonEventHandler(
                delegate(object sender, MouseButtonEventArgs e) {
                node.IsExpanded    = true;
                node.IsSelected    = true;                      // expand the path to the node so that the treeview can select it
                var oldNode        = this.SelectedRoot;
                this.SelectedRoot  = node;
                oldNode.IsSelected = false;
            }
                );

            HSVColor hsv = new HSVColor {
                Hue        = (float)rotationAngle,
                Saturation = 0.5f,
                Value      = 0.6f - level / 50f
            };

            SolidColorBrush brush = new SolidColorBrush();

            p.Fill = brush;

            Color normalColor = hsv.ToColor();

            hsv.Value = 0.8f;
            Color highlightColor = hsv.ToColor();

            brush.Color = normalColor;

            p.IsMouseDirectlyOverChanged += (sender, e) => {
                if (p.IsMouseDirectlyOver)
                {
                    brush.BeginAnimation(SolidColorBrush.ColorProperty,
                                         new ColorAnimation(highlightColor, new Duration(TimeSpan.FromSeconds(0.5)),
                                                            FillBehavior.HoldEnd));
                }
                else
                {
                    brush.BeginAnimation(SolidColorBrush.ColorProperty,
                                         new ColorAnimation(normalColor, new Duration(TimeSpan.FromSeconds(0.5)),
                                                            FillBehavior.Stop));
                }
            };

            return(p);
        }