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 /** cj error at runtime */ 67 CJ_ERROR = 9, 68 }; 69 70 /** 71 * @brief Check faultlogger service status 72 * 73 * This API is used to check the faultlogger service status 74 * 75 * @return When faultlogger service is available,it returns true. When not,it rerurns false. 76 */ 77 bool CheckFaultloggerStatus(); 78 79 /** 80 * @brief Add fault log 81 * 82 * This API is used to save fault information to file 83 * under the /data/log/fautlog/faultlogger directory and event database 84 * 85 * @param info structure containing information about fault 86 */ 87 88 void AddFaultLog(const FaultLogInfoInner &info); 89 90 /** 91 * @brief Add fault log 92 * 93 * This API is used to save fault information to file 94 * under the /data/log/fautlog/faultlogger directory and event database 95 * 96 * @param time the time of happening fault(unix timestamp of Milliseconds) 97 * @param logType the type of fault log. 98 * eg: CPP_CRASH,JS_CRASH,APP_FREEZE,SYS_FREEZE,SYS_WARNING,RUST_PANIC 99 * @param module name of module which happened fault 100 * @param summary the summary of fault information 101 */ 102 void AddFaultLog(int64_t time, int32_t logType, const std::string &module, const std::string &summary); 103 104 /** 105 * @brief query self fault log from event database 106 * 107 * This API is used to query fault log 108 * which belong to current pid and uid from event database 109 * 110 * @param faultType type of fault log. 111 * eg: NO_SPECIFIC,CPP_CRASH,JS_CRASH,APP_FREEZE 112 * @param maxNum max number of faultlog entries 113 * @return when success query return unique_ptr of FaultLogQueryResult, otherwise return nullptr 114 */ 115 std::unique_ptr<FaultLogQueryResult> QuerySelfFaultLog(FaultLogType faultType, int32_t maxNum); 116 117 /** 118 * @brief enable the GWP-ASAN grayscale of your application. 119 * 120 * @param alwaysEnabled - Control whether to enable GWP-ASan every time. 121 * @param sampleRate - sample rate of GWP-ASAN. 122 * @param maxSimutaneousAllocations - the max simutaneous allocations of GWP-ASAN. 123 * @param duration - The duration days of GWP-ASAN grayscale. 124 * @return true - enable success, false - enable falied 125 */ 126 bool EnableGwpAsanGrayscale(bool alwaysEnabled, double sampleRate, 127 double maxSimutaneousAllocations, int32_t duration); 128 129 /** 130 * @brief disable the GWP-ASAN grayscale of your application. 131 * 132 */ 133 void DisableGwpAsanGrayscale(); 134 135 /** 136 * @brief obtain the remaining days of GWP-ASan grayscale for your application. 137 * 138 * @returns the remaining days of GWP-ASan grayscale. 139 */ 140 uint32_t GetGwpAsanGrayscaleState(); 141 } // namespace HiviewDFX 142 } // namespace OHOS 143 #endif // HIVIEW_FAULTLOGGER_CLIENT_INTERFACE_H 144