コード例 #1
0
        public CtfReader(Stream stream, CtfMetadata metadata, CtfStream ctfStream)
        {
            _handle           = GCHandle.Alloc(_buffer, GCHandleType.Pinned);
            _stream           = stream;
            _metadata         = metadata;
            _streamDefinition = ctfStream;

            ResetBuffer();
        }
コード例 #2
0
ファイル: CtfMetadata.cs プロジェクト: lelonek1/perfview-1
        public void Load(CtfMetadataParser parser)
        {
            Dictionary <string, CtfMetadataType> typeAlias = new Dictionary <string, CtfMetadataType>();
            List <CtfStream> streams = new List <CtfStream>();

            foreach (CtfMetadataDeclaration entry in parser.Parse())
            {
                switch (entry.Definition)
                {
                case CtfDeclarationTypes.Clock:
                    CtfClock clock = new CtfClock(entry.Properties);
                    _clocks[clock.Name] = clock;
                    break;

                case CtfDeclarationTypes.Trace:
                    Trace = new CtfTrace(entry.Properties);
                    break;

                case CtfDeclarationTypes.Environment:
                    Environment = new CtfEnvironment(entry.Properties);
                    break;

                case CtfDeclarationTypes.TypeAlias:
                    typeAlias[entry.Name] = entry.Type;
                    break;

                case CtfDeclarationTypes.Struct:
                    typeAlias[entry.Name] = new CtfStruct(entry.Properties, entry.Fields);
                    break;

                case CtfDeclarationTypes.Stream:
                    CtfStream stream = new CtfStream(entry.Properties);
                    while (streams.Count <= stream.ID)
                    {
                        streams.Add(null);
                    }

                    streams[stream.ID] = stream;
                    break;

                case CtfDeclarationTypes.Event:
                    CtfEvent evt = new CtfEvent(entry.Properties);
                    streams[evt.Stream].AddEvent(evt);
                    break;

                default:
                    Debug.Fail("Unknown metadata entry type.");
                    break;
                }
            }

            Streams = streams.ToArray();
            ResolveReferences(typeAlias);
        }
コード例 #3
0
ファイル: CtfChannel.cs プロジェクト: lelonek1/perfview-1
        private bool ReadTraceHeader()
        {
            // Read Trace Header
            CtfStruct traceHeader = _metadata.Trace.Header;

            int traceHeaderSize = traceHeader.GetSize();

            if (traceHeaderSize == CtfEvent.SizeIndeterminate)
            {
                throw new FormatException("Unexpected metadata format.");
            }

            int magicOffset = traceHeader.GetFieldOffset("magic");

            if (magicOffset < 0)
            {
                throw new FormatException("Unexpected metadata format: No magic field.");
            }

            int streamIdOffset = traceHeader.GetFieldOffset("stream_id");

            if (streamIdOffset < 0)
            {
                throw new FormatException("Unexpected metadata format: No stream_id field.");
            }

            // Convert to bytes instead of bits
            magicOffset     /= 8;
            streamIdOffset  /= 8;
            traceHeaderSize /= 8;

            if (_stream.Read(_buffer, 0, traceHeaderSize) != traceHeaderSize)
            {
                return(false);
            }

#if DEBUG
            _fileOffset += traceHeaderSize;
#endif

            uint magic = BitConverter.ToUInt32(_buffer, magicOffset);
            if (magic != 0xc1fc1fc1)
            {
                throw new FormatException("Unknown magic number in trace header.");
            }

            uint streamId = BitConverter.ToUInt32(_buffer, streamIdOffset);
            _ctfStream = _metadata.Streams[streamId];

            return(true);
        }