summaryrefslogtreecommitdiffstats
path: root/dalvik/src
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2009-10-21 15:44:25 -0700
committerJesse Wilson <jessewilson@google.com>2009-10-22 20:52:29 -0700
commitc99250a4d619670f2a9410df121eff04fdc9e87c (patch)
treeaa93c43e01171d910a626c466ca52923606c7057 /dalvik/src
parent3597a2fbf1aedd3674e607ec84233fe6d23fa981 (diff)
downloadlibcore-c99250a4d619670f2a9410df121eff04fdc9e87c.zip
libcore-c99250a4d619670f2a9410df121eff04fdc9e87c.tar.gz
libcore-c99250a4d619670f2a9410df121eff04fdc9e87c.tar.bz2
Expose hooks for more efficient log handling in Android apps.
This change introduces a new interface, DalvikLogHandler. Log handlers that implement it opt-in to more efficient log handling for common-case log messages. The API requires far fewer objects to be allocated to log a message. A related change in frameworks/base adopts this optimization in the built-in AndroidHandler. This optimization resulted in a 2.75x improvement on my device: from 154ns to 56ns per message.
Diffstat (limited to 'dalvik/src')
-rw-r--r--dalvik/src/main/java/dalvik/system/DalvikLogHandler.java47
-rw-r--r--dalvik/src/main/java/dalvik/system/DalvikLogging.java48
2 files changed, 95 insertions, 0 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java b/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java
new file mode 100644
index 0000000..a62ca3b
--- /dev/null
+++ b/dalvik/src/main/java/dalvik/system/DalvikLogHandler.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2009 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 dalvik.system;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An optimized handler for efficient publishing of basic log messages.
+ * Implementers should also be subclasses of {@link java.util.logging.Handler}.
+ *
+ * <p>Unlike the default log handler, this API doesn't require intermediate
+ * objects to be allocated for log handling. It also includes a short tag, which
+ * may otherwise need to be calculated for each published message.
+ *
+ * @hide
+ */
+public interface DalvikLogHandler {
+
+ /**
+ * Publishes a log message. Unlike {@link
+ * java.util.logging.Handler#publish(java.util.logging.LogRecord)}, this
+ * method includes only the raw log message. Log messages that were created
+ * with additional fields (parameters, source methods, etc.) will flow
+ * through the conventional channels instead.
+ *
+ * @param tag the short (23 characters or fewer) logger tag identifying
+ * {@code logger}.
+ */
+ void publish(Logger source, String tag, Level level, String message);
+
+ // TODO: support messages with throwables?
+} \ No newline at end of file
diff --git a/dalvik/src/main/java/dalvik/system/DalvikLogging.java b/dalvik/src/main/java/dalvik/system/DalvikLogging.java
new file mode 100644
index 0000000..b5c7ad5
--- /dev/null
+++ b/dalvik/src/main/java/dalvik/system/DalvikLogging.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009 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 dalvik.system;
+
+/**
+ * Utility methods for logging to {@code DalvikHandlers}.
+ *
+ * @hide
+ */
+public final class DalvikLogging {
+ private DalvikLogging() {}
+
+ /**
+ * Returns the short logger tag (up to 23 chars) for the given logger name.
+ * Traditionally loggers are named by fully-qualified Java classes; this
+ * method attempts to return a concise identifying part of such names.
+ */
+ public static String loggerNameToTag(String loggerName) {
+ // Anonymous logger.
+ if (loggerName == null) {
+ return "null";
+ }
+
+ int length = loggerName.length();
+ if (length <= 23) {
+ return loggerName;
+ }
+
+ int lastPeriod = loggerName.lastIndexOf(".");
+ return length - (lastPeriod + 1) <= 23
+ ? loggerName.substring(lastPeriod + 1)
+ : loggerName.substring(loggerName.length() - 23);
+ }
+}