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 17 package android.tools.utils 18 19 import android.tools.Timestamp 20 import android.tools.io.Reader 21 import android.tools.io.RunStatus 22 import android.tools.io.TraceType 23 import android.tools.traces.events.CujTrace 24 import android.tools.traces.events.EventLog 25 import android.tools.traces.protolog.ProtoLogTrace 26 import android.tools.traces.surfaceflinger.LayersTrace 27 import android.tools.traces.surfaceflinger.TransactionsTrace 28 import android.tools.traces.wm.TransitionsTrace 29 import android.tools.traces.wm.WindowManagerTrace 30 31 /** Reads parsed traces from in memory objects */ 32 class ParsedTracesReader( 33 override val artifact: TestArtifact, 34 private val wmTrace: WindowManagerTrace? = null, 35 private val layersTrace: LayersTrace? = null, 36 private val transitionsTrace: TransitionsTrace? = null, 37 private val transactionsTrace: TransactionsTrace? = null, 38 private val eventLog: EventLog? = null, 39 private val protoLogTrace: ProtoLogTrace? = null, 40 private val layerDumps: Map<String, LayersTrace> = emptyMap(), 41 private val wmDumps: Map<String, WindowManagerTrace> = emptyMap(), 42 ) : Reader { 43 // TODO: Refactor all these values out of IReader, they don't totally make sense here 44 45 override val runStatus = RunStatus.UNDEFINED 46 override val executionError = null 47 override val artifactPath: String 48 get() = artifact.absolutePath 49 readLayersTracenull50 override fun readLayersTrace(): LayersTrace? = layersTrace 51 52 override fun readTransactionsTrace(): TransactionsTrace? = transactionsTrace 53 54 override fun readTransitionsTrace(): TransitionsTrace? = transitionsTrace 55 56 override fun readWmTrace(): WindowManagerTrace? = wmTrace 57 58 override fun readEventLogTrace(): EventLog? = eventLog 59 60 override fun readCujTrace(): CujTrace? = eventLog?.cujTrace 61 62 override fun readProtoLogTrace(): ProtoLogTrace? = protoLogTrace 63 64 override fun slice(startTimestamp: Timestamp, endTimestamp: Timestamp): ParsedTracesReader { 65 return ParsedTracesReader( 66 artifact, 67 wmTrace?.slice(startTimestamp, endTimestamp), 68 layersTrace?.slice(startTimestamp, endTimestamp), 69 transitionsTrace?.slice(startTimestamp, endTimestamp), 70 transactionsTrace?.slice(startTimestamp, endTimestamp), 71 eventLog?.slice(startTimestamp, endTimestamp), 72 protoLogTrace?.slice(startTimestamp, endTimestamp), 73 layerDumps, 74 wmDumps 75 ) 76 } 77 readLayersDumpnull78 override fun readLayersDump(tag: String): LayersTrace? = layerDumps[tag] 79 80 override fun readWmState(tag: String): WindowManagerTrace? = wmDumps[tag] 81 82 override fun readBytes(traceType: TraceType, tag: String): ByteArray? { 83 error("Feature not available") 84 } 85 } 86