diff options
| author | 2021-03-15 14:37:39 -0700 | |
|---|---|---|
| committer | 2021-03-16 12:01:38 -0700 | |
| commit | 08e7e12982727dfb3ad54cf450fab3f5a9a5de16 (patch) | |
| tree | 58e7342bdeae58ea73f98949dab53ea1eb2e3769 | |
| parent | 9c907184d5e1d70ea181b37e432858c7ac53ec1b (diff) | |
Added Warning about extra object allocation on SLog methods.
Test: m
Bug: 182476140
Change-Id: Id210956dcc060f0570d1f5c95e11e0effc7d0d24
| -rw-r--r-- | core/java/android/util/Slog.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/java/android/util/Slog.java b/core/java/android/util/Slog.java index f61ab2985163..b949ea3262c6 100644 --- a/core/java/android/util/Slog.java +++ b/core/java/android/util/Slog.java @@ -51,6 +51,12 @@ public final class Slog { /** * 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. */ public static void v(String tag, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.VERBOSE)) return; @@ -71,6 +77,12 @@ public final class Slog { /** * 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. */ public static void d(String tag, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.DEBUG)) return; @@ -90,6 +102,12 @@ public final class Slog { /** * 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. */ public static void i(String tag, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.INFO)) return; @@ -114,6 +132,12 @@ public final class Slog { /** * 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. */ public static void w(String tag, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.WARN)) return; @@ -123,6 +147,12 @@ public final class Slog { /** * 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. */ public static void w(String tag, Exception exception, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.WARN)) return; @@ -143,6 +173,12 @@ public final class Slog { /** * 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. */ public static void e(String tag, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.ERROR)) return; @@ -152,6 +188,12 @@ public final class Slog { /** * 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. */ public static void e(String tag, Exception exception, String format, @Nullable Object... args) { if (!Log.isLoggable(tag, Log.ERROR)) return; |