Perfetto changes for i/o tracing on user builds.

Bug: 74584014
Change-Id: Ie241267d530231a7f2d17f7e8bd2bf8aaf4bf507
diff --git a/perfetto.rc b/perfetto.rc
index 65256a9..23abaf2 100644
--- a/perfetto.rc
+++ b/perfetto.rc
@@ -31,6 +31,7 @@
     # unexpectedly.
     onrestart exec_background - nobody shell -- /system/bin/traced_probes --cleanup-after-crash
     file /dev/kmsg w
+    capabilities DAC_READ_SEARCH
 
 on property:sys.traced.enable_override=1
     setprop persist.traced.enable 1
diff --git a/src/ftrace_reader/ftrace_config_muxer.cc b/src/ftrace_reader/ftrace_config_muxer.cc
index 3642b24..641bd28 100644
--- a/src/ftrace_reader/ftrace_config_muxer.cc
+++ b/src/ftrace_reader/ftrace_config_muxer.cc
@@ -262,6 +262,8 @@
     if (ftrace_->EnableEvent(event->group, event->name)) {
       current_state_.ftrace_events.insert(name);
       *actual.add_ftrace_events() = name;
+    } else {
+      PERFETTO_DPLOG("Failed to enable %s.", name.c_str());
     }
   }
 
diff --git a/src/protozero/scattered_stream_writer.cc b/src/protozero/scattered_stream_writer.cc
index 8605e69..305fe0f 100644
--- a/src/protozero/scattered_stream_writer.cc
+++ b/src/protozero/scattered_stream_writer.cc
@@ -65,7 +65,7 @@
   }
   uint8_t* begin = write_ptr_;
   write_ptr_ += size;
-#ifndef NDEBUG
+#if PERFETTO_DCHECK_IS_ON()
   memset(begin, 0, size);
 #endif
   return begin;
diff --git a/src/traced/probes/filesystem/inode_file_data_source.cc b/src/traced/probes/filesystem/inode_file_data_source.cc
index 2f5c590..3186b3f 100644
--- a/src/traced/probes/filesystem/inode_file_data_source.cc
+++ b/src/traced/probes/filesystem/inode_file_data_source.cc
@@ -48,38 +48,41 @@
     directory += "/";
     if (!dir)
       continue;
+
+    struct stat buf;
+    if (lstat(directory.c_str(), &buf) != 0) {
+      PERFETTO_DPLOG("lstat %s", directory.c_str());
+      continue;
+    }
+    if (S_ISLNK(buf.st_mode))
+      continue;
+
+    BlockDeviceID block_device_id = buf.st_dev;
+
     while ((entry = readdir(dir.get())) != nullptr) {
       std::string filename = entry->d_name;
       if (filename == "." || filename == "..")
         continue;
       std::string filepath = directory + filename;
 
-      struct stat buf;
-      if (lstat(filepath.c_str(), &buf) != 0)
-        continue;
-
-      // This might happen on filesystems that do not return
-      // information in entry->d_type.
-      if (S_ISLNK(buf.st_mode))
-        continue;
-
       Inode inode_number = entry->d_ino;
-      BlockDeviceID block_device_id = buf.st_dev;
 
       protos::pbzero::InodeFileMap_Entry_Type type =
           protos::pbzero::InodeFileMap_Entry_Type_UNKNOWN;
       // Readdir and stat not guaranteed to have directory info for all systems
-      if (entry->d_type == DT_DIR || S_ISDIR(buf.st_mode)) {
+      if (entry->d_type == DT_DIR) {
         // Continue iterating through files if current entry is a directory
         queue.push_back(filepath);
         type = protos::pbzero::InodeFileMap_Entry_Type_DIRECTORY;
-      } else if (entry->d_type == DT_REG || S_ISREG(buf.st_mode)) {
+      } else if (entry->d_type == DT_REG) {
         type = protos::pbzero::InodeFileMap_Entry_Type_FILE;
       }
 
       if (!fn(block_device_id, inode_number, filepath, type))
         return;
     }
+    if (errno != 0)
+      PERFETTO_DPLOG("readdir %s", directory.c_str());
   }
 }