trace_processor: Refactor in order to implement global ordering.
This CL contains the changes to the end of the pipeline.
Specifically, splitting the handling of sched and process events from
the storage into their own class. Trace storage now only stores things.
The main pieces of new code are the Trace processor context and some
handling to clear the TraceStorage. All the rest has mainly just been
moved.
Bug:111389336
Change-Id: I5810375f24bc48837fff73b7ba60ee12ff2f2e1d
diff --git a/src/trace_processor/trace_parser.cc b/src/trace_processor/trace_parser.cc
index 260c0e4..ad04ee3 100644
--- a/src/trace_processor/trace_parser.cc
+++ b/src/trace_processor/trace_parser.cc
@@ -44,9 +44,9 @@
} // namespace
TraceParser::TraceParser(BlobReader* reader,
- TraceStorage* storage,
+ TraceProcessorContext* context,
uint32_t chunk_size_b)
- : reader_(reader), storage_(storage), chunk_size_b_(chunk_size_b) {}
+ : reader_(reader), chunk_size_b_(chunk_size_b), context_(context) {}
bool TraceParser::ParseNextChunk() {
if (!buffer_)
@@ -89,18 +89,12 @@
void TraceParser::ParseProcessTree(const uint8_t* data, size_t length) {
ProtoDecoder decoder(data, length);
- // TODO(taylori): We currently rely on process packets always coming before
- // their corresponding threads. This should be true but it is better
- // not to rely on it.
- bool parsed_thread_packet = false;
for (auto fld = decoder.ReadField(); fld.id != 0; fld = decoder.ReadField()) {
switch (fld.id) {
case protos::ProcessTree::kProcessesFieldNumber:
- PERFETTO_DCHECK(!parsed_thread_packet);
ParseProcess(fld.data(), fld.size());
break;
case protos::ProcessTree::kThreadsFieldNumber:
- parsed_thread_packet = true;
ParseThread(fld.data(), fld.size());
break;
default:
@@ -126,7 +120,7 @@
break;
}
}
- storage_->MatchThreadToProcess(tid, tgid);
+ context_->process_tracker->UpdateThread(tid, tgid);
PERFETTO_DCHECK(decoder.IsEndOfBuffer());
}
@@ -151,7 +145,7 @@
break;
}
}
- storage_->PushProcess(pid, process_name, process_name_len);
+ context_->process_tracker->UpdateProcess(pid, process_name, process_name_len);
PERFETTO_DCHECK(decoder.IsEndOfBuffer());
}
@@ -233,8 +227,8 @@
break;
}
}
- storage_->PushSchedSwitch(cpu, timestamp, prev_pid, prev_state, prev_comm,
- prev_comm_len, next_pid);
+ context_->sched_tracker->PushSchedSwitch(cpu, timestamp, prev_pid, prev_state,
+ prev_comm, prev_comm_len, next_pid);
PERFETTO_DCHECK(decoder.IsEndOfBuffer());
}