Beispiel #1
0
 public void AddCaller(CallTreeItem cti)
 {
     Callers.TryGetValue(cti, out int current);
     Callers[cti] = current + 1;
 }
Beispiel #2
0
        public static Dictionary <string, CallTreeItem> GetCallTree(StackSource stacks, out float timePerStack)
        {
            var callTree     = new Dictionary <string, CallTreeItem>(StringComparer.OrdinalIgnoreCase);
            var currentStack = new HashSet <string>();

            void AddRecursively(StackSourceCallStackIndex index, int depth = 0, CallTreeItem parent = null)
            {
                var name = stacks.GetFrameName(stacks.GetFrameIndex(index), false);

                if (name == "BROKEN")
                {
                    return;
                }
                var isRecursion = !currentStack.Add(name);
                var caller      = stacks.GetCallerIndex(index);

                if (!callTree.TryGetValue(name, out var item))
                {
                    callTree.Add(name, item = new CallTreeItem(name));
                }
                if (!isRecursion)
                {
                    item.IncSamples++;
                }
                if (depth == 0)
                {
                    item.Samples++;
                }
                else
                {
                    item.AddCallee(parent);
                }
                parent?.AddCaller(item);

                if (caller != StackSourceCallStackIndex.Invalid)
                {
                    AddRecursively(caller, depth + 1, item);
                }
                if (!isRecursion)
                {
                    currentStack.Remove(name);
                }
            }

            var metric = float.NaN;

            stacks.ForEach(stack => {
                if (float.IsNaN(metric))
                {
                    metric = stack.Metric;
                }
                if (metric != stack.Metric)
                {
                    throw new Exception();
                }
                if (stack.Count != 1)
                {
                    throw new Exception();
                }
                AddRecursively(stack.StackIndex);
                AddRecursively(stack.StackIndex);
            });
            timePerStack = metric;
            return(callTree);
        }
Beispiel #3
0
 public void AddCallee(CallTreeItem cti)
 {
     (_callees ?? (_callees = new Dictionary <CallTreeItem, int>(2))).TryGetValue(cti, out int current);
     _callees[cti] = current + 1;
 }