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
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
114
tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts
Normal file
114
tools/winscope/src/flickerlib/layers/LayerTraceEntryLazy.ts
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user