PerfettoNative.kt
/*
* Copyright 2022 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.
*/
package androidx.tracing.perfetto.jni
import androidx.tracing.perfetto.security.SafeLibLoader
import dalvik.annotation.optimization.CriticalNative
import dalvik.annotation.optimization.FastNative
import java.io.File
internal object PerfettoNative {
private const val libraryName = "tracing_perfetto"
// TODO(224510255): load from a file produced at build time
object Metadata {
const val version = "1.0.0-beta01"
val checksums = mapOf(
"arm64-v8a" to "4d5a1d9006571fb14919a867599895bbd4433c7f6b7695fdbce73315489aa6e2",
"armeabi-v7a" to "74dc8c7e1423f4b3a43813acd0d02e46fb80424d09fa3ac7fbd04656699a00fc",
"x86" to "0aec446a0ffceaf290347a6bae07edb4e4456326687a720ce84ff50d7d2d88da",
"x86_64" to "bcea1f5fc4587692a4ee7f318ebeb356172da839a9d4cf8c7b1d45d285613814",
)
}
fun loadLib() = System.loadLibrary(libraryName)
fun loadLib(file: File, loader: SafeLibLoader) = loader.loadLib(file, Metadata.checksums)
@JvmStatic
external fun nativeRegisterWithPerfetto()
@FastNative
@JvmStatic
external fun nativeTraceEventBegin(key: Int, traceInfo: String)
@CriticalNative
@JvmStatic
external fun nativeTraceEventEnd()
@JvmStatic
external fun nativeVersion(): String
}