/* * 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_DB_TYPED_COLUMN_H_ #define SRC_TRACE_PROCESSOR_DB_TYPED_COLUMN_H_ #include <cstdint> #include <optional> #include <type_traits> #include <vector> #include "perfetto/base/logging.h" #include "perfetto/trace_processor/basic_types.h" #include "src/trace_processor/containers/null_term_string_view.h" #include "src/trace_processor/db/column.h" #include "src/trace_processor/db/column/types.h" #include "src/trace_processor/db/column_storage.h" #include "src/trace_processor/db/typed_column_internal.h" namespace perfetto::trace_processor { // TypedColumn<T> // // Introduction: // TypedColumn exists to allow efficient access to the data in a Column without // having to go through dynamic type checking. There are two main reasons for // this: // 1. Performance: dynamic type checking is not free and so if this is used // in a particularily hot codepath, the typechecking can be a significant // overhead. // 2. Ergonomics: having to convert back and forth from/to SqlValue causes // signifcant clutter in parts of the code which can already be quite hard // to follow (e.g. trackers like SequenceStackProfileTracker which perform // cross checking of various ids). // // Implementation: // TypedColumn is implemented as a memberless subclass of Column. This allows // us to static cast from a Column* to a TypedColumn<T> where we know the // type T. The methods of TypedColumn are type-specialized methods of Column // which allow callers to pass real types instead of using SqlValue. // // There are two helper classes (tc_internal::TypeHandler and // tc_internal::Serializer) where we specialize behaviour which needs to be // different based on T. See their class documentation and below for details // on their purpose. template <typename T> class TypedColumn : public ColumnLegacy { … }; // Represents a column containing ids. template <typename Id> class IdColumn : public ColumnLegacy { … }; } // namespace perfetto::trace_processor #endif // SRC_TRACE_PROCESSOR_DB_TYPED_COLUMN_H_