traced_perf: avoid unnecessary PostTasks when writing packets due to reading frontend

This also fixes a bug in the enqueued footprint accounting (line 600
before) - the discarded sample was moved (without discarding the sampled
stack) into a task, and therefore stayed allocated until the
EmitSkippedSample task had run.

Change-Id: Ied9ec73436478897b44b1e09415ffaeeb53ec2a5
diff --git a/src/profiling/perf/perf_producer.cc b/src/profiling/perf/perf_producer.cc
index d837494..7794192 100644
--- a/src/profiling/perf/perf_producer.cc
+++ b/src/profiling/perf/perf_producer.cc
@@ -538,7 +538,7 @@
     if (!ds->event_config.sample_callstacks()) {
       CompletedSample output;
       output.common = sample->common;
-      PostEmitSample(ds_id, std::move(output));
+      EmitSample(ds_id, std::move(output));
       continue;
     }
 
@@ -554,8 +554,8 @@
     if (process_state == ProcessTrackingStatus::kExpired) {
       PERFETTO_DLOG("Skipping sample for previously expired pid [%d]",
                     static_cast<int>(pid));
-      PostEmitSkippedSample(ds_id, std::move(sample.value()),
-                            SampleSkipReason::kReadStage);
+      EmitSkippedSample(ds_id, std::move(sample.value()),
+                        SampleSkipReason::kReadStage);
       continue;
     }
 
@@ -597,8 +597,8 @@
       uint64_t footprint_bytes = unwinding_worker_->GetEnqueuedFootprint();
       if (footprint_bytes + sample_stack_size >= max_footprint_bytes) {
         PERFETTO_DLOG("Skipping sample enqueueing due to footprint limit.");
-        PostEmitSkippedSample(ds_id, std::move(sample.value()),
-                              SampleSkipReason::kUnwindEnqueue);
+        EmitSkippedSample(ds_id, std::move(sample.value()),
+                          SampleSkipReason::kUnwindEnqueue);
         continue;
       }
     }
@@ -613,8 +613,8 @@
       unwinding_worker_->IncrementEnqueuedFootprint(sample_stack_size);
     } else {
       PERFETTO_DLOG("Unwinder queue full, skipping sample");
-      PostEmitSkippedSample(ds_id, std::move(sample.value()),
-                            SampleSkipReason::kUnwindEnqueue);
+      EmitSkippedSample(ds_id, std::move(sample.value()),
+                        SampleSkipReason::kUnwindEnqueue);
     }
   }