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

Commit fc44f6ca authored by William Escande's avatar William Escande
Browse files

SystemServer: Metrics on shutdown latency

Bug: 356931756
Bug: 361850050
Test: atest CtsBluetoothTestCases
Change-Id: I90477c7cbcf0f417f3081373ecea9aa88916bd61
parent 69c1d22b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ java_defaults {
            "-Xep:InvalidBlockTag:ERROR",
            "-Xep:InvalidInlineTag:ERROR",
            "-Xep:InvalidParam:ERROR",
            "-Xep:LongFloatConversion:ERROR",
            "-Xep:MockNotUsedInProduction:ERROR",
            "-Xep:NonApiType:ERROR",
            "-Xep:NonCanonicalType:ERROR",
+9 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.modules.expresslog.Counter;
import com.android.modules.expresslog.Histogram;
import com.android.server.BluetoothManagerServiceDumpProto;
import com.android.server.bluetooth.airplane.AirplaneModeListener;
import com.android.server.bluetooth.satellite.SatelliteModeListener;
@@ -563,6 +564,10 @@ class BluetoothManagerService {
                }
            };

    private final Histogram mShutdownLatencyHistogram =
            new Histogram(
                    "bluetooth.value_shutdown_latency", new Histogram.UniformOptions(50, 0, 3000));

    BluetoothManagerService(@NonNull Context context, @NonNull Looper looper) {
        mContext = requireNonNull(context, "Context cannot be null");
        mContentResolver = requireNonNull(mContext.getContentResolver(), "Resolver cannot be null");
@@ -1194,6 +1199,7 @@ class BluetoothManagerService {
            if (mAdapter == null) {
                return;
            }
            long currentTimeMs = System.currentTimeMillis();

            try {
                mAdapter.unregisterCallback(mBluetoothCallback, mContext.getAttributionSource());
@@ -1236,6 +1242,9 @@ class BluetoothManagerService {
                Log.e(TAG, "Bluetooth death not received correctly after > 2000ms", e);
            }

            long timeSpentForShutdown = System.currentTimeMillis() - currentTimeMs;
            mShutdownLatencyHistogram.logSample((float) timeSpentForShutdown);

            // TODO: b/356931756 - Remove sleep
            SystemClock.sleep(100); // required to let the ActivityManager be notified of BT death