update_engine: Reduce verbosity of delta_generator

This outputs ~4000 lines of the form:

  0.00%         48 REPLACE_BZ <boot-operation-2>

which is not very useful in the build. Update it to show only unique lines
with a count of how many times that line was repeated.

BUG=chromium:737687
TEST=FEATURES=test emerge-reef update_engine
See the output. I have not added a specific test for this since it is
really just debug output IMO.
Change-Id: I15149733216ba0516c62f99e5968768ec4fa3d20
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/553579
Reviewed-by: Ben Chan <benchan@chromium.org>
diff --git a/payload_generator/payload_file.cc b/payload_generator/payload_file.cc
index ddf6f0a..38aa0da 100644
--- a/payload_generator/payload_file.cc
+++ b/payload_generator/payload_file.cc
@@ -19,6 +19,9 @@
 #include <endian.h>
 
 #include <algorithm>
+#include <map>
+
+#include <base/strings/stringprintf.h>
 
 #include "update_engine/common/hash_calculator.h"
 #include "update_engine/payload_consumer/delta_performer.h"
@@ -321,38 +324,39 @@
 }
 
 void PayloadFile::ReportPayloadUsage(uint64_t metadata_size) const {
-  vector<DeltaObject> objects;
+  std::map<DeltaObject, int> object_counts;
   off_t total_size = 0;
 
   for (const auto& part : part_vec_) {
     for (const AnnotatedOperation& aop : part.aops) {
-      objects.push_back(DeltaObject(aop.name,
-                                    aop.op.type(),
-                                    aop.op.data_length()));
+      DeltaObject delta(aop.name, aop.op.type(), aop.op.data_length());
+      object_counts[delta]++;
       total_size += aop.op.data_length();
     }
   }
 
-  objects.push_back(DeltaObject("<manifest-metadata>",
-                                -1,
-                                metadata_size));
+  object_counts[DeltaObject("<manifest-metadata>", -1, metadata_size)] = 1;
   total_size += metadata_size;
 
-  std::sort(objects.begin(), objects.end());
-
-  static const char kFormatString[] = "%6.2f%% %10jd %-10s %s\n";
-  for (const DeltaObject& object : objects) {
-    fprintf(
-        stderr, kFormatString,
+  static const char kFormatString[] = "%6.2f%% %10jd %-13s %s %d";
+  for (const auto& object_count : object_counts) {
+    const DeltaObject& object = object_count.first;
+    LOG(INFO) << base::StringPrintf(
+        kFormatString,
         object.size * 100.0 / total_size,
         static_cast<intmax_t>(object.size),
         (object.type >= 0 ? InstallOperationTypeName(
                                 static_cast<InstallOperation_Type>(object.type))
                           : "-"),
-        object.name.c_str());
+        object.name.c_str(),
+        object_count.second);
   }
-  fprintf(stderr, kFormatString,
-          100.0, static_cast<intmax_t>(total_size), "", "<total>");
+  LOG(INFO) << base::StringPrintf(kFormatString,
+                                  100.0,
+                                  static_cast<intmax_t>(total_size),
+                                  "",
+                                  "<total>",
+                                  1);
 }
 
 }  // namespace chromeos_update_engine