diff --git a/tools/winscope-ng/src/parsers/parser.ts b/tools/winscope-ng/src/parsers/parser.ts index 7f35097eb..1b9d937bd 100644 --- a/tools/winscope-ng/src/parsers/parser.ts +++ b/tools/winscope-ng/src/parsers/parser.ts @@ -45,13 +45,19 @@ abstract class Parser { return this.processDecodedEntry(this.decodedEntries[index]); } + public getTraceEntries(): any[] { + throw new Error("Batch retrieval of trace entries not implemented for this parser!" + + " Note that the usage of this functionality is discouraged," + + " since creating all the trace entry objects may consume too much memory."); + } + protected abstract getMagicNumber(): undefined|number[]; protected abstract decodeTrace(buffer: Uint8Array): any[]; protected abstract getTimestamp(decodedEntry: any): number; protected abstract processDecodedEntry(decodedEntry: any): any; - private decodedEntries: any[]; - private timestamps: number[]; + protected decodedEntries: any[]; + protected timestamps: number[]; } export {Parser}; diff --git a/tools/winscope-ng/src/parsers/parser_protolog.spec.ts b/tools/winscope-ng/src/parsers/parser_protolog.spec.ts index 77dd95c61..fd7855672 100644 --- a/tools/winscope-ng/src/parsers/parser_protolog.spec.ts +++ b/tools/winscope-ng/src/parsers/parser_protolog.spec.ts @@ -17,10 +17,20 @@ import {TraceTypeId} from "common/trace/type_id"; import {ParserFactory} from "./parser_factory"; import {Parser} from "./parser"; import {TestUtils} from "test/test_utils"; +import {LogMessage} from '../common/trace/protolog'; describe("ParserProtoLog", () => { let parser: Parser; + const expectedFirstLogMessage = { + text: "InsetsSource updateVisibility for ITYPE_IME, serverVisible: false clientVisible: false", + time: "14m10s746ms", + tag: "WindowManager", + level: "DEBUG", + at: "com/android/server/wm/InsetsSourceProvider.java", + timestamp: Number(850746266486), + }; + beforeAll(() => { const buffer = TestUtils.loadFixture("trace_ProtoLog.pb"); const parsers = new ParserFactory().createParsers([buffer]); @@ -41,15 +51,22 @@ describe("ParserProtoLog", () => { }); it("reconstructs human-readable log message", () => { - const actual = parser.getTraceEntry(850746266486)!; - const expected = { - text: "InsetsSource updateVisibility for ITYPE_IME, serverVisible: false clientVisible: false", - time: "14m10s746ms", - tag: "WindowManager", - level: "DEBUG", - at: "com/android/server/wm/InsetsSourceProvider.java", - timestamp: Number(850746266486), - }; - expect(Object.assign({}, actual)).toEqual(expected); + const actualMessage = parser.getTraceEntry(850746266486)!; + + expect(actualMessage).toBeInstanceOf(LogMessage); + expect(Object.assign({}, actualMessage)).toEqual(expectedFirstLogMessage); + }); + + it("allows retrieving all the log messages", () => { + const actualMessages = parser.getTraceEntries(); + + expect(actualMessages.length).toEqual(50); + + actualMessages.forEach(message => { + expect(message).toBeInstanceOf(LogMessage); + }); + + const actualFirstLogMessage = Object.assign({}, actualMessages[0]); + expect(actualFirstLogMessage).toEqual(expectedFirstLogMessage); }); }); diff --git a/tools/winscope-ng/src/parsers/parser_protolog.ts b/tools/winscope-ng/src/parsers/parser_protolog.ts index 13cc51881..4b888d0a6 100644 --- a/tools/winscope-ng/src/parsers/parser_protolog.ts +++ b/tools/winscope-ng/src/parsers/parser_protolog.ts @@ -75,6 +75,12 @@ class ParserProtoLog extends Parser { } } + override getTraceEntries(): LogMessage[] { + return this.decodedEntries.map((entryProto: any) => { + return this.processDecodedEntry(entryProto); + }); + } + private static readonly MAGIC_NUMBER = [0x09, 0x50, 0x52, 0x4f, 0x54, 0x4f, 0x4c, 0x4f, 0x47]; // .PROTOLOG private static readonly PROTOLOG_VERSION = "1.0.0"; }