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