TraceProcessor: extract Iterator{,Impl} into their own classes

Non-functional refactoring. This is just to allow
Iterator (and IteratorImpl) to be forward declared and
prevent circular dependencies.
Also keeps the codebase a bit cleaner keeping one class
per header with a matching name.

Change-Id: I30a2d9a9fd8e6042d6a98ee029dd37f824e61f98
diff --git a/Android.bp b/Android.bp
index b1fdcd5..15d8883 100644
--- a/Android.bp
+++ b/Android.bp
@@ -6573,6 +6573,7 @@
     "src/trace_processor/dynamic/experimental_counter_dur_generator.cc",
     "src/trace_processor/dynamic/experimental_flamegraph_generator.cc",
     "src/trace_processor/dynamic/experimental_slice_layout_generator.cc",
+    "src/trace_processor/iterator_impl.cc",
     "src/trace_processor/read_trace.cc",
     "src/trace_processor/trace_processor.cc",
     "src/trace_processor/trace_processor_impl.cc",
diff --git a/BUILD b/BUILD
index f426d10..d13caca 100644
--- a/BUILD
+++ b/BUILD
@@ -452,6 +452,7 @@
 filegroup(
     name = "include_perfetto_trace_processor_trace_processor",
     srcs = [
+        "include/perfetto/trace_processor/iterator.h",
         "include/perfetto/trace_processor/read_trace.h",
         "include/perfetto/trace_processor/trace_processor.h",
     ],
@@ -936,6 +937,8 @@
         "src/trace_processor/dynamic/experimental_flamegraph_generator.h",
         "src/trace_processor/dynamic/experimental_slice_layout_generator.cc",
         "src/trace_processor/dynamic/experimental_slice_layout_generator.h",
+        "src/trace_processor/iterator_impl.cc",
+        "src/trace_processor/iterator_impl.h",
         "src/trace_processor/read_trace.cc",
         "src/trace_processor/trace_processor.cc",
         "src/trace_processor/trace_processor_impl.cc",
diff --git a/include/perfetto/trace_processor/BUILD.gn b/include/perfetto/trace_processor/BUILD.gn
index 8db2a2f..bdaf789 100644
--- a/include/perfetto/trace_processor/BUILD.gn
+++ b/include/perfetto/trace_processor/BUILD.gn
@@ -14,6 +14,7 @@
 
 source_set("trace_processor") {
   sources = [
+    "iterator.h",
     "read_trace.h",
     "trace_processor.h",
   ]
diff --git a/include/perfetto/trace_processor/iterator.h b/include/perfetto/trace_processor/iterator.h
new file mode 100644
index 0000000..9578f8f
--- /dev/null
+++ b/include/perfetto/trace_processor/iterator.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2020 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 INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_
+#define INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_
+
+#include <stdint.h>
+
+#include <memory>
+
+#include "perfetto/base/export.h"
+#include "perfetto/trace_processor/basic_types.h"
+#include "perfetto/trace_processor/status.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+class IteratorImpl;
+
+// Iterator returning SQL rows satisfied by a query.
+class PERFETTO_EXPORT Iterator {
+ public:
+  explicit Iterator(std::unique_ptr<IteratorImpl>);
+  ~Iterator();
+
+  Iterator(Iterator&) noexcept = delete;
+  Iterator& operator=(Iterator&) = delete;
+
+  Iterator(Iterator&&) noexcept;
+  Iterator& operator=(Iterator&&);
+
+  // Forwards the iterator to the next result row and returns a boolean of
+  // whether there is a next row. If this method returns false,
+  // |Status()| should be called to check if there was an error. If
+  // there was no error, this means the EOF was reached.
+  bool Next();
+
+  // Returns the value associated with the column |col|. Any call to
+  // |Get()| must be preceded by a call to |Next()| returning
+  // kHasNext. |col| must be less than the number returned by |ColumnCount()|.
+  SqlValue Get(uint32_t col);
+
+  // Returns the name of the column at index |col|. Can be called even before
+  // calling |Next()|.
+  std::string GetColumnName(uint32_t col);
+
+  // Returns the number of columns in this iterator's query. Can be called
+  // even before calling |Next()|.
+  uint32_t ColumnCount();
+
+  // Returns the status of the iterator.
+  util::Status Status();
+
+ private:
+  // A PIMPL pattern is used to avoid leaking the dependencies on sqlite3.h and
+  // other internal classes.
+  std::unique_ptr<IteratorImpl> iterator_;
+};
+
+}  // namespace trace_processor
+}  // namespace perfetto
+
+#endif  // INCLUDE_PERFETTO_TRACE_PROCESSOR_ITERATOR_H_
diff --git a/include/perfetto/trace_processor/trace_processor.h b/include/perfetto/trace_processor/trace_processor.h
index 920c3fa..0cc7dbf 100644
--- a/include/perfetto/trace_processor/trace_processor.h
+++ b/include/perfetto/trace_processor/trace_processor.h
@@ -23,6 +23,7 @@
 #include "perfetto/base/build_config.h"
 #include "perfetto/base/export.h"
 #include "perfetto/trace_processor/basic_types.h"
