diff options
Diffstat (limited to 'src/trace_processor/db/column.h')
-rw-r--r-- | src/trace_processor/db/column.h | 110 |
1 files changed, 75 insertions, 35 deletions
diff --git a/src/trace_processor/db/column.h b/src/trace_processor/db/column.h index 17ebe2d19..24ff8f5c1 100644 --- a/src/trace_processor/db/column.h +++ b/src/trace_processor/db/column.h @@ -30,6 +30,19 @@ namespace perfetto { namespace trace_processor { +// Id type which can be used as a base for strongly typed ids. +// TypedColumn has support for storing descendents of BaseId seamlessly +// in a Column. +struct BaseId { + BaseId() = default; + explicit constexpr BaseId(uint32_t v) : value(v) {} + + bool operator==(const BaseId& o) const { return o.value == value; } + bool operator<(const BaseId& o) const { return value < o.value; } + + uint32_t value; +}; + // Represents the possible filter operations on a column. enum class FilterOp { kEq, @@ -40,8 +53,6 @@ enum class FilterOp { kLe, kIsNull, kIsNotNull, - kLike, - kGlob, }; // Represents a constraint on a column. @@ -85,8 +96,17 @@ class Column { // This is used to speed up filters as we can safely index SparseVector // directly if this flag is set. kNonNull = 1 << 1, + + // Indicates that the data in the column is "hidden". This can by used to + // hint to users of Table and Column that this column should not be + // displayed to the user as it is part of the internal implementation + // details of the table. + kHidden = 1 << 2, }; + // Flags specified for an id column. + static constexpr uint32_t kIdFlags = Flag::kSorted | Flag::kNonNull; + template <typename T> Column(const char* name, SparseVector<T>* storage, @@ -100,7 +120,8 @@ class Column { table, col_idx_in_table, row_map_idx, - storage) {} + storage, + nullptr) {} // Create a Column has the same name and is backed by the same data as // |column| but is associated to a different table. @@ -113,6 +134,18 @@ class Column { Column(Column&&) noexcept = default; Column& operator=(Column&&) = default; + template <typename T> + static Column WithOwnedStorage(const char* name, + std::unique_ptr<SparseVector<T>> storage, + /* Flag */ uint32_t flags, + Table* table, + uint32_t col_idx_in_table, + uint32_t row_map_idx) { + SparseVector<T>* ptr = storage.get(); + return Column(name, ToColumnType<T>(), flags, table, col_idx_in_table, + row_map_idx, ptr, std::move(storage)); + } + // Creates a Column which returns the index as the value of the row. static Column IdColumn(Table* table, uint32_t col_idx_in_table, @@ -257,19 +290,12 @@ class Column { const char* name() const { return name_; } // Returns the type of this Column in terms of SqlValue::Type. - SqlValue::Type type() const { - switch (type_) { - case ColumnType::kInt32: - case ColumnType::kUint32: - case ColumnType::kInt64: - case ColumnType::kId: - return SqlValue::Type::kLong; - case ColumnType::kDouble: - return SqlValue::Type::kDouble; - case ColumnType::kString: - return SqlValue::Type::kString; - } - PERFETTO_FATAL("For GCC"); + SqlValue::Type type() const { return ToSqlValueType(type_); } + + // Test the type of this Column. + template <typename T> + bool IsColumnType() const { + return ToColumnType<T>() == type_; } // Returns the index of the current column in the containing table. @@ -309,13 +335,6 @@ class Column { JoinKey join_key() const { return JoinKey{col_idx_in_table_}; } protected: - // Returns the string at the index |idx|. - // Should only be called when |type_| == ColumnType::kString. - NullTermStringView GetStringPoolStringAtIdx(uint32_t idx) const { - PERFETTO_DCHECK(type_ == ColumnType::kString); - return string_pool_->Get(sparse_vector<StringPool::Id>().GetNonNull(idx)); - } - // Returns the backing sparse vector cast to contain data of type T. // Should only be called when |type_| == ToColumnType<T>(). template <typename T> @@ -332,15 +351,10 @@ class Column { return *static_cast<const SparseVector<T>*>(sparse_vector_); } - // Converts a primitive numeric value to an SqlValue of the correct type. + // Returns the type of this Column in terms of SqlValue::Type. template <typename T> - static SqlValue NumericToSqlValue(T value) { - if (std::is_same<T, double>::value) { - return SqlValue::Double(value); - } else if (std::is_convertible<T, int64_t>::value) { - return SqlValue::Long(value); - } - PERFETTO_FATAL("Invalid type"); + static SqlValue::Type ToSqlValueType() { + return ToSqlValueType(ToColumnType<T>()); } const StringPool& string_pool() const { return *string_pool_; } @@ -410,7 +424,8 @@ class Column { Table* table, uint32_t col_idx_in_table, uint32_t row_map_idx, - void* sparse_vector); + SparseVectorBase* sparse_vector, + std::shared_ptr<SparseVectorBase> owned_sparse_vector); Column(const Column&) = delete; Column& operator=(const Column&) = delete; @@ -485,11 +500,9 @@ class Column { rm->Intersect(RowMap(beg, row_map().size())); return true; } - case FilterOp::kGlob: case FilterOp::kNe: case FilterOp::kIsNull: case FilterOp::kIsNotNull: - case FilterOp::kLike: break; } return false; @@ -541,9 +554,36 @@ class Column { } } + static SqlValue::Type ToSqlValueType(ColumnType type) { + switch (type) { + case ColumnType::kInt32: + case ColumnType::kUint32: + case ColumnType::kInt64: + case ColumnType::kId: + return SqlValue::Type::kLong; + case ColumnType::kDouble: + return SqlValue::Type::kDouble; + case ColumnType::kString: + return SqlValue::Type::kString; + } + PERFETTO_FATAL("For GCC"); + } + + // Returns the string at the index |idx|. + // Should only be called when |type_| == ColumnType::kString. + NullTermStringView GetStringPoolStringAtIdx(uint32_t idx) const { + PERFETTO_DCHECK(type_ == ColumnType::kString); + return string_pool_->Get(sparse_vector<StringPool::Id>().GetNonNull(idx)); + } + + // Only filled for columns which own the data inside them. Generally this is + // only true for columns which are dynamically generated at runtime. + // Keep this before |sparse_vector_|. + std::shared_ptr<SparseVectorBase> owned_sparse_vector_; + // type_ is used to cast sparse_vector_ to the correct type. ColumnType type_ = ColumnType::kInt64; - void* sparse_vector_ = nullptr; + SparseVectorBase* sparse_vector_ = nullptr; const char* name_ = nullptr; uint32_t flags_ = Flag::kNoFlag; |