1/* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {Event, EventLogParser} from 'trace/flickerlib/common'; 18import {RealTimestamp, Timestamp, TimestampType} from 'trace/timestamp'; 19import {TraceType} from 'trace/trace_type'; 20import {AbstractParser} from './abstract_parser'; 21 22class ParserEventLog extends AbstractParser<Event> { 23 override getTraceType(): TraceType { 24 return TraceType.EVENT_LOG; 25 } 26 27 override getMagicNumber(): number[] { 28 return ParserEventLog.MAGIC_NUMBER; 29 } 30 31 override decodeTrace(buffer: Uint8Array): Event[] { 32 const eventLog = EventLogParser.prototype.parse(buffer); 33 34 return eventLog.entries; 35 } 36 37 override getTimestamp(type: TimestampType, entry: any): undefined | Timestamp { 38 if (type === TimestampType.REAL) { 39 return new RealTimestamp(BigInt(entry.timestamp.unixNanos)); 40 } 41 return undefined; 42 } 43 44 override processDecodedEntry(index: number, timestampType: TimestampType, entry: Event): Event { 45 return entry; 46 } 47 48 private static readonly MAGIC_NUMBER: number[] = Array.from(new TextEncoder().encode('EventLog')); 49} 50 51export {ParserEventLog}; 52