1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "src/trace_processor/storage_schema.h" 18 19 #include "src/trace_processor/row_iterators.h" 20 21 namespace perfetto { 22 namespace trace_processor { 23 24 StorageSchema::StorageSchema() = default; 25 StorageSchema::StorageSchema(Columns columns, 26 std::vector<std::string> primary_keys) 27 : columns_(std::move(columns)), primary_keys_(std::move(primary_keys)) {} 28 29 Table::Schema StorageSchema::ToTableSchema() { 30 std::vector<Table::Column> columns; 31 size_t i = 0; 32 for (const auto& col : columns_) 33 columns.emplace_back(i++, col->name(), col->GetType(), col->hidden()); 34 35 std::vector<size_t> primary_keys; 36 for (const auto& p_key : primary_keys_) 37 primary_keys.emplace_back(ColumnIndexFromName(p_key)); 38 return Table::Schema(std::move(columns), std::move(primary_keys)); 39 } 40 41 size_t StorageSchema::ColumnIndexFromName(const std::string& name) const { 42 auto p = [name](const std::unique_ptr<StorageColumn>& col) { 43 return name == col->name(); 44 }; 45 auto it = std::find_if(columns_.begin(), columns_.end(), p); 46 return static_cast<size_t>(std::distance(columns_.begin(), it)); 47 } 48 49 } // namespace trace_processor 50 } // namespace perfetto 51