Ejemplo n.º 1
0
        public FoldedStackLine(MethodCallLine methodCallLine, bool includeTimeOfEvent)
        {
            MethodCallLine methodCallLineOriginal = methodCallLine;

            // Allocate some characters per class/method pair
            StringBuilder sbFoldedCallStack = new StringBuilder(128 * methodCallLine.Depth + 1);

            int specialSlotForTime = 0;

            if (includeTimeOfEvent == true)
            {
                specialSlotForTime = 3;
            }

            // Allocate the array for the timings
            this.StackTimingArray = new long[methodCallLine.Depth + 1 + specialSlotForTime];

            // Walk from the leaf up to the parent, building the flattened stack with frames separated by ;
            while (methodCallLine != null)
            {
                if (sbFoldedCallStack.Length > 0)
                {
                    sbFoldedCallStack.Insert(0, ";");
                }
                sbFoldedCallStack.Insert(0, methodCallLine.FullName);
                this.StackTimingArray[methodCallLine.Depth + specialSlotForTime] = methodCallLine.Exec;
                methodCallLine = methodCallLine.Parent;
            }
            if (includeTimeOfEvent == true)
            {
                if (sbFoldedCallStack.Length > 0)
                {
                    sbFoldedCallStack.Insert(0, ";");
                }
                sbFoldedCallStack.Insert(0,
                                         String.Format("{0:yyyyMMddHH};{1};{2:00}",
                                                       methodCallLineOriginal.Occurred,
                                                       get10MinuteRange(methodCallLineOriginal.Occurred.Minute),
                                                       methodCallLineOriginal.Occurred.Minute));
                this.StackTimingArray[0] = 0;
                this.StackTimingArray[1] = 0;
                this.StackTimingArray[2] = 0;
            }

            this.FoldedStack = sbFoldedCallStack.ToString();
            this.NumSamples  = 1;
        }
Ejemplo n.º 2
0
        public FoldedStackLine(MethodCallLine methodCallLine, bool includeTimeOfEvent)
        {
            MethodCallLine methodCallLineOriginal = methodCallLine;

            // Allocate some characters per class/method pair
            StringBuilder sbFoldedCallStack = new StringBuilder(128 * methodCallLine.Depth + 1);

            // Allocate the array for the timings
            int numberOfSpecialSlotsForTime = 0;

            if (includeTimeOfEvent == true)
            {
                numberOfSpecialSlotsForTime = 3;
            }
            this.StackTimingArray = new long[methodCallLine.Depth + 1 + numberOfSpecialSlotsForTime];

            // Allocate some characters for each exit call, assume only 1% of call stack will have exits
            this.ExitCallsArray = new string[methodCallLine.Depth + 1 + numberOfSpecialSlotsForTime];
            for (int i = 0; i < this.ExitCallsArray.Length; i++)
            {
                this.ExitCallsArray[i] = String.Empty;
            }

            // Walk from the leaf up to the parent, building the flattened stack with frames separated by ;
            while (methodCallLine != null)
            {
                // Add stack frame to the beginning of the string
                if (sbFoldedCallStack.Length > 0)
                {
                    sbFoldedCallStack.Insert(0, ";");
                }
                sbFoldedCallStack.Insert(0, methodCallLine.FullName);

                // Add method timing to the array
                this.StackTimingArray[methodCallLine.Depth + numberOfSpecialSlotsForTime] = methodCallLine.Exec;

                // Add exit calls to the array
                if (methodCallLine.NumExits > 0)
                {
                    // Encode the exits because they may contain carriage returns

                    string exitCallsWithTiming = methodCallLine.ExitCalls;

                    Regex regexDuration = new Regex(@"\[\d+ ms( async)?\]", RegexOptions.IgnoreCase);
                    exitCallsWithTiming = regexDuration.Replace(exitCallsWithTiming, "[## ms]");

                    Regex regexSegment = new Regex(@"\/\d+\/ ", RegexOptions.IgnoreCase);
                    exitCallsWithTiming = regexSegment.Replace(exitCallsWithTiming, "");

                    this.ExitCallsArray[methodCallLine.Depth + numberOfSpecialSlotsForTime] = Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(exitCallsWithTiming));
                }

                // Move to parent
                methodCallLine = methodCallLine.Parent;
            }

            if (includeTimeOfEvent == true)
            {
                // Add synthetic frames for Flame Chart
                if (sbFoldedCallStack.Length > 0)
                {
                    sbFoldedCallStack.Insert(0, ";");
                }
                sbFoldedCallStack.Insert(0,
                                         String.Format("{0:yyyyMMddHH};{1};{2:00}",
                                                       methodCallLineOriginal.Occurred,
                                                       get10MinuteRange(methodCallLineOriginal.Occurred.Minute),
                                                       methodCallLineOriginal.Occurred.Minute));
                this.StackTimingArray[0] = 0;
                this.StackTimingArray[1] = 0;
                this.StackTimingArray[2] = 0;
            }

            this.FoldedStack = sbFoldedCallStack.ToString();
            this.NumSamples  = 1;
        }