• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.common.traces.surfaceflinger
18 
19 import android.tools.common.ITrace
20 import android.tools.common.Timestamp
21 import kotlin.js.JsExport
22 import kotlin.js.JsName
23 
24 @JsExport
25 class TransactionsTrace(override val entries: Array<TransactionsTraceEntry>) :
26     ITrace<TransactionsTraceEntry> {
27 
28     init {
29         val alwaysIncreasing =
30             entries
31                 .toList()
32                 .zipWithNext { prev, next ->
33                     prev.timestamp.elapsedNanos < next.timestamp.elapsedNanos
34                 }
35                 .all { it }
36         require(alwaysIncreasing) { "Transaction timestamp not always increasing..." }
37     }
38 
39     @JsName("allTransactions")
40     val allTransactions: List<Transaction> = entries.toList().flatMap { it.transactions.toList() }
41 
42     override fun slice(startTimestamp: Timestamp, endTimestamp: Timestamp): TransactionsTrace {
43         return TransactionsTrace(
44             entries
45                 .dropWhile { it.timestamp < startTimestamp }
46                 .dropLastWhile { it.timestamp > endTimestamp }
47                 .toTypedArray()
48         )
49     }
50 }
51