trace_processor: add base trace loading code
This CL sets out the foundation for the trace loading code.
Specifically, it introduces BlobReader (an abstraction for reading data
from an arbitary data source into a buffer) and TraceLoader.
TraceLoader will use BlobReader and a class known as ProtoParser (to be
introduced in a follow-up CL) to read and parse the trace packets and
place them in the ColumnarTrace introduced in the previous CL
Bug: 80416541
Change-Id: I5eb725ff6676b3ecb12daba74e8f0dc766eff11e
diff --git a/src/trace_processor/trace_parser.cc b/src/trace_processor/trace_parser.cc
new file mode 100644
index 0000000..355c6f1
--- /dev/null
+++ b/src/trace_processor/trace_parser.cc
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "src/trace_processor/trace_parser.h"
+
+#include "perfetto/base/utils.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+TraceParser::TraceParser(BlobReader* reader,
+ TraceStorage* trace,
+ uint32_t chunk_size_b)
+ : reader_(reader), trace_(trace), chunk_size_b_(chunk_size_b) {}
+
+void TraceParser::LoadNextChunk() {
+ if (!buffer_)
+ buffer_.reset(new uint8_t[chunk_size_b_]);
+
+ uint32_t read = reader_->Read(offset_, chunk_size_b_, buffer_.get());
+ if (read == 0)
+ return;
+
+ // TODO(lalitm): actually parse the data read here.
+ base::ignore_result(trace_);
+
+ offset_ += read;
+}
+
+} // namespace trace_processor
+} // namespace perfetto