Enable profile data filtering in profman

Update profile merging to accept a set of apks (passes with --apk) which
will dictate what data should be processed.

When profman is invoked with a list of --apk files, only profile data
belonging to that apks will be in the output reference profile.

If no --dex-location is specified then the locations is inferred from
reding /proc/self/fd/apk_fd link.

Test: profile_assistant_test
Bug: 30934496
Change-Id: I44698c6db545ecf91454db1387c3d0e47fe5b9b3
diff --git a/profman/profile_assistant.cc b/profman/profile_assistant.cc
index ff02b5d..a00b1fa 100644
--- a/profman/profile_assistant.cc
+++ b/profman/profile_assistant.cc
@@ -31,12 +31,13 @@
 
 ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfilesInternal(
         const std::vector<ScopedFlock>& profile_files,
-        const ScopedFlock& reference_profile_file) {
+        const ScopedFlock& reference_profile_file,
+        const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) {
   DCHECK(!profile_files.empty());
 
   ProfileCompilationInfo info;
   // Load the reference profile.
-  if (!info.Load(reference_profile_file->Fd())) {
+  if (!info.Load(reference_profile_file->Fd(), /*merge_classes*/ true, filter_fn)) {
     LOG(WARNING) << "Could not load reference profile file";
     return kErrorBadProfiles;
   }
@@ -48,7 +49,7 @@
   // Merge all current profiles.
   for (size_t i = 0; i < profile_files.size(); i++) {
     ProfileCompilationInfo cur_info;
-    if (!cur_info.Load(profile_files[i]->Fd())) {
+    if (!cur_info.Load(profile_files[i]->Fd(), /*merge_classes*/ true, filter_fn)) {
       LOG(WARNING) << "Could not load profile file at index " << i;
       return kErrorBadProfiles;
     }
@@ -122,7 +123,8 @@
 
 ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles(
         const std::vector<int>& profile_files_fd,
-        int reference_profile_file_fd) {
+        int reference_profile_file_fd,
+        const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) {
   DCHECK_GE(reference_profile_file_fd, 0);
 
   std::string error;
@@ -143,12 +145,15 @@
     return kErrorCannotLock;
   }
 
-  return ProcessProfilesInternal(profile_files.Get(), reference_profile_file);
+  return ProcessProfilesInternal(profile_files.Get(),
+                                 reference_profile_file,
+                                 filter_fn);
 }
 
 ProfileAssistant::ProcessingResult ProfileAssistant::ProcessProfiles(
         const std::vector<std::string>& profile_files,
-        const std::string& reference_profile_file) {
+        const std::string& reference_profile_file,
+        const ProfileCompilationInfo::ProfileLoadFilterFn& filter_fn) {
   std::string error;
 
   ScopedFlockList profile_files_list(profile_files.size());
@@ -164,7 +169,9 @@
     return kErrorCannotLock;
   }
 
-  return ProcessProfilesInternal(profile_files_list.Get(), locked_reference_profile_file);
+  return ProcessProfilesInternal(profile_files_list.Get(),
+                                 locked_reference_profile_file,
+                                 filter_fn);
 }
 
 }  // namespace art