1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TRACE_DATA_DB_H 17 #define TRACE_DATA_DB_H 18 19 #include <list> 20 #include <string> 21 22 extern "C" { 23 struct sqlite3; 24 struct sqlite3_stmt; 25 extern int sqlite3_close(sqlite3*); 26 extern int sqlite3_finalize(sqlite3_stmt* pStmt); 27 } 28 29 namespace SysTuning { 30 namespace TraceStreamer { 31 class TraceDataDB { 32 public: 33 TraceDataDB(); 34 TraceDataDB(const TraceDataDB&) = delete; 35 TraceDataDB& operator=(const TraceDataDB&) = delete; 36 virtual ~TraceDataDB(); 37 virtual void InitDB() = 0; 38 39 public: 40 int ExportDatabase(const std::string& outputName); 41 int SearchData(const std::string& outputName); 42 void AppendNewTable(std::string tableName); 43 void EnableMetaTable(bool enabled); 44 45 public: 46 sqlite3* db_; 47 48 private: 49 void ExecuteSql(const std::string_view& sql); 50 std::list<std::string> internalTables_ = {}; 51 bool exportMetaTable_ = false; 52 }; 53 } // namespace TraceStreamer 54 } // namespace SysTuning 55 #endif 56