• 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 #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     const auto &composeRules = rule.GetComposeRule();
41 
42     std::map<std::string, std::string> eventInfoMap;
43     for (const auto& composeRule : composeRules) {
44         FeatureAnalysis feature(featureSets[composeRule.first], composeRule.second, eventType);
45         if (feature.AnalysisLog()) {
46             auto result = feature.GetReasult();
47             for (const auto& one : result) {
48                 eventInfoMap.emplace(one.first, one.second);
49             }
50         }
51     }
52     return eventInfoMap;
53 }
54 } // namespace HiviewDFX
55 } // namespace OHOS
56