Removed Slog methods that support message formatting.
Slog is a core class provided by frameworks.jar, and these new methods
were causing performance regressions, so they were moved to a
system_server only class (com.android.server.utils.Slogf).
Test: m
Fixes: 183523451
Bug: 182476140
Change-Id: I511dd57faee194b58cf77c0c39c92dd0e876566e
diff --git a/core/java/android/util/Slog.java b/core/java/android/util/Slog.java
index 78c4739..117d75e 100644
--- a/core/java/android/util/Slog.java
+++ b/core/java/android/util/Slog.java
@@ -16,15 +16,9 @@
package android.util;
-import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
-import com.android.internal.annotations.GuardedBy;
-
-import java.util.Formatter;
-import java.util.Locale;
-
/**
* API for sending log output to the {@link Log#LOG_ID_SYSTEM} buffer.
*
@@ -34,12 +28,6 @@
*/
public final class Slog {
- @GuardedBy("Slog.class")
- private static StringBuilder sMessageBuilder;
-
- @GuardedBy("Slog.class")
- private static Formatter sFormatter;
-
private Slog() {
}
@@ -53,24 +41,6 @@
msg + '\n' + Log.getStackTraceString(tr));
}
- /**
- * Logs a {@link Log.VERBOSE} message.
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void v(String tag, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.VERBOSE)) return;
-
- v(tag, getMessage(format, args));
- }
-
@UnsupportedAppUsage
public static int d(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag, msg);
@@ -82,24 +52,6 @@
msg + '\n' + Log.getStackTraceString(tr));
}
- /**
- * Logs a {@link Log.DEBUG} message.
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void d(String tag, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.DEBUG)) return;
-
- d(tag, getMessage(format, args));
- }
-
@UnsupportedAppUsage
public static int i(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag, msg);
@@ -110,24 +62,6 @@
msg + '\n' + Log.getStackTraceString(tr));
}
- /**
- * Logs a {@link Log.INFO} message.
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void i(String tag, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.INFO)) return;
-
- i(tag, getMessage(format, args));
- }
-
@UnsupportedAppUsage
public static int w(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, msg);
@@ -143,42 +77,6 @@
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
}
- /**
- * Logs a {@link Log.WARN} message.
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void w(String tag, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.WARN)) return;
-
- w(tag, getMessage(format, args));
- }
-
- /**
- * Logs a {@link Log.WARN} message with an exception
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void w(String tag, Exception exception, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.WARN)) return;
-
- w(tag, getMessage(format, args), exception);
- }
-
@UnsupportedAppUsage
public static int e(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag, msg);
@@ -191,42 +89,6 @@
}
/**
- * Logs a {@link Log.ERROR} message.
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void e(String tag, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.ERROR)) return;
-
- e(tag, getMessage(format, args));
- }
-
- /**
- * Logs a {@link Log.ERROR} message with an exception
- *
- * <p><strong>Note: </strong>the message will only be formatted if {@link Log#WARN} logging is
- * enabled for the given {@code tag}, but the compiler will still create an intermediate array
- * of the objects for the {@code vargars}, which could affect garbage collection. So, if you're
- * calling this method in a critical path, make sure to explicitly do the check before calling
- * it.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void e(String tag, Exception exception, String format, @Nullable Object... args) {
- if (!Log.isLoggable(tag, Log.ERROR)) return;
-
- e(tag, getMessage(format, args), exception);
- }
-
- /**
* Like {@link Log#wtf(String, String)}, but will never cause the caller to crash, and
* will always be handled asynchronously. Primarily for use by coding running within
* the system process.
@@ -237,27 +99,6 @@
}
/**
- * Logs a {@code wtf} message.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void wtf(String tag, String format, @Nullable Object... args) {
- wtf(tag, getMessage(format, args));
- }
-
- /**
- * Logs a {@code wtf} message with an exception.
- *
- * @deprecated use {@code com.android.server.utils.SLogF} instead.
- */
- @Deprecated
- public static void wtf(String tag, Exception exception, String format,
- @Nullable Object... args) {
- wtf(tag, getMessage(format, args), exception);
- }
-
- /**
* Like {@link #wtf(String, String)}, but does not output anything to the log.
*/
public static void wtfQuiet(String tag, String msg) {
@@ -297,18 +138,4 @@
public static int println(int priority, String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, priority, tag, msg);
}
-
- private static String getMessage(String format, @Nullable Object... args) {
- synchronized (Slog.class) {
- if (sMessageBuilder == null) {
- // Lazy load so they're not created if not used by the process
- sMessageBuilder = new StringBuilder();
- sFormatter = new Formatter(sMessageBuilder, Locale.ENGLISH);
- }
- sFormatter.format(format, args);
- String message = sMessageBuilder.toString();
- sMessageBuilder.setLength(0);
- return message;
- }
- }
}