Add more flexibility to the boot image profiles creation

Verify that the boot image profile output is specified
and make the preloaded classes output optional.

This way, the same command line can be used to extract
system server profiles.

Test: gtest
Bug: 152574358
Merged-In: I9019a61635daeb4652e6ec8be42601aeddaee236
Change-Id: I9019a61635daeb4652e6ec8be42601aeddaee236
diff --git a/profman/boot_image_profile.cc b/profman/boot_image_profile.cc
index 8c9d0cd..fdd0a29 100644
--- a/profman/boot_image_profile.cc
+++ b/profman/boot_image_profile.cc
@@ -198,6 +198,13 @@
     const BootImageOptions& options,
     const std::string& boot_profile_out_path,
     const std::string& preloaded_classes_out_path) {
+  if (boot_profile_out_path.empty()) {
+    LOG(ERROR) << "No output file specified";
+    return false;
+  }
+
+  bool generate_preloaded_classes = !preloaded_classes_out_path.empty();
+
   std::unique_ptr<FlattenProfileData> flattenData = profile.ExtractProfileData(dex_files);
 
   // We want the output sorted by the method/class name.
@@ -228,7 +235,7 @@
             options)) {
       profile_classes.Put(BootImageRepresentation(it.first), it.second);
     }
-    if (IncludeInPreloadedClasses(
+    if (generate_preloaded_classes && IncludeInPreloadedClasses(
             flattenData->GetMaxAggregationForClasses(),
             metadata,
             options)) {
@@ -247,13 +254,17 @@
     profile_content += MethodToProfileFormat(it.first, it.second, options.append_package_use_list)
         + "\n";
   }
-  for (const auto& it : preloaded_classes) {
-    preloaded_content += ClassToProfileFormat(it.first, it.second, options.append_package_use_list)
-        + "\n";
+
+  if (generate_preloaded_classes) {
+    for (const auto& it : preloaded_classes) {
+      preloaded_content +=
+          ClassToProfileFormat(it.first, it.second, options.append_package_use_list) + "\n";
+    }
   }
 
   return android::base::WriteStringToFile(profile_content, boot_profile_out_path)
-      && android::base::WriteStringToFile(preloaded_content, preloaded_classes_out_path);
+      && (!generate_preloaded_classes
+          || android::base::WriteStringToFile(preloaded_content, preloaded_classes_out_path));
 }
 
 }  // namespace art
diff --git a/profman/profile_assistant_test.cc b/profman/profile_assistant_test.cc
index ffdc8be..c4d0d39 100644
--- a/profman/profile_assistant_test.cc
+++ b/profman/profile_assistant_test.cc
@@ -214,7 +214,7 @@
     argv_str.push_back(profman_cmd);
     argv_str.push_back("--generate-test-profile=" + filename);
     std::string error;
-     return ExecAndReturnCode(argv_str, &error);
+    return ExecAndReturnCode(argv_str, &error);
   }
 
   bool GenerateTestProfileWithInputDex(const std::string& filename) {