[Segmentation] report model execution results along with input/output tensors

This CL adds model execution results to structured metrics report for immediate
collections, so that it will be easier for server to study the models. We
need the execution results so that we know how features are working in
Chrome.

BUG=1295447

Change-Id: I31c8a4610d45ce064f4177e6e2a36c4b2031d36a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3597546
Reviewed-by: Siddhartha S <[email protected]>
Commit-Queue: Min Qin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#995050}
diff --git a/components/segmentation_platform/internal/segmentation_ukm_helper.cc b/components/segmentation_platform/internal/segmentation_ukm_helper.cc
index 8a99d1b..5e7b87b 100644
--- a/components/segmentation_platform/internal/segmentation_ukm_helper.cc
+++ b/components/segmentation_platform/internal/segmentation_ukm_helper.cc
@@ -125,7 +125,8 @@
     int64_t model_version,
     const std::vector<float>& input_tensor,
     const std::vector<float>& outputs,
-    const std::vector<int>& output_indexes) {
+    const std::vector<int>& output_indexes,
+    const absl::optional<proto::PredictionResult>& prediction_result) {
   ukm::SourceId source_id = ukm::NoURLSourceId();
   ukm::builders::Segmentation_ModelExecution execution_result(source_id);
   if (!AddInputsToUkm(&execution_result, segment_id, model_version,
@@ -137,6 +138,14 @@
     return ukm::kInvalidSourceId;
   }
 
+  if (prediction_result.has_value()) {
+    execution_result.SetPredictionResult(
+        FloatToInt64(prediction_result->result()));
+    base::Time execution_time = base::Time::FromDeltaSinceWindowsEpoch(
+        base::Microseconds(prediction_result->timestamp_us()));
+    execution_result.SetOutputDelaySec(
+        (base::Time::Now() - execution_time).InSeconds());
+  }
   execution_result.Record(ukm::UkmRecorder::Get());
   return source_id;
 }