Move bionic_systrace.cpp over to CachedProperty.

This is the last bionic caller that was manually trying to cache
property values.

Bug: N/A
Test: builds and boots
Change-Id: Id66c0a05d8448f08c39dbf7189241e75615d44b4
diff --git a/libc/bionic/bionic_systrace.cpp b/libc/bionic/bionic_systrace.cpp
index 8e8ff76..5699f6e 100644
--- a/libc/bionic/bionic_systrace.cpp
+++ b/libc/bionic/bionic_systrace.cpp
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include <cutils/trace.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -23,55 +22,26 @@
 
 #include "private/bionic_lock.h"
 #include "private/bionic_systrace.h"
+#include "private/CachedProperty.h"
 #include "private/libc_logging.h"
 
-#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
-#include <sys/_system_properties.h>
+#include <cutils/trace.h> // For ATRACE_TAG_BIONIC.
 
 #define WRITE_OFFSET   32
 
-constexpr char SYSTRACE_PROPERTY_NAME[] = "debug.atrace.tags.enableflags";
-
 static Lock g_lock;
-static const prop_info* g_pinfo;
-static uint32_t g_property_serial = -1;
-static uint32_t g_property_area_serial = -1;
-static uint64_t g_tags;
 static int g_trace_marker_fd = -1;
 
 static bool should_trace() {
-  bool result = false;
-  g_lock.lock();
-  // debug.atrace.tags.enableflags is set to a safe non-tracing value during property
-  // space initialization, so it should only be null in two cases, if there are
-  // insufficient permissions for this process to access the property, in which
-  // case an audit will be logged, and during boot before the property server has
-  // been started, in which case we store the global property_area serial to prevent
-  // the costly find operation until we see a changed property_area.
-  if (g_pinfo == nullptr && g_property_area_serial != __system_property_area_serial()) {
-    g_property_area_serial = __system_property_area_serial();
-    g_pinfo = __system_property_find(SYSTRACE_PROPERTY_NAME);
-  }
+  static CachedProperty g_debug_atrace_tags_enableflags("debug.atrace.tags.enableflags");
+  static uint64_t g_tags;
 
-  if (g_pinfo) {
-    // Find out which tags have been enabled on the command line and set
-    // the value of tags accordingly.  If the value of the property changes,
-    // the serial will also change, so the costly system_property_read function
-    // can be avoided by calling the much cheaper system_property_serial
-    // first.  The values within pinfo may change, but its location is guaranteed
-    // not to move.
-    uint32_t cur_serial = __system_property_serial(g_pinfo);
-    if (cur_serial != g_property_serial) {
-      __system_property_read_callback(g_pinfo,
-              [] (void*, const char*, const char* value, uint32_t serial) {
-                g_property_serial = serial;
-                g_tags = strtoull(value, nullptr, 0);
-              }, nullptr);
-    }
-    result = ((g_tags & ATRACE_TAG_BIONIC) != 0);
+  g_lock.lock();
+  if (g_debug_atrace_tags_enableflags.DidChange()) {
+    g_tags = strtoull(g_debug_atrace_tags_enableflags.Get(), nullptr, 0);
   }
   g_lock.unlock();
-  return result;
+  return ((g_tags & ATRACE_TAG_BIONIC) != 0);
 }
 
 static int get_trace_marker_fd() {