+#include "perfetto/trace_processor/iterator.h"
 #include "perfetto/trace_processor/status.h"
 #include "perfetto/trace_processor/trace_processor_storage.h"
 
@@ -33,45 +34,9 @@
 // traces. See TraceProcessorStorage for parsing of trace files.
 class PERFETTO_EXPORT TraceProcessor : public TraceProcessorStorage {
  public:
-  class IteratorImpl;
-
-  // Iterator returning SQL rows satisfied by a query.
-  class Iterator {
-   public:
-    Iterator(std::unique_ptr<IteratorImpl> iterator);
-    ~Iterator();
-
-    Iterator(Iterator&) noexcept = delete;
-    Iterator& operator=(Iterator&) = delete;
-
-    Iterator(Iterator&&) noexcept;
-    Iterator& operator=(Iterator&&);
-
-    // Forwards the iterator to the next result row and returns a boolean of
-    // whether there is a next row. If this method returns false,
-    // |Status()| should be called to check if there was an error. If
-    // there was no error, this means the EOF was reached.
-    bool Next();
-
-    // Returns the value associated with the column |col|. Any call to
-    // |Get()| must be preceded by a call to |Next()| returning
-    // kHasNext. |col| must be less than the number returned by |ColumnCount()|.
-    SqlValue Get(uint32_t col);
-
-    // Returns the name of the column at index |col|. Can be called even before
-    // calling |Next()|.
-    std::string GetColumnName(uint32_t col);
-
-    // Returns the number of columns in this iterator's query. Can be called
-    // even before calling |Next()|.
-    uint32_t ColumnCount();
-
-    // Returns the status of the iterator.
-    util::Status Status();
-
-   private:
-    std::unique_ptr<IteratorImpl> iterator_;
-  };
+  // For legacy API clients. Iterator used to be a nested class here. Many API
+  // clients depends on it at this point.
+  using Iterator = ::perfetto::trace_processor::Iterator;
 
   // Creates a new instance of TraceProcessor.
   static std::unique_ptr<TraceProcessor> CreateInstance(const Config&);
diff --git a/src/profiling/symbolizer/symbolize_database.cc b/src/profiling/symbolizer/symbolize_database.cc
index 462e836..a608bc0 100644
--- a/src/profiling/symbolizer/symbolize_database.cc
+++ b/src/profiling/symbolizer/symbolize_database.cc
@@ -34,7 +34,7 @@
 namespace profiling {
 
 namespace {
-using Iterator = trace_processor::TraceProcessor::Iterator;
+using trace_processor::Iterator;
 
 constexpr const char* kQueryUnsymbolized =
     "select spm.name, spm.build_id, spf.rel_pc "
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index 2b26b7e..0e2f47a 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -206,10 +206,10 @@
     "importers/proto/android_probes_parser.h",
     "importers/proto/android_probes_tracker.cc",
     "importers/proto/android_probes_tracker.h",
-    "importers/proto/graphics_event_module.cc",
-    "importers/proto/graphics_event_module.h",
     "importers/proto/gpu_event_parser.cc",
     "importers/proto/gpu_event_parser.h",
+    "importers/proto/graphics_event_module.cc",
+    "importers/proto/graphics_event_module.h",
     "importers/proto/graphics_frame_event_parser.cc",
     "importers/proto/graphics_frame_event_parser.h",
     "importers/proto/heap_graph_module.cc",
@@ -286,6 +286,8 @@
       "dynamic/experimental_flamegraph_generator.h",
       "dynamic/experimental_slice_layout_generator.cc",
       "dynamic/experimental_slice_layout_generator.h",
+      "iterator_impl.cc",
+      "iterator_impl.h",
       "read_trace.cc",
       "trace_processor.cc",
       "trace_processor_impl.cc",
diff --git a/src/trace_processor/iterator_impl.cc b/src/trace_processor/iterator_impl.cc
new file mode 100644
index 0000000..bf6e507
--- /dev/null
+++ b/src/trace_processor/iterator_impl.cc
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2020 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/iterator_impl.h"
+
+#include "perfetto/base/time.h"
+#include "perfetto/trace_processor/trace_processor_storage.h"
+#include "src/trace_processor/storage/trace_storage.h"
+#include "src/trace_processor/trace_processor_impl.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+IteratorImpl::IteratorImpl(TraceProcessorImpl* trace_processor,
+                           sqlite3* db,
+                           ScopedStmt stmt,
+                           uint32_t column_count,
+                           util::Status status,
+                           uint32_t sql_stats_row)
+    : trace_processor_(trace_processor),
+      db_(db),
+      stmt_(std::move(stmt)),
+      column_count_(column_count),
+      status_(status),
+      sql_stats_row_(sql_stats_row) {}
+
+IteratorImpl::~IteratorImpl() {
+  if (trace_processor_) {
+    auto* its = &trace_processor_->iterators_;
+    auto it = std::find(its->begin(), its->end(), this);
+    PERFETTO_CHECK(it != its->end());
+    its->erase(it);
+
+    base::TimeNanos t_end = base::GetWallTimeNs();
+    auto* sql_stats = trace_processor_->context_.storage->mutable_sql_stats();
+    sql_stats->RecordQueryEnd(sql_stats_row_, t_end.count());
+  }
+}
+
+void IteratorImpl::Reset() {
+  *this = IteratorImpl(nullptr, nullptr, ScopedStmt(), 0,
+                       util::ErrStatus("Trace processor was deleted"), 0);
+}
+
+void IteratorImpl::RecordFirstNextInSqlStats() {
+  base::TimeNanos t_first_next = base::GetWallTimeNs();
+  auto* sql_stats = trace_processor_->context_.storage->mutable_sql_stats();
+  sql_stats->RecordQueryFirstNext(sql_stats_row_, t_first_next.count());
+}
+
+Iterator::Iterator(std::unique_ptr<IteratorImpl> iterator)
+    : iterator_(std::move(iterator)) {}
+Iterator::~Iterator() = default;
+
+Iterator::Iterator(Iterator&&) noexcept = default;
+Iterator& Iterator::operator=(Iterator&&) = default;
+
+bool Iterator::Next() {
+  return iterator_->Next();
+}
+
+SqlValue Iterator::Get(uint32_t col) {
+  return iterator_->Get(col);
+}
+
+std::string Iterator::GetColumnName(uint32_t col) {
+  return iterator_->GetColumnName(col);
+}
+
+uint32_t Iterator::ColumnCount() {
+  return iterator_->ColumnCount();
+}
+
+util::Status Iterator::Status() {
+  return iterator_->Status();
+}
+
+}  // namespace trace_processor
+}  // namespace perfetto
diff --git a/src/trace_processor/iterator_impl.h b/src/trace_processor/iterator_impl.h
new file mode 100644
index 0000000..3613f29
--- /dev/null
+++ b/src/trace_processor/iterator_impl.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2020 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_ITERATOR_IMPL_H_
+#define SRC_TRACE_PROCESSOR_ITERATOR_IMPL_H_
+
+#include <sqlite3.h>
+
+#include <memory>
+#include <vector>
+
+#include "perfetto/base/build_config.h"
+#include "perfetto/base/export.h"
+#include "perfetto/trace_processor/basic_types.h"
+#include "perfetto/trace_processor/iterator.h"
+#include "perfetto/trace_processor/status.h"
+#include "src/trace_processor/sqlite/scoped_db.h"
+
+namespace perfetto {
+namespace trace_processor {
+
+class TraceProcessorImpl;
+
+class IteratorImpl {
+ public:
+  IteratorImpl(TraceProcessorImpl* impl,
+               sqlite3* db,
+               ScopedStmt,
+               uint32_t column_count,
+               util::Status,
+               uint32_t sql_stats_row);
+  ~IteratorImpl();
+
+  IteratorImpl(IteratorImpl&) noexcept = delete;
+  IteratorImpl& operator=(IteratorImpl&) = delete;
+
+  IteratorImpl(IteratorImpl&&) noexcept = default;
+  IteratorImpl& operator=(IteratorImpl&&) = default;
+
+  // Methods called by the base Iterator class.
+  bool Next() {
+    // Delegate to the cc file to prevent trace_storage.h include in this file.
+    if (!called_next_) {
+      RecordFirstNextInSqlStats();
+      called_next_ = true;
+    }
+
+    if (!status_.ok())
+      return false;
+
+    int ret = sqlite3_step(*stmt_);
+    if (PERFETTO_UNLIKELY(ret != SQLITE_ROW && ret != SQLITE_DONE)) {
+      status_ = util::ErrStatus("%s", sqlite3_errmsg(db_));
+      return false;
+    }
+    return ret == SQLITE_ROW;
+  }
+
+  SqlValue Get(uint32_t col) {
+    auto column = static_cast<int>(col);
+    auto col_type = sqlite3_column_type(*stmt_, column);
+    SqlValue value;
+    switch (col_type) {
+      case SQLITE_INTEGER:
+        value.type = SqlValue::kLong;
+        value.long_value = sqlite3_column_int64(*stmt_, column);
+        break;
+      case SQLITE_TEXT:
+        value.type = SqlValue::kString;
+        value.string_value =
+            reinterpret_cast<const char*>(sqlite3_column_text(*stmt_, column));
+        break;
+      case SQLITE_FLOAT:
+        value.type = SqlValue::kDouble;
+        value.double_value = sqlite3_column_double(*stmt_, column);
+        break;
+      case SQLITE_BLOB:
+        value.type = SqlValue::kBytes;
+        value.bytes_value = sqlite3_column_blob(*stmt_, column);
+        value.bytes_count =
+            static_cast<size_t>(sqlite3_column_bytes(*stmt_, column));
+        break;
+      case SQLITE_NULL:
+        value.type = SqlValue::kNull;
+        break;
+    }
+    return value;
+  }
+
+  std::string GetColumnName(uint32_t col) {
+    return sqlite3_column_name(stmt_.get(), static_cast<int>(col));
+  }
+
+  uint32_t ColumnCount() { return column_count_; }
+
+  util::Status Status() { return status_; }
+
+  // Methods called by TraceProcessorImpl.
+  void Reset();
+
+ private:
+  void RecordFirstNextInSqlStats();
+
+  TraceProcessorImpl* trace_processor_;
+  sqlite3* db_ = nullptr;
+  ScopedStmt stmt_;
+  uint32_t column_count_ = 0;
+  util::Status status_;
+
+  uint32_t sql_stats_row_ = 0;
+  bool called_next_ = false;
+};
+
+}  // namespace trace_processor
+}  // namespace perfetto
+
+#endif  // SRC_TRACE_PROCESSOR_ITERATOR_IMPL_H_
diff --git a/src/trace_processor/trace_database_integrationtest.cc b/src/trace_processor/trace_database_integrationtest.cc
index 0255ed5..fb80e77 100644
--- a/src/trace_processor/trace_database_integrationtest.cc
+++ b/src/trace_processor/trace_database_integrationtest.cc
@@ -55,7 +55,7 @@
     return util::OkStatus();
   }
 
