• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "log_analyzer.h"
16 
17 #include <securec.h>
18 
19 #include "common_utils.h"
20 #include "faultlog_util.h"
21 #include "file_util.h"
22 #include "smart_parser.h"
23 #include "string_util.h"
24 #include "tbox.h"
25 
26 namespace OHOS {
27 namespace HiviewDFX {
AnalysisFaultlog(const FaultLogInfo & info,std::map<std::string,std::string> & eventInfos)28 bool AnalysisFaultlog(const FaultLogInfo& info, std::map<std::string, std::string>& eventInfos)
29 {
30     std::string fingerPrint;
31     bool needDelete = false;
32     std::string logPath = info.logPath;
33     auto eventType = GetFaultNameByType(info.faultLogType, false);
34     if (eventType == "JS_ERROR" && !FileUtil::FileExists(info.logPath) && !info.summary.empty()) {
35         logPath = info.logPath + "tmp";
36         FileUtil::SaveStringToFile(logPath, info.summary);
37         needDelete = true;
38     }
39     eventInfos = SmartParser::Analysis(logPath, SMART_PARSER_PATH, eventType);
40     if (needDelete) {
41         FileUtil::RemoveFile(logPath);
42     }
43     if (eventInfos.empty()) {
44         eventInfos.insert(std::make_pair("fingerPrint", Tbox::CalcFingerPrint(info.module + info.reason +
45                                                                             info.summary, 0, FP_BUFFER)));
46         return false;
47     }
48     Tbox::FilterTrace(eventInfos, eventType);
49     fingerPrint = Tbox::CalcFingerPrint(info.module + StringUtil::GetLeftSubstr(info.reason, "@") +
50         eventInfos["FIRST_FRAME"] + eventInfos["SECOND_FRAME"] + eventInfos["LAST_FRAME"] +
51         ((eventType == "JS_ERROR") ? eventInfos["SUBREASON"] : ""), 0, FP_BUFFER);
52     eventInfos["fingerPrint"] = fingerPrint;
53 
54     if (eventType == "APP_FREEZE" && !(eventInfos["TRACER_PID"].empty())) {
55         int32_t pid = 0;
56         if (sscanf_s(eventInfos["TRACER_PID"].c_str(), "%d", &pid) == 1 && pid > 0) {
57             eventInfos["LAST_FRAME"] += ("(Tracer Process Name:" + CommonUtils::GetProcNameByPid(pid) + ")");
58         }
59     }
60 
61     return true;
62 }
63 } // namespace HiviewDFX
64 } // namespace OHOS
65