blob: 33d1e1145abdd6aaeb9f801795bae9ecfa4fbca2 [file] [log] [blame]
/*
* Copyright (C) 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.
*/
@file:JvmName("Extensions")
package com.android.server.wm.flicker.monitor
import com.android.server.wm.traces.common.DeviceTraceDump
import com.android.server.wm.traces.common.layers.LayersTrace
import com.android.server.wm.traces.common.windowmanager.WindowManagerTrace
import com.android.server.wm.traces.parser.DeviceDumpParser
import com.android.server.wm.traces.parser.layers.LayersTraceParser
import com.android.server.wm.traces.parser.windowmanager.WindowManagerTraceParser
/**
* Acquire the [WindowManagerTrace] with the device state changes that happen when executing the
* commands defined in the [predicate].
*
* @param predicate Commands to execute
* @throws UnsupportedOperationException If tracing is already activated
*/
fun withWMTracing(predicate: () -> Unit): WindowManagerTrace {
return WindowManagerTraceParser().parse(WindowManagerTraceMonitor().withTracing(predicate))
}
/**
* Acquire the [LayersTrace] with the device state changes that happen when executing the commands
* defined in the [predicate].
*
* @param traceFlags Flags to indicate tracing level
* @param predicate Commands to execute
* @throws UnsupportedOperationException If tracing is already activated
*/
@JvmOverloads
fun withSFTracing(
traceFlags: Int = LayersTraceMonitor.TRACE_FLAGS,
predicate: () -> Unit
): LayersTrace {
return LayersTraceParser().parse(LayersTraceMonitor(traceFlags).withTracing(predicate))
}
/**
* Acquire the [WindowManagerTrace] and [LayersTrace] with the device state changes that happen when
* executing the commands defined in the [predicate].
*
* @param predicate Commands to execute
* @throws UnsupportedOperationException If tracing is already activated
*/
fun withTracing(predicate: () -> Unit): DeviceTraceDump {
val traces = recordTraces(predicate)
val wmTraceData = traces.first
val layersTraceData = traces.second
return DeviceDumpParser.fromTrace(wmTraceData, layersTraceData, clearCache = true)
}
/**
* Acquire the [WindowManagerTrace] and [LayersTrace] with the device state changes that happen when
* executing the commands defined in the [predicate].
*
* @param predicate Commands to execute
* @throws UnsupportedOperationException If tracing is already activated
* @return a pair containing the WM and SF traces
*/
fun recordTraces(predicate: () -> Unit): Pair<ByteArray, ByteArray> {
var wmTraceData = ByteArray(0)
val layersTraceData =
LayersTraceMonitor().withTracing {
wmTraceData = WindowManagerTraceMonitor().withTracing(predicate)
}
return Pair(wmTraceData, layersTraceData)
}