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 #include "smart_parser.h"
16 
17 #include "feature_analysis.h"
18 #include "file_util.h"
19 #include "hiview_logger.h"
20 #include "rule.h"
21 
22 using namespace std;
23 
24 namespace OHOS {
25 namespace HiviewDFX {
26 DEFINE_LOG_TAG("SmartParser");
27 
Analysis(const std::string & eventPath,const std::string & analysisConfig,const std::string & eventType)28 std::map<std::string, std::string> SmartParser::Analysis(const std::string& eventPath,
29     const std::string& analysisConfig, const std::string& eventType)
30 {
31     std::string config;
32     if (!FileUtil::PathToRealPath(analysisConfig, config) || config.empty()) {
33         HIVIEW_LOGE("config %{public}s isn't real path.", analysisConfig.c_str());
34         return {};
35     }
36 
37     Rule rule(eventPath, config, eventType);
38     rule.ParseRule();
39     auto featureSets = rule.GetExtractRule();
40     auto composeRules = rule.GetComposeRule();
41     auto segStatusCfg = rule.GetSegStatusCfg();
42 
43     std::map<std::string, std::string> eventInfoMap;
44     for (const auto& composeRule : composeRules) {
45         FeatureAnalysis feature(featureSets[composeRule.first], composeRule.second, eventType);
46         if (feature.AnalysisLog()) {
47             auto result = feature.GetReasult();
48             for (const auto& one : result) {
49                 eventInfoMap.emplace(one.first, one.second);
50             }
51         }
52     }
53     return eventInfoMap;
54 }
55 } // namespace HiviewDFX
56 } // namespace OHOS
57