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 #include "faultlogger_client_msg.h" 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 /** 26 * @brief Add fault log 27 * 28 * The C style of API is used to save fault information to file 29 * under the /data/log/fautlog/faultlogger directory and event database 30 * 31 * @param info structure containing information about fault 32 */ 33 void AddFaultLog(FaultLogInfoInner* info); 34 /** 35 * @brief report cpp crash event to Hiview 36 * 37 * report cpp crash event to Hiview and save it to event database 38 * 39 * @param info structure containing information about fault 40 */ 41 void ReportCppCrashEvent(FaultLogInfoInner* info); 42 #ifdef __cplusplus 43 } 44 #endif 45 46 namespace OHOS { 47 namespace HiviewDFX { 48 /** 49 * @brief Distinguish different types of fault 50 */ 51 enum FaultLogType { 52 /** unspecific fault types */ 53 NO_SPECIFIC = 0, 54 /** C/C++ crash at runtime*/ 55 CPP_CRASH = 2, 56 /** js crash at runtime*/ 57 JS_CRASH, 58 /** application happen freezing */ 59 APP_FREEZE, 60 /** system happen freezing */ 61 SYS_FREEZE, 62 /** system happen warning */ 63 SYS_WARNING, 64 /** rust crash at runtime */ 65 RUST_PANIC, 66 }; 67 68 /** 69 * @brief Check faultlogger service status 70 * 71 * This API is used to check the faultlogger service status 72 * 73 * @return When faultlogger service is available,it returns true. When not,it rerurns false. 74 */ 75 bool CheckFaultloggerStatus(); 76 77 /** 78 * @brief Add fault log 79 * 80 * This API is used to save fault information to file 81 * under the /data/log/fautlog/faultlogger directory and event database 82 * 83 * @param info structure containing information about fault 84 */ 85 86 void AddFaultLog(const FaultLogInfoInner &info); 87 88 /** 89 * @brief Add fault log 90 * 91 * This API is used to save fault information to file 92 * under the /data/log/fautlog/faultlogger directory and event database 93 * 94 * @param time the time of happening fault(unix timestamp of Milliseconds) 95 * @param logType the type of fault log. 96 * eg: CPP_CRASH,JS_CRASH,APP_FREEZE,SYS_FREEZE,SYS_WARNING,RUST_PANIC 97 * @param module name of module which happened fault 98 * @param summary the summary of fault information 99 */ 100 void AddFaultLog(int64_t time, int32_t logType, const std::string &module, const std::string &summary); 101 102 /** 103 * @brief query self fault log from event database 104 * 105 * This API is used to query fault log 106 * which belong to current pid and uid from event database 107 * 108 * @param faultType type of fault log. 109 * eg: NO_SPECIFIC,CPP_CRASH,JS_CRASH,APP_FREEZE 110 * @param maxNum max number of faultlog entries 111 * @return when success query return unique_ptr of FaultLogQueryResult, otherwise return nullptr 112 */ 113 std::unique_ptr<FaultLogQueryResult> QuerySelfFaultLog(FaultLogType faultType, int32_t maxNum); 114 } // namespace HiviewDFX 115 } // namespace OHOS 116 #endif // HIVIEW_FAULTLOGGER_CLIENT_INTERFACE_H 117