Make Loop::destroyAll() smarter.

Instead of blindly looping across 4096 possible devices, use
readdir() to only look at valid devices.  This speeds up destroyAll()
from 40ms to 0.7ms.

Add tracing information in several places.

Test: external/chromium-trace/systrace.py -b 128768 sched freq am pm ss core_services binder_driver -a system_server,installd,vold
Bug: 65634729, 65737446
Change-Id: If581de47fb55850c0fcd6e25bf33ed246e1b079d
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 70f71f9..e96b7ac 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#define ATRACE_TAG ATRACE_TAG_PACKAGE_MANAGER
+
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -40,6 +42,7 @@
 #include <android-base/stringprintf.h>
 #include <cutils/fs.h>
 #include <cutils/log.h>
+#include <utils/Trace.h>
 
 #include <selinux/android.h>
 
@@ -94,6 +97,7 @@
 }
 
 int VolumeManager::updateVirtualDisk() {
+    ATRACE_NAME("VolumeManager::updateVirtualDisk");
     if (property_get_bool(kPropVirtualDisk, false)) {
         if (access(kPathVirtualDisk, F_OK) != 0) {
             Loop::createImageFile(kPathVirtualDisk, kSizeVirtualDisk / 512);
@@ -148,6 +152,8 @@
 }
 
 int VolumeManager::start() {
+    ATRACE_NAME("VolumeManager::start");
+
     // Always start from a clean slate by unmounting everything in
     // directories that we own, in case we crashed.
     unmountAll();
@@ -548,6 +554,7 @@
 
 int VolumeManager::unmountAll() {
     std::lock_guard<std::mutex> lock(mLock);
+    ATRACE_NAME("VolumeManager::unmountAll()");
 
     // First, try gracefully unmounting all known devices
     if (mInternalEmulated != nullptr) {