-  TraceProcessor::Iterator Query(const std::string& query) {
+  Iterator Query(const std::string& query) {
     return processor_->ExecuteQuery(query.c_str());
   }
 
diff --git a/src/trace_processor/trace_processor.cc b/src/trace_processor/trace_processor.cc
index 9be89e5..72b0b1d 100644
--- a/src/trace_processor/trace_processor.cc
+++ b/src/trace_processor/trace_processor.cc
@@ -30,35 +30,6 @@
 
 TraceProcessor::~TraceProcessor() = default;
 
-TraceProcessor::Iterator::Iterator(std::unique_ptr<IteratorImpl> iterator)
-    : iterator_(std::move(iterator)) {}
-TraceProcessor::Iterator::~Iterator() = default;
-
-TraceProcessor::Iterator::Iterator(TraceProcessor::Iterator&&) noexcept =
-    default;
-TraceProcessor::Iterator& TraceProcessor::Iterator::operator=(
-    TraceProcessor::Iterator&&) = default;
-
-bool TraceProcessor::Iterator::Next() {
-  return iterator_->Next();
-}
-
-SqlValue TraceProcessor::Iterator::Get(uint32_t col) {
-  return iterator_->Get(col);
-}
-
-std::string TraceProcessor::Iterator::GetColumnName(uint32_t col) {
-  return iterator_->GetColumnName(col);
-}
-
-uint32_t TraceProcessor::Iterator::ColumnCount() {
-  return iterator_->ColumnCount();
-}
-
-util::Status TraceProcessor::Iterator::Status() {
-  return iterator_->Status();
-}
-
 // static
 void EnableSQLiteVtableDebugging() {
   // This level of indirection is required to avoid clients to depend on table.h
diff --git a/src/trace_processor/trace_processor_impl.cc b/src/trace_processor/trace_processor_impl.cc
index ae171f4..0efb1a0 100644
--- a/src/trace_processor/trace_processor_impl.cc
+++ b/src/trace_processor/trace_processor_impl.cc
@@ -37,6 +37,7 @@
 #include "src/trace_processor/importers/json/json_trace_tokenizer.h"
 #include "src/trace_processor/importers/proto/metadata_tracker.h"
 #include "src/trace_processor/importers/systrace/systrace_trace_parser.h"
+#include "src/trace_processor/iterator_impl.h"
 #include "src/trace_processor/sqlite/span_join_operator_table.h"
 #include "src/trace_processor/sqlite/sql_stats_table.h"
 #include "src/trace_processor/sqlite/sqlite3_str_split.h"
@@ -705,9 +706,8 @@
   return deletion_list.size();
 }
 
-TraceProcessor::Iterator TraceProcessorImpl::ExecuteQuery(
-    const std::string& sql,
-    int64_t time_queued) {
+Iterator TraceProcessorImpl::ExecuteQuery(const std::string& sql,
+                                          int64_t time_queued) {
   sqlite3_stmt* raw_stmt;
   int err;
   {
@@ -732,7 +732,7 @@
   std::unique_ptr<IteratorImpl> impl(new IteratorImpl(
       this, *db_, ScopedStmt(raw_stmt), col_count, status, sql_stats_row));
   iterators_.emplace_back(impl.get());
-  return TraceProcessor::Iterator(std::move(impl));
+  return Iterator(std::move(impl));
 }
 
 void TraceProcessorImpl::InterruptQuery() {
@@ -854,42 +854,5 @@
   return util::OkStatus();
 }
 
-TraceProcessor::IteratorImpl::IteratorImpl(TraceProcessorImpl* trace_processor,
-                                           sqlite3* db,
-                                           ScopedStmt stmt,
-                                           uint32_t column_count,
-                                           util::Status status,
-                                           uint32_t sql_stats_row)
-    : trace_processor_(trace_processor),
-      db_(db),
-      stmt_(std::move(stmt)),
-      column_count_(column_count),
-      status_(status),
-      sql_stats_row_(sql_stats_row) {}
-
-TraceProcessor::IteratorImpl::~IteratorImpl() {
-  if (trace_processor_) {
-    auto* its = &trace_processor_->iterators_;
-    auto it = std::find(its->begin(), its->end(), this);
-    PERFETTO_CHECK(it != its->end());
-    its->erase(it);
-
-    base::TimeNanos t_end = base::GetWallTimeNs();
-    auto* sql_stats = trace_processor_->context_.storage->mutable_sql_stats();
-    sql_stats->RecordQueryEnd(sql_stats_row_, t_end.count());
-  }
-}
-
-void TraceProcessor::IteratorImpl::Reset() {
-  *this = IteratorImpl(nullptr, nullptr, ScopedStmt(), 0,
-                       util::ErrStatus("Trace processor was deleted"), 0);
-}
-
-void TraceProcessor::IteratorImpl::RecordFirstNextInSqlStats() {
-  base::TimeNanos t_first_next = base::GetWallTimeNs();
-  auto* sql_stats = trace_processor_->context_.storage->mutable_sql_stats();
-  sql_stats->RecordQueryFirstNext(sql_stats_row_, t_first_next.count());
-}
-
 }  // namespace trace_processor
 }  // namespace perfetto
diff --git a/src/trace_processor/trace_processor_impl.h b/src/trace_processor/trace_processor_impl.h
index c2523a2..84a74f2 100644
--- a/src/trace_processor/trace_processor_impl.h
+++ b/src/trace_processor/trace_processor_impl.h
@@ -113,96 +113,6 @@
   uint64_t bytes_parsed_ = 0;
 };
 
