public void Parse(string blockName)
        {
            List <string> types          = new List <string>();
            int           recursionLevel = 0;
            Call          baseCall       = new Call("Engine");
            Call          curCall        = baseCall;

            _infos.Clear();
            _details = new CallDetails();
            _stream.Seek(-4, SeekOrigin.End);
            uint endMagic = _stream.ReadU32(32);

            if (endMagic == 0xDEADCAFE)
            {
                _stream.Seek(-12, SeekOrigin.End);
                _length = _stream.ReadU64(64);

                if (_length > _stream.Length())
                {
                    _length     = _stream.Length();
                    _terminated = false;
                }
                else
                {
                    _terminated = true;
                }
            }
            else
            {
                _length     = _stream.Length();
                _terminated = false;
            }

            _stream.Seek(0, SeekOrigin.Begin);
            uint startMagic = _stream.ReadU32(32);

            if (startMagic != 0xDEADCAFE)
            {
                throw new ErrorException("Unrecognized file format.");
            }

            _profilerVersion = _stream.ReadU32(16);
            _wseVersionMajor = _stream.ReadU32(16);
            _wseVersionMinor = _stream.ReadU32(16);
            _wseVersionBuild = _stream.ReadU32(16);
            _frequency       = (float)_stream.ReadU64(64);
            _overhead        = _stream.ReadU64(64);
            _totalTime       = 0;

            while (_stream.Position() < _length)
            {
                var type = _stream.ReadU32(1);

                if (type == 0)
                {
                    var rec = _stream.ReadU32(1);
                    var bci = _stream.ReadBCI15();

                    if (rec > 0)
                    {
                        var call = new Call(types[(int)bci], curCall);

                        curCall.Children.Add(call);
                        curCall = call;
                        recursionLevel++;
                    }
                    else
                    {
                        ulong time = bci - _overhead;

                        if (time < 0)
                        {
                            time = 0;
                        }

                        curCall.Time = time * 1000000 / _frequency;

                        if (curCall.Id == blockName)
                        {
                            _details.AddCall(curCall);
                        }

                        curCall = curCall.Parent;
                        recursionLevel--;
                    }

                    if (curCall == baseCall)
                    {
                        if (blockName == "")
                        {
                            if (curCall.Children.Count != 1)
                            {
                                throw new Exception("Base call with multiple children.");
                            }

                            _totalTime += curCall.Children[0].TimeRecursive;
                            ParseCall(curCall.Children[0]);
                        }

                        curCall.Children.Clear();
                    }
                }
                else if (type == 1)
                {
                    types.Add(_stream.ReadString());
                }
            }

            if (recursionLevel != 0)
            {
                this.ShowWarning("Final block depth non-zero. Is the profiling file damaged or incomplete?");

                var call = curCall;

                while (call != null)
                {
                    ParseCall(call);
                    call = call.Parent;
                }
            }
        }
 public void Close()
 {
     _infos.Clear();
     _details = null;
     GC.Collect();
 }