summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Pablo Gamito <pablogamito@google.com> 2024-08-26 13:00:04 +0000
committer Pablo Gamito <pablogamito@google.com> 2024-08-26 13:38:23 +0000
commit5004cd018a10c3053d48989d90215d5db8bba974 (patch)
tree13b2b5c36a466fbb6ce188c8a64e3d4181e3b1cd
parent607432e7485d0e9bca6566110711d86808775425 (diff)
Support unprocessed files when Perfetto protologging is not enabled
Some files are not processable by the ProtoLog tool yet because they use newer language features than the java parser we use supports. This means these files will use the default ProtoLog call instead of the generate implementation. The PerfettoProtoLogImpl supports tracing non-processed log messages to Perfetto, but the LogcatOnlyProtoLogImpl which is used when the logging to Perfetto flag is disabled crashes in those cases unless the REQUIRE_PROTOLOGTOOL is set to false. We want to make sure we don't crash in such cases and just warn about the unprocessed file. Flag: EXEMPT small bug fix Bug: 358044587 Change-Id: Ibfa1dbfaa2f7db769c245936ebd0cbb005609f2c
-rw-r--r--core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java26
-rw-r--r--core/java/com/android/internal/protolog/ProtoLog.java5
2 files changed, 18 insertions, 13 deletions
diff --git a/core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java b/core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java
index e8d5195d121d..7a384097754b 100644
--- a/core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java
+++ b/core/java/com/android/internal/protolog/LogcatOnlyProtoLogImpl.java
@@ -36,6 +36,8 @@ import com.android.internal.protolog.common.LogLevel;
*/
@Deprecated
public class LogcatOnlyProtoLogImpl implements IProtoLog {
+ private static final String LOG_TAG = LogcatOnlyProtoLogImpl.class.getName();
+
@Override
public void log(LogLevel logLevel, IProtoLogGroup group, long messageHash, int paramsMask,
Object[] args) {
@@ -44,19 +46,21 @@ public class LogcatOnlyProtoLogImpl implements IProtoLog {
@Override
public void log(LogLevel logLevel, IProtoLogGroup group, String messageString, Object[] args) {
- if (REQUIRE_PROTOLOGTOOL) {
- throw new RuntimeException(
- "REQUIRE_PROTOLOGTOOL not set to false before the first log call.");
+ if (REQUIRE_PROTOLOGTOOL && group.isLogToProto()) {
+ Log.w(LOG_TAG, "ProtoLog message not processed. Failed to log it to proto. "
+ + "Logging it below to logcat instead.");
}
- String formattedString = TextUtils.formatSimple(messageString, args);
- switch (logLevel) {
- case VERBOSE -> Log.v(group.getTag(), formattedString);
- case INFO -> Log.i(group.getTag(), formattedString);
- case DEBUG -> Log.d(group.getTag(), formattedString);
- case WARN -> Log.w(group.getTag(), formattedString);
- case ERROR -> Log.e(group.getTag(), formattedString);
- case WTF -> Log.wtf(group.getTag(), formattedString);
+ if (group.isLogToLogcat() || group.isLogToProto()) {
+ String formattedString = TextUtils.formatSimple(messageString, args);
+ switch (logLevel) {
+ case VERBOSE -> Log.v(group.getTag(), formattedString);
+ case INFO -> Log.i(group.getTag(), formattedString);
+ case DEBUG -> Log.d(group.getTag(), formattedString);
+ case WARN -> Log.w(group.getTag(), formattedString);
+ case ERROR -> Log.e(group.getTag(), formattedString);
+ case WTF -> Log.wtf(group.getTag(), formattedString);
+ }
}
}
diff --git a/core/java/com/android/internal/protolog/ProtoLog.java b/core/java/com/android/internal/protolog/ProtoLog.java
index f9b989477907..c23112c1b18b 100644
--- a/core/java/com/android/internal/protolog/ProtoLog.java
+++ b/core/java/com/android/internal/protolog/ProtoLog.java
@@ -58,11 +58,12 @@ public class ProtoLog {
* @param groups The ProtoLog groups that will be used in the process.
*/
public static void init(IProtoLogGroup... groups) {
+ // These tracing instances are only used when we cannot or do not preprocess the source
+ // files to extract out the log strings. Otherwise, the trace calls are replaced with calls
+ // directly to the generated tracing implementations.
if (android.tracing.Flags.perfettoProtologTracing()) {
sProtoLogInstance = new PerfettoProtoLogImpl(groups);
} else {
- // The first call to ProtoLog is likely to flip REQUIRE_PROTOLOGTOOL, which is when this
- // static block will be executed before REQUIRE_PROTOLOGTOOL is actually set.
sProtoLogInstance = new LogcatOnlyProtoLogImpl();
}
}