1 /* 2 * Copyright (C) 2019 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 #ifndef SRC_TRACE_PROCESSOR_SQLITE_SQLITE_RAW_TABLE_H_ 18 #define SRC_TRACE_PROCESSOR_SQLITE_SQLITE_RAW_TABLE_H_ 19 20 #include "perfetto/base/logging.h" 21 #include "perfetto/ext/base/flat_hash_map.h" 22 #include "perfetto/ext/base/string_writer.h" 23 #include "src/trace_processor/sqlite/db_sqlite_table.h" 24 #include "src/trace_processor/storage/trace_storage.h" 25 #include "src/trace_processor/types/trace_processor_context.h" 26 #include "src/trace_processor/types/variadic.h" 27 28 namespace perfetto { 29 namespace trace_processor { 30 31 class SystraceSerializer { 32 public: 33 using ScopedCString = std::unique_ptr<char, void (*)(void*)>; 34 35 explicit SystraceSerializer(TraceProcessorContext* context); 36 37 ScopedCString SerializeToString(uint32_t raw_row); 38 39 private: 40 using StringIdMap = 41 base::FlatHashMap<StringId, std::vector<base::Optional<uint32_t>>>; 42 43 void SerializePrefix(uint32_t raw_row, base::StringWriter* writer); 44 45 StringIdMap proto_id_to_arg_index_by_event_; 46 const TraceStorage* storage_ = nullptr; 47 TraceProcessorContext* context_ = nullptr; 48 }; 49 50 class SqliteRawTable : public DbSqliteTable { 51 public: 52 struct Context { 53 QueryCache* cache; 54 TraceProcessorContext* context; 55 }; 56 57 SqliteRawTable(sqlite3*, Context); 58 ~SqliteRawTable() override; 59 60 static void RegisterTable(sqlite3* db, QueryCache*, TraceProcessorContext*); 61 62 private: 63 void ToSystrace(sqlite3_context* ctx, int argc, sqlite3_value** argv); 64 65 SystraceSerializer serializer_; 66 }; 67 68 } // namespace trace_processor 69 } // namespace perfetto 70 71 #endif // SRC_TRACE_PROCESSOR_SQLITE_SQLITE_RAW_TABLE_H_ 72