• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "metrics.h"
21 #include "trace_data/trace_data_cache.h"
22 #include "trace_streamer_filters.h"
23 
24 namespace SysTuning {
25 namespace TraceStreamer {
26 class BytraceParser;
27 class HtraceParser;
28 class RawTraceParser;
29 class TraceStreamerSelector {
30 public:
31     TraceStreamerSelector();
32     ~TraceStreamerSelector();
33     bool ParseTraceDataSegment(std::unique_ptr<uint8_t[]> data, size_t size, bool isSplitFile, int32_t isFinish);
34     void EnableMetaTable(bool enabled);
35     void EnableFileSave(bool enabled);
36     static void SetCleanMode(bool cleanMode);
37     int32_t ExportDatabase(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr);
38     int32_t ExportPerfReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr);
39     int32_t ExportHookReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr);
40     int32_t ExportEbpfReadableText(const std::string& outputName, TraceDataDB::ResultCallBack resultCallBack = nullptr);
41     bool ReloadSymbolFiles(std::string& directory, std::vector<std::string>& symbolsPaths);
42     std::vector<std::string> SearchData();
43     int32_t OperateDatabase(const std::string& sql);
44     int32_t SearchDatabase(const std::string& sql, TraceDataDB::ResultCallBack resultCallBack);
45     int32_t SearchDatabase(const std::string& sql, uint8_t* out, int32_t outLen);
46     int32_t SearchDatabase(std::string& sql, bool printf);
47     int32_t SearchDatabaseToProto(const std::string& data, SqllitePreparCacheData::TLVResultCallBack resultCallBack);
48     std::string SearchDatabase(const std::string& sql);
49     int32_t UpdateTraceRangeTime(uint8_t* data, int32_t len);
50     void WaitForParserEnd();
51     void Clear();
52     MetaData* GetMetaData();
53     void SetDataType(TraceFileType type);
54     void SetCancel(bool cancel);
55     bool ParserAndPrintMetrics(const std::string& metrics);
56     bool ReadSqlFileAndPrintResult(const std::string& sqlOperator);
DataType()57     TraceFileType DataType() const
58     {
59         return fileType_;
60     }
61     void UpdateAnimationTraceStatus(bool status);
62     void UpdateTaskPoolTraceStatus(bool status);
63     void UpdateAppStartTraceStatus(bool status);
64     void UpdateBinderRunnableTraceStatus(bool status);
65     void InitMetricsMap(std::map<std::string, std::string>& metricsMap);
66     const std::string MetricsSqlQuery(const std::string& metrics);
GetBytraceData()67     auto GetBytraceData()
68     {
69         return bytraceParser_.get();
70     }
GetHtraceData()71     auto GetHtraceData()
72     {
73         return htraceParser_.get();
74     }
GetFileType()75     const auto GetFileType()
76     {
77         return fileType_;
78     }
GetTraceDataCache()79     auto GetTraceDataCache()
80     {
81         return traceDataCache_.get();
82     }
GetStreamFilter()83     auto GetStreamFilter()
84     {
85         return streamFilters_.get();
86     }
87     int32_t CreatEmptyBatchDB(const std::string dbPath);
88     int32_t BatchExportDatabase(const std::string& outputName);
89     bool BatchParseTraceDataSegment(std::unique_ptr<uint8_t[]> data, size_t size);
90     void RevertTableName(const std::string& outputName);
91     uint64_t minTs_ = INVALID_UINT64;
92     uint64_t maxTs_ = INVALID_UINT64;
93 
94 private:
95     void InitFilter();
96     bool LoadQueryFile(const std::string& sqlOperator, std::vector<std::string>& sqlStrings);
97     TraceFileType fileType_;
98     std::unique_ptr<TraceStreamerFilters> streamFilters_ = {};
99     std::unique_ptr<TraceDataCache> traceDataCache_ = {};
100     std::unique_ptr<BytraceParser> bytraceParser_;
101     std::unique_ptr<HtraceParser> htraceParser_;
102     std::unique_ptr<RawTraceParser> rawTraceParser_;
103     bool enableFileSeparate_ = false;
104 };
105 } // namespace TraceStreamer
106 } // namespace SysTuning
107 
108 #endif // TRACE_STREAMER_SELECTOR_H
109