Esempio n. 1
0
        internal void SetCalls(CallRecord[] calls, int callCount)
        {
            var compacted = new CallRecord[callCount];

            Calls = compacted;

            Array.Copy(calls, compacted, callCount);
        }
Esempio n. 2
0
        private void ParseLoop()
        {
            int    depth = 0;
            string name;

            var stream = reader.BaseStream;

            int callNodeCount = 0;

            CallRecord[] calls     = new CallRecord[600];
            ProfileFrame lastFrame = null;

            long         Length   = stream.Length;
            int          maxDepth = 0;
            ProfileFrame frame    = null;

            while ((int)reader.TotalRead < Length)
            {
                byte typeByte = reader.ReadByte();
                var  type     = (PlogEntryType)(typeByte >> 5);


                switch (type)
                {
                case PlogEntryType.Frame:
                    depth = 1;

                    if (lastFrame != null)
                    {
                        CompleteFrame(calls, callNodeCount, maxDepth);
                        maxDepth = callNodeCount = 0;
                        _markers.Clear();
                    }
                    frame     = ReadFrame(lastFrame);
                    lastFrame = frame;
                    break;

                case PlogEntryType.NameId:
                    int ppId = reader.ReadPPId(typeByte);
                    name = readString();
                    ppMap.Add(ppId, name);
                    break;

                case PlogEntryType.Call:
                case PlogEntryType.CallAndDepthInc:

                    calls[callNodeCount].ppid      = reader.ReadPPId(typeByte);
                    calls[callNodeCount].Depth     = (ushort)depth;
                    calls[callNodeCount].CallCount = Math.Max(1, readVarInt());
                    calls[callNodeCount].Time      = readVarInt();
                    //calls[callNodeCount].listPosition = (byte)(type == PlogEntyType.CallAndDepthInc ? 0 : 3);
                    callNodeCount++;

                    if ((callNodeCount + 1) > calls.Length)
                    {
                        var newList = new CallRecord[callNodeCount + 200];

                        Array.Copy(calls, newList, callNodeCount);
                        calls = newList;
                    }

                    if (type == PlogEntryType.CallAndDepthInc)
                    {
                        depth++;
                        maxDepth = Math.Max(maxDepth, depth);
                    }
                    break;

                case PlogEntryType.CallDepthDec:
                    if (callNodeCount != 0)
                    {
                        // calls[callNodeCount - 1].listPosition = 1;
                    }
                    //Debug.Assert((depth-1) >= 0);
                    depth = Math.Max(depth - 1, 0);
                    break;

                case PlogEntryType.NetworkStats:
                    ReadNetworkStats();
                    break;

                case PlogEntryType.Extended:
                    var id = (ExtendedSection)((reader.ReadByte() << 5) | (typeByte & 0xF));
                    ReadExtenedSection(id);
                    break;

                default:
                    throw new Exception("Unknown profile section");
                }
            }

            CompleteFrame(calls, callNodeCount, maxDepth);

            return;
        }