コード例 #1
0
 public ProfileThread(ProfileFrame frame, int nameId, string name)
 {
     Debug.Assert(name != null);
     Frame     = frame;
     Name      = name;
     NameId    = nameId;
     NodeCount = -1;
 }
コード例 #2
0
        private ProfileFrame ReadFrame(ProfileFrame prev)
        {
            long endTime      = (long)reader.readVarInt64();
            int  sectionCount = reader.ReadByte();

            if (StartTime == 0)
            {
                StartTime = endTime;
            }
            else
            {
                endTime = endTime - StartTime;
            }

            var sections = new ProfileSection[sectionCount];

            for (int i = 0; i < sectionCount; i++)
            {
                var sectionTime = readVarInt();

                sections[i] = new ProfileSection()
                {
                    Time  = sectionTime,
                    Ratio = 0,
                };
            }

            _currentframe = new ProfileFrame(this, frameCount, endTime, sections);
            frameCount++;

            if (prev != null)
            {
                _currentframe.SetStartTime(prevTime);
            }
            prevTime = endTime;

            return(_currentframe);
        }
コード例 #3
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;
        }