From 07f9bcccf425561a2c4efcac919c67d568d152d0 Mon Sep 17 00:00:00 2001 From: Nataniel Borges Date: Tue, 8 Mar 2022 15:31:58 +0100 Subject: [PATCH] Use lazy file for LayerTraceEntry This speeds up winscope by parsing each state only when necessary Bug: 211049519 Test: build winscope and open a trace Change-Id: I35e362ebcb7927887b2793697037984fa26de61c --- tools/winscope/src/flickerlib/LayersTrace.ts | 4 +- tools/winscope/src/flickerlib/common.js | 3 + .../flickerlib/layers/LayerTraceEntryLazy.ts | 114 ++++++++++++++++++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts diff --git a/tools/winscope/src/flickerlib/LayersTrace.ts b/tools/winscope/src/flickerlib/LayersTrace.ts index 7160d604d..01720114a 100644 --- a/tools/winscope/src/flickerlib/LayersTrace.ts +++ b/tools/winscope/src/flickerlib/LayersTrace.ts @@ -15,12 +15,12 @@ */ import { LayersTrace } from "./common" -import LayerTraceEntry from './layers/LayerTraceEntry' +import LayerTraceEntryLazy from './layers/LayerTraceEntryLazy' LayersTrace.fromProto = function (proto: any): LayersTrace { const entries = [] for (const entryProto of proto.entry) { - const transformedEntry = LayerTraceEntry.fromProto( + const transformedEntry = new LayerTraceEntryLazy( /* protos */ entryProto.layers.layers, /* displays */ entryProto.displays, /* timestamp */ entryProto.elapsedRealtimeNanos, diff --git a/tools/winscope/src/flickerlib/common.js b/tools/winscope/src/flickerlib/common.js index a20b909bc..7538d233d 100644 --- a/tools/winscope/src/flickerlib/common.js +++ b/tools/winscope/src/flickerlib/common.js @@ -56,6 +56,8 @@ const WindowToken = require('flicker').com.android.server.wm.traces.common. // SF const Layer = require('flicker').com.android.server.wm.traces.common. layers.Layer; +const AbstractLayerTraceEntry = require('flicker').com.android.server.wm.traces.common. + layers.AbstractLayerTraceEntry; const LayerTraceEntry = require('flicker').com.android.server.wm.traces.common. layers.LayerTraceEntry; const LayerTraceEntryBuilder = require('flicker').com.android.server.wm.traces. @@ -270,6 +272,7 @@ export { WindowManagerTrace, WindowManagerState, // SF + AbstractLayerTraceEntry, Layer, LayerTraceEntry, LayerTraceEntryBuilder, diff --git a/tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts b/tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts new file mode 100644 index 000000000..035cee7e1 --- /dev/null +++ b/tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts @@ -0,0 +1,114 @@ +/* + * Copyright 2021, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import { AbstractLayerTraceEntry } from "../common"; +import LayerTraceEntry from "./LayerTraceEntry"; + +class LayerTraceEntryLazy extends AbstractLayerTraceEntry { + private _isInitialized: boolean = false; + private _layersProto: any[]; + private _displayProtos: any[]; + timestamp: number; + timestampMs: string; + hwcBlob: string; + where: string; + private _lazyLayerTraceEntry: LayerTraceEntry; + + constructor (layersProto: any[], displayProtos: any[], + timestamp: number, hwcBlob: string, where: string = '') { + super(); + this._layersProto = layersProto; + this._displayProtos = displayProtos; + this.timestamp = timestamp; + this.timestampMs = timestamp.toString(); + this.hwcBlob = hwcBlob; + this.where = where; + + this.declareLazyProperties(); + } + + private initialize() { + if (this._isInitialized) return; + + this._isInitialized = true; + this._lazyLayerTraceEntry = LayerTraceEntry.fromProto( + this._layersProto, this._displayProtos, this.timestamp, + this.hwcBlob, this.where); + this._layersProto = []; + this._displayProtos = []; + } + + + private declareLazyProperties() { + Object.defineProperty(this, 'kind', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.kind; + }}); + + Object.defineProperty(this, 'timestampMs', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.timestampMs; + }}); + + Object.defineProperty(this, 'rects', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.rects; + }}); + + Object.defineProperty(this, 'proto', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.proto; + }}); + + Object.defineProperty(this, 'shortName', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.shortName; + }}); + + Object.defineProperty(this, 'isVisible', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.isVisible; + }}); + + Object.defineProperty(this, 'flattenedLayers', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.flattenedLayers; + }}); + + Object.defineProperty(this, 'stableId', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.stableId; + }}); + + Object.defineProperty(this, 'visibleLayers', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.visibleLayers; + }}); + + Object.defineProperty(this, 'children', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.children; + }}); + + Object.defineProperty(this, 'displays', {configurable: true, enumerable: true, get: function () { + this.initialize(); + return this._lazyLayerTraceEntry.displays; + }}); + } +} + +export default LayerTraceEntryLazy;