1 /* 2 * Copyright (c) 2022 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 DB_DFX_ADAPTER_H 17 #define DB_DFX_ADAPTER_H 18 19 #include <string> 20 #include <vector> 21 22 namespace DistributedDB { 23 enum DBEventType { 24 FAULT = 1, 25 STATISTIC = 2, 26 SECURITY = 3, 27 BEHAVIOR = 4 28 }; 29 30 enum class Scene { 31 OPEN_CONN = 1, 32 SEND_RECV_DATA, 33 CLOUD_SYNC, 34 DATA_ACCESS, 35 SEARCH_DATA, 36 DEVICE_SYNC 37 }; 38 39 enum class State { 40 BEGIN = 0, 41 END 42 }; 43 44 enum class Stage { 45 GET_DB = 0, 46 CHECK_OPT, 47 GET_DB_CONN, 48 CLOUD_SYNC, 49 CLOUD_DOWNLOAD, 50 CLOUD_UPLOAD, 51 CLOUD_NOTIFY, 52 DEVICE_SYNC, 53 }; 54 55 enum class StageResult { 56 IDLE = 0, 57 SUCC, 58 FAIL, 59 CANCLE, 60 UNKNOWN 61 }; 62 63 struct ReportTask { 64 std::string funcName; 65 Scene scene; 66 State state; 67 Stage stage; 68 StageResult result; 69 int errCode = 0; 70 }; 71 72 class DBDfxAdapter final { 73 public: 74 static void Dump(int fd, const std::vector<std::u16string> &args); 75 76 static void ReportBehavior(const ReportTask &reportTask); 77 78 static void StartTrace(const std::string &action); 79 static void FinishTrace(); 80 81 static void StartTracing(); 82 static void FinishTracing(); 83 84 static void StartAsyncTrace(const std::string &action, int32_t taskId); 85 static void FinishAsyncTrace(const std::string &action, int32_t taskId); 86 87 static const std::string SYNC_ACTION; 88 static const std::string EVENT_OPEN_DATABASE_FAILED; 89 private: 90 static const std::string ORG_PKG; 91 static const std::string FUNC; 92 static const std::string BIZ_SCENE; 93 static const std::string BIZ_STATE; 94 static const std::string BIZ_STAGE; 95 static const std::string STAGE_RES; 96 static const std::string ERROR_CODE; 97 static const std::string DISTRIBUTED_DB_BEHAVIOR; 98 static const std::string ORG_PKG_NAME; 99 static const std::string SQLITE_EXECUTE; 100 101 static constexpr int E_DB_DFX_BASE = 27328512; 102 }; 103 } // namespace DistributedDB 104 105 #endif // DB_DFX_ADAPTER_H 106