-// The pointer implementation of TraceProcessor::Iterator.
-class TraceProcessor::IteratorImpl {
- public:
-  IteratorImpl(TraceProcessorImpl* impl,
-               sqlite3* db,
-               ScopedStmt,
-               uint32_t column_count,
-               util::Status,
-               uint32_t sql_stats_row);
-  ~IteratorImpl();
-
-  IteratorImpl(IteratorImpl&) noexcept = delete;
-  IteratorImpl& operator=(IteratorImpl&) = delete;
-
-  IteratorImpl(IteratorImpl&&) noexcept = default;
-  IteratorImpl& operator=(IteratorImpl&&) = default;
-
-  // Methods called by TraceProcessor::Iterator.
-  bool Next() {
-    // Delegate to the cc file to prevent trace_storage.h include in this file.
-    if (!called_next_) {
-      RecordFirstNextInSqlStats();
-      called_next_ = true;
-    }
-
-    if (!status_.ok())
-      return false;
-
-    int ret = sqlite3_step(*stmt_);
-    if (PERFETTO_UNLIKELY(ret != SQLITE_ROW && ret != SQLITE_DONE)) {
-      status_ = util::ErrStatus("%s", sqlite3_errmsg(db_));
-      return false;
-    }
-    return ret == SQLITE_ROW;
-  }
-
-  SqlValue Get(uint32_t col) {
-    auto column = static_cast<int>(col);
-    auto col_type = sqlite3_column_type(*stmt_, column);
-    SqlValue value;
-    switch (col_type) {
-      case SQLITE_INTEGER:
-        value.type = SqlValue::kLong;
-        value.long_value = sqlite3_column_int64(*stmt_, column);
-        break;
-      case SQLITE_TEXT:
-        value.type = SqlValue::kString;
-        value.string_value =
-            reinterpret_cast<const char*>(sqlite3_column_text(*stmt_, column));
-        break;
-      case SQLITE_FLOAT:
-        value.type = SqlValue::kDouble;
-        value.double_value = sqlite3_column_double(*stmt_, column);
-        break;
-      case SQLITE_BLOB:
-        value.type = SqlValue::kBytes;
-        value.bytes_value = sqlite3_column_blob(*stmt_, column);
-        value.bytes_count =
-            static_cast<size_t>(sqlite3_column_bytes(*stmt_, column));
-        break;
-      case SQLITE_NULL:
-        value.type = SqlValue::kNull;
-        break;
-    }
-    return value;
-  }
-
-  std::string GetColumnName(uint32_t col) {
-    return sqlite3_column_name(stmt_.get(), static_cast<int>(col));
-  }
-
-  uint32_t ColumnCount() { return column_count_; }
-
-  util::Status Status() { return status_; }
-
-  // Methods called by TraceProcessorImpl.
-  void Reset();
-
- private:
-  void RecordFirstNextInSqlStats();
-
-  TraceProcessorImpl* trace_processor_;
-  sqlite3* db_ = nullptr;
-  ScopedStmt stmt_;
-  uint32_t column_count_ = 0;
-  util::Status status_;
-
-  uint32_t sql_stats_row_ = 0;
-  bool called_next_ = false;
-};
 
 }  // namespace trace_processor
 }  // namespace perfetto
