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_STREAMER_SELECTOR_H 17 #define TRACE_STREAMER_SELECTOR_H 18 #include <functional> 19 #include <memory> 20 #include "trace_data/trace_data_cache.h" 21 #include "trace_streamer_filters.h" 22 23 namespace SysTuning { 24 namespace TraceStreamer { 25 class BytraceParser; 26 class HtraceParser; 27 enum TraceFileType { TRACE_FILETYPE_BY_TRACE, TRACE_FILETYPE_H_TRACE, TRACE_FILETYPE_SYSEVENT, TRACE_FILETYPE_UN_KNOW }; 28 class TraceStreamerSelector { 29 public: 30 TraceStreamerSelector(); 31 ~TraceStreamerSelector(); 32 bool ParseTraceDataSegment(std::unique_ptr<uint8_t[]> data, size_t size); 33 void EnableMetaTable(bool enabled); 34 static void SetCleanMode(bool cleanMode); 35 int ExportDatabase(const std::string& outputName) const; 36 int SearchData(); 37 int OperateDatabase(const std::string& sql); 38 int SearchDatabase(const std::string& sql, TraceDataDB::ResultCallBack resultCallBack); 39 int SearchDatabase(const std::string& sql, uint8_t* out, int outLen); 40 int UpdateTraceRangeTime(uint8_t* data, int len); 41 void WaitForParserEnd(); 42 void Clear(); 43 MetaData* GetMetaData(); 44 void SetDataType(TraceFileType type); 45 void SetCancel(bool cancel); DataType()46 TraceFileType DataType() const 47 { 48 return fileType_; 49 } 50 51 private: 52 void InitFilter(); 53 TraceFileType fileType_; 54 std::unique_ptr<TraceStreamerFilters> streamFilters_ = {}; 55 std::unique_ptr<TraceDataCache> traceDataCache_ = {}; 56 57 std::unique_ptr<BytraceParser> bytraceParser_; 58 std::unique_ptr<HtraceParser> htraceParser_; 59 }; 60 } // namespace TraceStreamer 61 } // namespace SysTuning 62 63 #endif // TRACE_STREAMER_SELECTOR_H 64