trace_processor: initial definition of columnar trace class

This class will form the common point which other classes will read
from/write to. It will be shared across the three virtual tables (event, thread
and process) and be read from.

Bug: 80416541
Change-Id: I9d431a98c2f4d7359338d55a03af09a04c01859e
diff --git a/src/trace_processor/trace_storage.h b/src/trace_processor/trace_storage.h
new file mode 100644
index 0000000..ea2cdf1
--- /dev/null
+++ b/src/trace_processor/trace_storage.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#ifndef SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_
+#define SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_
+
+#include <deque>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+namespace perfetto {
+namespace trace_processor {
+
+// Stores a data inside a trace file in a columnar form. This makes it efficient
+// to read or search across a single field of the trace (e.g. all the thread
+// names for a given CPU).
+class TraceStorage {
+ public:
+  // Adds a sched slice for a given cpu.
+  void AddSliceForCpu(uint32_t cpu,
+                      uint64_t start_timestamp,
+                      uint64_t duration,
+                      const char* thread_name);
+
+  // Reading methods.
+  const std::deque<uint64_t>& start_timestamps_for_cpu(uint32_t cpu) {
+    return cpu_events_[cpu].start_timestamps;
+  }
+
+ private:
+  // Each StringId is an offset into |strings_|.
+  typedef size_t StringId;
+  typedef uint32_t StringHash;
+
+  struct SlicesPerCpu {
+    uint32_t cpu_ = 0;
+
+    // Each vector below has the same number of entries (the number of slices
+    // in the trace for the CPU).
+    std::deque<uint64_t> start_timestamps;
+    std::deque<uint64_t> durations;
+    std::deque<StringId> thread_names;
+  };
+
+  // One entry for each CPU in the trace.
+  std::vector<SlicesPerCpu> cpu_events_;
+
+  // One entry for each unique string in the trace.
+  std::deque<std::string> strings_;
+
+  // One entry for each unique string in the trace.
+  std::unordered_map<StringHash, StringId> string_pool_;
+};
+
+}  // namespace trace_processor
+}  // namespace perfetto
+
+#endif  // SRC_TRACE_PROCESSOR_TRACE_STORAGE_H_