trace_processor: Flatten CPU freq storage and remove cycles

In order to join the cpu freq information quickly with the sched table
the cpu freq events need to be in timestamp order, rather than
stored per cpu. A side effect of that is that we can't quickly compute
cycles the way that we were doing before, but that's OK because we
can compute cycles when we span join with the sched table.

The counters table is not optimised. We let SQLite do the
filtering and ordering for now.

Since the counters are no longer stored by cpu, duration can not
be computed on the fly. Instead a stage is added to sched_tracker
(rename pending) similar to the sched slices that waits for the next
event on the same cpu before outputting the prev event with it's
duration.

Change-Id: I27da5366aae6bd4cf6a7d30b1e248b938f50b965
diff --git a/src/trace_processor/proto_trace_parser.cc b/src/trace_processor/proto_trace_parser.cc
index 8cf1101..78ee7ad 100644
--- a/src/trace_processor/proto_trace_parser.cc
+++ b/src/trace_processor/proto_trace_parser.cc
@@ -84,7 +84,8 @@
 using protozero::proto_utils::kFieldTypeLengthDelimited;
 
 ProtoTraceParser::ProtoTraceParser(TraceProcessorContext* context)
-    : context_(context) {}
+    : context_(context),
+      cpu_freq_name_id_(context->storage->InternString("cpufreq")) {}
 
 ProtoTraceParser::~ProtoTraceParser() = default;
 
@@ -204,20 +205,20 @@
 void ProtoTraceParser::ParseCpuFreq(uint64_t timestamp, TraceBlobView view) {
   ProtoDecoder decoder(view.data(), view.length());
 
-  uint32_t cpu = 0;
+  uint32_t cpu_affected = 0;
   uint32_t new_freq = 0;
   for (auto fld = decoder.ReadField(); fld.id != 0; fld = decoder.ReadField()) {
     switch (fld.id) {
       case protos::CpuFrequencyFtraceEvent::kCpuIdFieldNumber:
-        cpu = fld.as_uint32();
+        cpu_affected = fld.as_uint32();
         break;
       case protos::CpuFrequencyFtraceEvent::kStateFieldNumber:
         new_freq = fld.as_uint32();
         break;
     }
   }
-
-  context_->storage->PushCpuFreq(timestamp, cpu, new_freq);
+  context_->sched_tracker->PushCounter(timestamp, new_freq, cpu_freq_name_id_,
+                                       cpu_affected, RefType::kCPU_ID);
 
   PERFETTO_DCHECK(decoder.IsEndOfBuffer());
 }