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