Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0f6ef48 authored by Peter Kalauskas's avatar Peter Kalauskas Committed by Android (Google) Code Review
Browse files

Merge "Remove public api variant of tracinglib" into main

parents 8e2d306d 3178ec7f
Loading
Loading
Loading
Loading
+1 −18
Original line number Diff line number Diff line
@@ -24,26 +24,9 @@ java_library {
        "com_android_systemui_flags_lib",
        "//frameworks/libs/systemui:compilelib",
    ],
    srcs: ["android/src-platform-api/**/*.kt"],
    srcs: ["android/src/**/*.kt"],
}

// TODO(b/358541864): Remove source files of "tracinglib-androidx" and delete this target
// Disable due to compilation error using java.lang.StackWalker:
// java_library {
//     name: "tracinglib-androidx",
//     defaults: ["tracinglib-defaults"],
//     static_libs: [
//         "kotlinx_coroutines_android",
//         "com_android_systemui_flags_lib",
//         "//frameworks/libs/systemui:compilelib",
//         "androidx.tracing_tracing",
//     ],
//     srcs: ["android/src-public-api/**/*.kt"],
//     sdk_version: "31",
//     min_sdk_version: "19",
//     java_version: "17",
// }

java_test_host {
    name: "tracinglib-host-test",
    defaults: ["tracinglib-defaults"],
+0 −77
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.app.tracing

import androidx.tracing.Trace
import java.util.concurrent.ThreadLocalRandom

@PublishedApi
internal actual fun isEnabled(): Boolean {
    return Trace.isEnabled()
}

internal actual fun traceCounter(counterName: String, counterValue: Int) {
    Trace.setCounter(counterName, counterValue)
}

internal actual fun traceBegin(methodName: String) {
    Trace.beginSection(methodName)
}

internal actual fun traceEnd() {
    Trace.endSection()
}

internal actual fun asyncTraceBegin(methodName: String, cookie: Int) {
    Trace.beginAsyncSection(methodName, cookie)
}

internal actual fun asyncTraceEnd(methodName: String, cookie: Int) {
    Trace.endAsyncSection(methodName, cookie)
}

private fun namedSlice(trackName: String, methodName: String) = "$trackName:$methodName"

@PublishedApi
internal actual fun asyncTraceForTrackBegin(trackName: String, methodName: String, cookie: Int) {
    if (isEnabled()) {
        asyncTraceBegin(namedSlice(trackName, methodName), cookie)
    }
}

@PublishedApi
internal actual fun asyncTraceForTrackEnd(trackName: String, methodName: String, cookie: Int) {
    if (isEnabled()) {
        asyncTraceEnd(namedSlice(trackName, methodName), cookie)
    }
}

internal actual fun instant(eventName: String) {
    if (isEnabled()) {
        traceBegin("instant:$eventName")
        traceEnd()
    }
}

internal actual fun instantForTrack(trackName: String, eventName: String) {
    if (Trace.isEnabled()) {
        val cookie = ThreadLocalRandom.current().nextInt()
        val name = "instant:${namedSlice(trackName,eventName)}"
        asyncTraceBegin(name, cookie)
        asyncTraceEnd(name, cookie)
    }
}