1 /* 2 * Copyright (C) 2021 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 17 package com.android.server.wm.traces.common.layers 18 19 import com.android.server.wm.traces.common.ITrace 20 21 /** 22 * Contains a collection of parsed Layers trace entries and assertions to apply over a single entry. 23 * 24 * Each entry is parsed into a list of [LayerTraceEntry] objects. 25 * 26 * This is a generic object that is reused by both Flicker and Winscope and cannot 27 * access internal Java/Android functionality 28 * 29 */ 30 data class LayersTrace( 31 override val entries: Array<LayerTraceEntry>, 32 override val source: String = "" 33 ) : ITrace<LayerTraceEntry>, List<LayerTraceEntry> by entries.toList() { 34 constructor(entry: LayerTraceEntry): this(arrayOf(entry)) 35 toStringnull36 override fun toString(): String { 37 return "LayersTrace(Start: ${entries.first()}, " + 38 "End: ${entries.last()})" 39 } 40 equalsnull41 override fun equals(other: Any?): Boolean { 42 if (this === other) return true 43 if (other !is LayersTrace) return false 44 45 if (!entries.contentEquals(other.entries)) return false 46 if (source != other.source) return false 47 48 return true 49 } 50 hashCodenull51 override fun hashCode(): Int { 52 var result = entries.contentHashCode() 53 result = 31 * result + source.hashCode() 54 return result 55 } 56 57 /** 58 * Split the trace by the start and end timestamp. 59 * 60 * @param from the start timestamp 61 * @param to the end timestamp 62 * @return the subtrace trace(from, to) 63 */ filternull64 fun filter(from: Long, to: Long): LayersTrace { 65 return LayersTrace( 66 this.entries 67 .dropWhile { it.timestamp < from } 68 .dropLastWhile { it.timestamp > to } 69 .toTypedArray(), 70 source = "") 71 } 72 } 73