1 /* 2 * Copyright (c) 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 16 #ifndef FREEZE_JSON_GENERATOR_H 17 #define FREEZE_JSON_GENERATOR_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace HiviewDFX { 23 24 class FreezeJsonException { 25 public: 26 class Builder { 27 public: Builder()28 Builder() {}; ~Builder()29 ~Builder() {}; 30 Builder& InitName(const std::string& name); 31 Builder& InitMessage(const std::string& message); 32 FreezeJsonException Build() const; 33 34 private: 35 std::string name_ = ""; 36 std::string message_ = ""; 37 friend class FreezeJsonException; 38 }; 39 40 explicit FreezeJsonException(const FreezeJsonException::Builder& builder); ~FreezeJsonException()41 ~FreezeJsonException() {}; 42 std::string JsonStr() const; 43 44 private: 45 static const inline std::string jsonExceptionName = "name"; 46 static const inline std::string jsonExceptionMessage = "message"; 47 48 std::string name_; 49 std::string message_; 50 }; 51 52 class FreezeJsonMemory { 53 public: 54 class Builder { 55 public: Builder()56 Builder() {}; ~Builder()57 ~Builder() {}; 58 Builder& InitRss(unsigned long long rss); 59 Builder& InitVss(unsigned long long vss); 60 Builder& InitPss(unsigned long long pss); 61 Builder& InitSysFreeMem(unsigned long long sysFreeMem); 62 Builder& InitSysAvailMem(unsigned long long sysAvailMem); 63 Builder& InitSysTotalMem(unsigned long long sysTotalMem); 64 FreezeJsonMemory Build() const; 65 66 private: 67 unsigned long long rss_ = 0; 68 unsigned long long vss_ = 0; 69 unsigned long long pss_ = 0; 70 unsigned long long sysFreeMem_ = 0; 71 unsigned long long sysAvailMem_ = 0; 72 unsigned long long sysTotalMem_ = 0; 73 friend class FreezeJsonMemory; 74 }; 75 76 explicit FreezeJsonMemory(const FreezeJsonMemory::Builder& builder); ~FreezeJsonMemory()77 ~FreezeJsonMemory() {}; 78 std::string JsonStr() const; 79 80 private: 81 static const inline std::string jsonMemoryRss = "rss"; 82 static const inline std::string jsonMemoryVss = "vss"; 83 static const inline std::string jsonMemoryPss = "pss"; 84 static const inline std::string jsonMemorySysFreeMem = "sys_free_mem"; 85 static const inline std::string jsonMemorySysAvailMem = "sys_avail_mem"; 86 static const inline std::string jsonMemorySysTotalMem = "sys_total_mem"; 87 unsigned long long rss_; 88 unsigned long long vss_; 89 unsigned long long pss_; 90 unsigned long long sysFreeMem_; 91 unsigned long long sysAvailMem_; 92 unsigned long long sysTotalMem_; 93 }; 94 95 class FreezeJsonParams { 96 public: 97 class Builder { 98 public: Builder()99 Builder() {}; ~Builder()100 ~Builder() {}; 101 Builder& InitTime(unsigned long long time); 102 Builder& InitUuid(const std::string& uuid); 103 Builder& InitFreezeType(const std::string& freezeType); 104 Builder& InitForeground(bool foreground); 105 Builder& InitBundleVersion(const std::string& bundleVersion); 106 Builder& InitBundleName(const std::string& bundleName); 107 Builder& InitProcessName(const std::string& processName); 108 Builder& InitExternalLog(const std::string& externalLog); 109 Builder& InitPid(long pid); 110 Builder& InitUid(long uid); 111 Builder& InitAppRunningUniqueId(const std::string& appRunningUniqueId); 112 Builder& InitException(const std::string& exception); 113 Builder& InitHilog(const std::string& hilog); 114 Builder& InitEventHandler(const std::string& eventHandler); 115 Builder& InitEventHandlerSize3s(const std::string& eventHandlerSize3s); 116 Builder& InitEventHandlerSize6s(const std::string& eventHandlerSize6s); 117 Builder& InitPeerBinder(const std::string& peerBinder); 118 Builder& InitThreads(const std::string& threads); 119 Builder& InitMemory(const std::string& memory); 120 FreezeJsonParams Build() const; 121 122 private: 123 unsigned long long time_ = 0; 124 std::string uuid_ = ""; 125 std::string freezeType_ = ""; 126 bool foreground_ = false; 127 std::string bundleVersion_ = ""; 128 std::string bundleName_ = ""; 129 std::string processName_ = ""; 130 std::string externalLog_ = "[]"; 131 long pid_ = 0; 132 long uid_ = 0; 133 std::string appRunningUniqueId_ = ""; 134 std::string exception_ = "{}"; 135 std::string hilog_ = "[]"; 136 std::string eventHandler_ = "[]"; 137 std::string eventHandlerSize3s_ = ""; 138 std::string eventHandlerSize6s_ = ""; 139 std::string peerBinder_ = "[]"; 140 std::string threads_ = "[]"; 141 std::string memory_ = "{}"; 142 friend class FreezeJsonParams; 143 }; 144 145 explicit FreezeJsonParams(const FreezeJsonParams::Builder& builder); ~FreezeJsonParams()146 ~FreezeJsonParams() {}; 147 std::string JsonStr() const; 148 149 private: 150 static const inline std::string jsonParamsTime = "time"; 151 static const inline std::string jsonParamsUuid = "uuid"; 152 static const inline std::string jsonParamsFreezeType = "freeze_type"; 153 static const inline std::string jsonParamsForeground = "foreground"; 154 static const inline std::string jsonParamsBundleVersion = "bundle_version"; 155 static const inline std::string jsonParamsBundleName = "bundle_name"; 156 static const inline std::string jsonParamsProcessName = "process_name"; 157 static const inline std::string jsonParamsExternalLog = "external_log"; 158 static const inline std::string jsonParamsPid = "pid"; 159 static const inline std::string jsonParamsUid = "uid"; 160 static const inline std::string jsonParamsAppRunningUniqueId = "app_running_unique_id"; 161 static const inline std::string jsonParamsException = "exception"; 162 static const inline std::string jsonParamsHilog = "hilog"; 163 static const inline std::string jsonParamsEventHandler = "event_handler"; 164 static const inline std::string jsonParamsEventHandlerSize3s = "event_handler_size_3s"; 165 static const inline std::string jsonParamsEventHandlerSize6s = "event_handler_size_6s"; 166 static const inline std::string jsonParamsPeerBinder = "peer_binder"; 167 static const inline std::string jsonParamsThreads = "threads"; 168 static const inline std::string jsonParamsMemory = "memory"; 169 170 unsigned long long time_; 171 std::string uuid_; 172 std::string freezeType_; 173 bool foreground_; 174 std::string bundleVersion_; 175 std::string bundleName_; 176 std::string processName_; 177 std::string externalLog_ = ""; 178 long pid_ = 0; 179 long uid_ = 0; 180 std::string appRunningUniqueId_ = ""; 181 std::string exception_; 182 std::string hilog_; 183 std::string eventHandler_; 184 std::string eventHandlerSize3s_; 185 std::string eventHandlerSize6s_; 186 std::string peerBinder_; 187 std::string threads_; 188 std::string memory_; 189 }; 190 191 } // namespace HiviewDFX 192 } // namespace OHOS 193 #endif