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 FREEZE_VENDOR_H
17 #define FREEZE_VENDOR_H
18 
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 #include "faultlog_info.h"
24 #include "freeze_common.h"
25 #include "log_store_ex.h"
26 #include "power_mgr_client.h"
27 #include "smart_parser.h"
28 #include "watch_point.h"
29 
30 namespace OHOS {
31 namespace HiviewDFX {
32 class Vendor {
33 public:
Vendor(std::shared_ptr<FreezeCommon> fc)34     explicit Vendor(std::shared_ptr<FreezeCommon> fc) : freezeCommon_(fc) {};
~Vendor()35     ~Vendor() {};
36     Vendor& operator=(const Vendor&) = delete;
37     Vendor(const Vendor&) = delete;
38 
39     bool Init();
40     std::string GetTimeString(unsigned long long timestamp) const;
41     void DumpEventInfo(std::ostringstream& oss, const std::string& header, const WatchPoint& watchPoint) const;
42     void InitLogInfo(const WatchPoint& watchPoint, std::string& type, std::string& pubLogPathName,
43         std::string& processName, std::string& isScbPro) const;
44     void InitLogBody(const std::vector<WatchPoint>& list, std::ostringstream& body,
45         bool& isFileExists) const;
46     std::string MergeEventLog(
47         const WatchPoint &watchPoint, const std::vector<WatchPoint>& list,
48         const std::vector<FreezeResult>& result) const;
49     bool ReduceRelevanceEvents(std::list<WatchPoint>& list, const FreezeResult& result) const;
50 
51 private:
52     static const int MAX_LINE_NUM = 100;
53     static const int TIME_STRING_LEN = 16;
54     static const int MAX_FILE_NUM = 5;
55     static const int MAX_FOLDER_SIZE = 5 * 1024 * 1024;
56     static const inline std::string TRIGGER_HEADER = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
57     static const inline std::string HEADER = "*******************************************";
58     static const inline std::string HYPHEN = "-";
59     static const inline std::string NEW_LINE = "\n";
60     static const inline std::string EVENT_SUMMARY = "SUMMARY";
61     static const inline std::string POSTFIX = ".tmp";
62     static const inline std::string APPFREEZE = "appfreeze";
63     static const inline std::string SYSFREEZE = "sysfreeze";
64     static const inline std::string SP_SYSTEMHUNGFAULT = "SystemHungFault";
65     static const inline std::string SP_APPFREEZE = "AppFreeze";
66     static const inline std::string SP_ENDSTACK = "END_STACK";
67     static const inline std::string FREEZE_DETECTOR_PATH = "/data/log/faultlog/freeze/";
68     static const inline std::string FAULT_LOGGER_PATH = "/data/log/faultlog/faultlogger/";
69     static const inline std::string SMART_PARSER_PATH = "/system/etc/hiview/";
70 
71     std::string SendFaultLog(const WatchPoint &watchPoint, const std::string& logPath, const std::string& type,
72         const std::string& processName, const std::string& isScbPro) const;
73     void MergeFreezeJsonFile(const WatchPoint &watchPoint, const std::vector<WatchPoint>& list) const;
74     static void InitLogFfrt(const WatchPoint &watchPoint, std::ostringstream& ffrt);
75     static std::string GetDisPlayPowerInfo();
76     static std::string GetPowerStateString(OHOS::PowerMgr::PowerState state);
77     static std::string IsScbProName(std::string& processName);
78 
79     std::unique_ptr<LogStoreEx> logStore_ = nullptr;
80     std::shared_ptr<FreezeCommon> freezeCommon_ = nullptr;
81 };
82 }  // namespace HiviewDFX
83 }  // namespace OHOS
84 #endif // FREEZE_VENDOR_H
85