• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef HIVIEW_FAULTLOGGER_CLIENT_INTERFACE_H
16 #define HIVIEW_FAULTLOGGER_CLIENT_INTERFACE_H
17 #include <cstdint>
18 #include <map>
19 #include <string>
20 #include "faultlog_query_result.h"
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 /**
25  * @brief  information of fault log
26  *
27 */
28 struct FaultLogInfoInner {
29     /** the time of happening fault */
30     int64_t time {0};
31     /** the id of current user when fault happened  */
32     int32_t id {-1};
33     /** the id of process which fault happened*/
34     int32_t pid {-1};
35     /** the fd of pipe to transfer json string*/
36     int32_t pipeFd {-1};
37     /** type of fault */
38     int32_t faultLogType {0};
39     /** name of module which fault occurred */
40     std::string module;
41     /** the reason why fault occurred */
42     std::string reason;
43     /** the summary of fault information */
44     std::string summary;
45     /** file path of log */
46     std::string logPath;
47     /** key thread registers */
48     std::string registers;
49     /** information about faultlog using <key,value> */
50     std::map<std::string, std::string> sectionMaps;
51 };
52 /**
53  * @brief Add fault log
54  *
55  * The C style of API is used to save fault information to file
56  * under the /data/log/fautlog/faultlogger directory and event database
57  *
58  * @param info  structure containing information about fault
59 */
60 void AddFaultLog(FaultLogInfoInner* info);
61 /**
62  * @brief report cpp crash event to Hiview
63  *
64  * report cpp crash event to Hiview and save it to event database
65  *
66  * @param info  structure containing information about fault
67 */
68 void ReportCppCrashEvent(FaultLogInfoInner* info);
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 namespace OHOS {
74 namespace HiviewDFX {
75 /**
76  * @brief Distinguish different types of fault
77  */
78 enum FaultLogType {
79     /** unspecific fault types */
80     NO_SPECIFIC = 0,
81     /** C/C++ crash at runtime*/
82     CPP_CRASH = 2,
83     /** js crash at runtime*/
84     JS_CRASH,
85     /** application happen freezing */
86     APP_FREEZE,
87     /** system happen freezing */
88     SYS_FREEZE,
89     /** rust crash at runtime */
90     RUST_PANIC,
91 };
92 
93 /**
94  * @brief Check faultlogger service status
95  *
96  * This API is used to check the faultlogger service status
97  *
98  * @return When faultlogger service is available,it returns true. When not,it rerurns false.
99 */
100 bool CheckFaultloggerStatus();
101 
102 /**
103  * @brief Add fault log
104  *
105  * This API is used to save fault information to file
106  * under the /data/log/fautlog/faultlogger directory and event database
107  *
108  * @param info  structure containing information about fault
109 */
110 
111 void AddFaultLog(const FaultLogInfoInner &info);
112 
113 /**
114  * @brief Add fault log
115  *
116  * This API is used to save fault information to file
117  * under the /data/log/fautlog/faultlogger directory and event database
118  *
119  * @param time  the time of happening fault(unix timestamp of Milliseconds)
120  * @param logType  the type of fault log.
121  * eg: CPP_CRASH,JS_CRASH,APP_FREEZE,SYS_FREEZE,RUST_PANIC
122  * @param module name of module which happened fault
123  * @param summary the summary of fault information
124 */
125 void AddFaultLog(int64_t time, int32_t logType, const std::string &module, const std::string &summary);
126 
127 /**
128  * @brief query self fault log from event database
129  *
130  * This API is used to query fault log
131  * which belong to current pid and uid from event database
132  *
133  * @param faultType type of fault log.
134  * eg: NO_SPECIFIC,CPP_CRASH,JS_CRASH,APP_FREEZE
135  * @param maxNum max number of faultlog entries
136  * @return when success query return unique_ptr of FaultLogQueryResult, otherwise return nullptr
137 */
138 std::unique_ptr<FaultLogQueryResult> QuerySelfFaultLog(FaultLogType faultType, int32_t maxNum);
139 }  // namespace HiviewDFX
140 }  // namespace OHOS
141 #endif  // HIVIEW_FAULTLOGGER_CLIENT_INTERFACE_H
142