diff --git a/src/trace_processor/trace_processor_shell.cc b/src/trace_processor/trace_processor_shell.cc
index f79b57e..0d8565e 100644
--- a/src/trace_processor/trace_processor_shell.cc
+++ b/src/trace_processor/trace_processor_shell.cc
@@ -437,7 +437,7 @@
   return util::OkStatus();
 }
 
-void PrintQueryResultInteractively(TraceProcessor::Iterator* it,
+void PrintQueryResultInteractively(Iterator* it,
                                    base::TimeNanos t_start,
                                    uint32_t column_width) {
   base::TimeNanos t_end = t_start;
@@ -543,7 +543,7 @@
   return util::OkStatus();
 }
 
-util::Status PrintQueryResultAsCsv(TraceProcessor::Iterator* it, FILE* output) {
+util::Status PrintQueryResultAsCsv(Iterator* it, FILE* output) {
   for (uint32_t c = 0; c < it->ColumnCount(); c++) {
     if (c > 0)
       fprintf(output, ",");
diff --git a/tools/trace_to_text/pprof_builder.cc b/tools/trace_to_text/pprof_builder.cc
index 54a1527..d95f0cc 100644
--- a/tools/trace_to_text/pprof_builder.cc
+++ b/tools/trace_to_text/pprof_builder.cc
@@ -76,7 +76,7 @@
 const View kViews[] = {kAllocObjectsView, kObjectsView, kAllocSpaceView,
                        kSpaceView};
 
-using Iterator = trace_processor::TraceProcessor::Iterator;
+using trace_processor::Iterator;
 
 constexpr const char* kQueryProfiles =
     "select distinct hpa.upid, hpa.ts, p.pid from heap_profile_allocation hpa, "
diff --git a/tools/trace_to_text/trace_to_systrace.cc b/tools/trace_to_text/trace_to_systrace.cc
index e5900c8..d2c4f44 100644
--- a/tools/trace_to_text/trace_to_systrace.cc
+++ b/tools/trace_to_text/trace_to_systrace.cc
@@ -190,7 +190,7 @@
                     TraceWriter* trace_writer,
                     bool wrapped_in_json,
                     Keep truncate_keep) {
-  using Iterator = trace_processor::TraceProcessor::Iterator;
+  using trace_processor::Iterator;
 
   QueryWriter q_writer(tp, trace_writer);
   if (wrapped_in_json) {
diff --git a/tools/trace_to_text/utils.cc b/tools/trace_to_text/utils.cc
index 64a4aee..ee2cebb 100644
--- a/tools/trace_to_text/utils.cc
+++ b/tools/trace_to_text/utils.cc
@@ -37,7 +37,7 @@
 namespace trace_to_text {
 namespace {
 
-using Iterator = trace_processor::TraceProcessor::Iterator;
+using trace_processor::Iterator;
 
 #if PERFETTO_BUILDFLAG(PERFETTO_ZLIB)
 constexpr size_t kCompressionBufferSize = 500 * 1024;