Trace Redaction - Replace comm instead of drop comm in proc free

With sched switch and waking events, we've seen issues dropping comm
fields. This issue goes away when they are replaced with an empty
string.

Because proc free events are few, it is hard to find issues in the
Perfetto UI. To be proactive, this updates the proc free primitive to
use the empty string approach.

Change-Id: I29bcc6efdb6081648d9144606af5b540b9a5dc26
diff --git a/src/trace_redaction/redact_process_free.cc b/src/trace_redaction/redact_process_free.cc
index 654b7b2..750ca05 100644
--- a/src/trace_redaction/redact_process_free.cc
+++ b/src/trace_redaction/redact_process_free.cc
@@ -51,24 +51,27 @@
     const protos::pbzero::FtraceEvent::Decoder&,
     protozero::ConstBytes bytes,
     protos::pbzero::FtraceEvent* event_message) const {
-  protos::pbzero::SchedProcessFreeFtraceEvent::Decoder process_free(bytes);
+  // SchedProcessFreeFtraceEvent
+  protozero::ProtoDecoder process_free_decoder(bytes);
 
-  // There must be pid. If there's no pid, dropping the event is the safest
-  // option.
-  if (!process_free.has_pid()) {
+  // There must be pid. If there's no pid, the safest option is to drop it.
+  auto pid = process_free_decoder.FindField(
+      protos::pbzero::SchedProcessFreeFtraceEvent::kPidFieldNumber);
+
+  if (!pid.valid()) {
     return base::OkStatus();
   }
 
-  // Avoid making the message until we know that we have prev and next pids.
   auto* process_free_message = event_message->set_sched_process_free();
 
-  // To read the fields, move the read head back to the start.
-  process_free.Reset();
-
-  for (auto field = process_free.ReadField(); field.valid();
-       field = process_free.ReadField()) {
-    if (field.id() !=
+  // Replace the comm with an empty string instead of dropping the comm field.
+  // The perfetto UI doesn't render things correctly if comm values are missing.
+  for (auto field = process_free_decoder.ReadField(); field.valid();
+       field = process_free_decoder.ReadField()) {
+    if (field.id() ==
         protos::pbzero::SchedProcessFreeFtraceEvent::kCommFieldNumber) {
+      process_free_message->set_comm("");
+    } else {
       proto_util::AppendField(field, process_free_message);
     }
   }