liblog: is loggable is flaky
- Deal with __android_log_is_loggable inside signal handler by
treating a lock contention system call as more costly than reading
the associated property directly. Rather waiting around in a
contended stat to hit cache.
- Check both the individual known __system_property_serial() and
global __system_property_area_serial() to detect updates or
additions to the properties to respond in the most aggressive and
timely manner. __android_log_is_loggable() return at max CPU
clockrate on a N9 in 61ns.
- Craft a common do_cache2 inline that adds the above to the other
functions that utilize cache handling and preserves (within 3ns)
performance in android_log_clockid() and __android_log_security().
These functions return at max CPU clockrate on a N9 in 23ns.
Bug: 19544788
Bug: 25693940
Bug: 25792367
Bug: 26178938
Change-Id: I9cd94598f5c558e946b93977ad3714a4b03d0422
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index 9f29a09..01fb50f 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -660,3 +660,31 @@
StopBenchmarkTiming();
}
BENCHMARK(BM_is_loggable);
+
+/*
+ * Measure the time it takes for android_log_clockid.
+ */
+static void BM_clockid(int iters) {
+ StartBenchmarkTiming();
+
+ for (int i = 0; i < iters; ++i) {
+ android_log_clockid();
+ }
+
+ StopBenchmarkTiming();
+}
+BENCHMARK(BM_clockid);
+
+/*
+ * Measure the time it takes for __android_log_security.
+ */
+static void BM_security(int iters) {
+ StartBenchmarkTiming();
+
+ for (int i = 0; i < iters; ++i) {
+ __android_log_security();
+ }
+
+ StopBenchmarkTiming();
+}
+BENCHMARK(BM_security);