Example #1
0
 public StackTree(IEnumerable <SampledProfileTraceData> profileEvents)
 {
     Root = new StackTreeNode("ROOT");
     foreach (var profileEvent in profileEvents)
     {
         var frames = Program.StackFramesForProfileEvent(profileEvent);
         MaxDepth = Math.Max(MaxDepth, frames.Length);
         Root.AddStack(frames);
     }
 }
Example #2
0
        private string DisplayTextForNode(StackTreeNode node)
        {
            string weightPct   = String.Format("{0:N2}", node.Weight * 100.0 / _totalTreeWeight);
            string displayText = $"{node.Frame} ({node.Weight} samples, {weightPct}%)";

            displayText = displayText.Replace("<", "&lt;");
            displayText = displayText.Replace(">", "&gt;");
            displayText = displayText.Replace("&", "&amp;");
            displayText = displayText.Replace("\"", "&quot;");
            return(displayText);
        }
Example #3
0
        private StackTreeNode GetOrCreateChild(string frame)
        {
            StackTreeNode child;

            if (!Children.TryGetValue(frame, out child))
            {
                child = new StackTreeNode(frame);
                Children.Add(frame, child);
            }
            return(child);
        }
Example #4
0
        private void WriteStackTreeNode(StackTreeNode node, float startX, float startY)
        {
            float rectWidth = WidthOfRect(node), rectHeight = 20; // TODO
            float textX = startX, textY = startY + (rectHeight - _textPadHeight);
            float rectX = startX, rectY = startY;

            if (rectWidth < _minRectWidth)
            {
                return;
            }

            textX += _textPadWidth;
            float textWidth = rectWidth - 2 * _textPadWidth;

            string displayText = DisplayTextForNode(node);
            string rectColor   = NameColor(node.Frame);

            // Figure out what can fit depending on the fonts
            string shownText;
            int    numChars = (int)(textWidth / _letterWidth);

            if (numChars <= 3)
            {
                shownText = "";
            }
            else
            {
                if (numChars < displayText.Length)
                {
                    shownText = displayText.Substring(0, numChars - 3) + "...";
                }
                else
                {
                    shownText = displayText;
                }
            }

            _output.WriteLine($"<g onmouseover=\"s('{displayText}')\"> onmouseout=\"c()\" onclick=\"zoom(this)\"");
            _output.WriteLine($"<title>{displayText}</title>");
            _output.WriteLine($"<rect x=\"{rectX}\" y=\"{rectY}\" width=\"{rectWidth}\" height=\"{rectHeight}\" fill=\"{rectColor}\" rx=\"2\" ry=\"2\" />");
            _output.WriteLine($"<text text-anchor=\"\" x=\"{textX}\" y=\"{textY}\" font-size=\"{_fontSize}\" font-family=\"{_fontFamily}\" fill=\"rgb(0,0,0)\">{shownText}</text>");
            _output.WriteLine("</g>");

            var   children      = node.Children.Values.ToArray();
            float currentChildX = startX;

            for (int i = 0; i < children.Length; ++i)
            {
                WriteStackTreeNode(children[i], currentChildX, startY + rectHeight);
                currentChildX += WidthOfRect(children[i]); // TODO Add some padding probably
            }
        }
Example #5
0
 private float WidthOfRect(StackTreeNode node)
 {
     return(node.Weight * _width / (1.0f * _totalTreeWeight));
 }