Log DeltaPerformer operation histogram after update

Record and log InstallOperation run durations in DeltaPerformer. Since
these operations block the single-threaded process they may be
responsible for dbus service timeouts.

BUG=chromium:578270
TEST=deploy to device, restart update-engine, perform update (e.g.
`cros flash ssh://...`), check logs for histogram.

Change-Id: Idb782c86a627b1738a29901edd5d3b45790f4bb9
Reviewed-on: https://chromium-review.googlesource.com/570997
Commit-Ready: Lann Martin <lannm@chromium.org>
Tested-by: Lann Martin <lannm@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
diff --git a/payload_consumer/download_action.cc b/payload_consumer/download_action.cc
index 084848e..b2405ef 100644
--- a/payload_consumer/download_action.cc
+++ b/payload_consumer/download_action.cc
@@ -23,6 +23,7 @@
 #include <vector>
 
 #include <base/files/file_path.h>
+#include <base/metrics/statistics_recorder.h>
 #include <base/strings/stringprintf.h>
 
 #include "update_engine/common/action_pipe.h"
@@ -55,6 +56,7 @@
       bytes_received_(0),
       p2p_sharing_fd_(-1),
       p2p_visible_(true) {
+  base::StatisticsRecorder::Initialize();
 }
 
 DownloadAction::~DownloadAction() {}
@@ -305,7 +307,14 @@
   if (code == ErrorCode::kSuccess && delta_performer_.get()) {
     code = delta_performer_->VerifyPayload(install_plan_.payload_hash,
                                            install_plan_.payload_size);
-    if (code != ErrorCode::kSuccess) {
+    if (code == ErrorCode::kSuccess) {
+      // Log UpdateEngine.DownloadAction.* histograms to help diagnose
+      // long-blocking oeprations.
+      std::string histogram_output;
+      base::StatisticsRecorder::WriteGraph(
+          "UpdateEngine.DownloadAction.", &histogram_output);
+      LOG(INFO) << histogram_output;
+    } else {
       LOG(ERROR) << "Download of " << install_plan_.download_url
                  << " failed due to payload verification error.";
       // Delete p2p file, if applicable.