已合并
fix:BREAK/RECOVER/PROFILE_STAT事件无法落盘。 #2097
honghecun9zu创建于 2024年8月16日
fix:BREAK/RECOVER/PROFILE_STAT事件无法落盘。 #2097
已合并
从refs/pull/2097/head合入到master
共 13 个文件变更+233-246
| @@ -133,7 +133,7 @@ std::string GetConfigFilePath(const std::string& configZipFileName, const std::s | |||
| 133 | HIVIEW_LOGI("succeed to do cloud update for %{public}s", configFileName.c_str()); | 133 | HIVIEW_LOGI("succeed to do cloud update for %{public}s", configFileName.c_str()); |
| 134 | return destConfigFilePath; | 134 | return destConfigFilePath; |
| 135 | } | 135 | } |
| 136 | - // do local update if local version is newer than clouad version or cloud update is failed | 136 | + // do local update if local version is newer than cloud version or cloud update is failed |
| 137 | if (UnZipConfigFile(LOCAL_CFG_PATH, configZipFileName, destConfigDir, configFileName) && | 137 | if (UnZipConfigFile(LOCAL_CFG_PATH, configZipFileName, destConfigDir, configFileName) && |
| 138 | CopyConfigVersionFile(destConfigDir, true)) { | 138 | CopyConfigVersionFile(destConfigDir, true)) { |
| 139 | HIVIEW_LOGI("succeed to do local update for %{public}s", configFileName.c_str()); | 139 | HIVIEW_LOGI("succeed to do local update for %{public}s", configFileName.c_str()); |
| @@ -74,6 +74,7 @@ ohos_source_set("sysevent_source") { | |||
| 74 | "cJSON:cjson", | 74 | "cJSON:cjson", |
| 75 | "ffrt:libffrt", | 75 | "ffrt:libffrt", |
| 76 | "hilog:libhilog", | 76 | "hilog:libhilog", |
| 77 | + "hisysevent:libhisysevent", | ||
| 77 | "init:libbegetutil", | 78 | "init:libbegetutil", |
| 78 | "jsoncpp:jsoncpp", | 79 | "jsoncpp:jsoncpp", |
| 79 | "relational_store:native_rdb", | 80 | "relational_store:native_rdb", |
| @@ -21,63 +21,22 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | - | ||
| 25 | 24 | ||
| 26 | namespace OHOS { | 25 | namespace OHOS { |
| 27 | namespace HiviewDFX { | 26 | namespace HiviewDFX { |
| 28 | namespace { | 27 | namespace { |
| 29 | DEFINE_LOG_TAG("Event-JsonParser"); | 28 | DEFINE_LOG_TAG("Event-JsonParser"); |
| 30 | -constexpr uint64_t PRIME = 0x100000001B3ULL; | 29 | + |
| 31 | -constexpr uint64_t BASIS = 0xCBF29CE484222325ULL; | ||
| 32 | constexpr char BASE[] = "__BASE"; | 30 | constexpr char BASE[] = "__BASE"; |
| 33 | constexpr char LEVEL[] = "level"; | 31 | constexpr char LEVEL[] = "level"; |
| 34 | constexpr char TAG[] = "tag"; | 32 | constexpr char TAG[] = "tag"; |
| 35 | constexpr char TYPE[] = "type"; | 33 | constexpr char TYPE[] = "type"; |
| 36 | constexpr char PRIVACY[] = "privacy"; | 34 | constexpr char PRIVACY[] = "privacy"; |
| 37 | constexpr char PRESERVE[] = "preserve"; | 35 | constexpr char PRESERVE[] = "preserve"; |
| 38 | -constexpr char TEST_TYPE_PARAM_KEY[] = "hiviewdfx.hiview.testtype"; | ||
| 39 | -constexpr char TEST_TYPE_KEY[] = "test_type_"; | ||
| 40 | const std::map<std::string, uint8_t> EVENT_TYPE_MAP = { | 36 | const std::map<std::string, uint8_t> EVENT_TYPE_MAP = { |
| 41 | {"FAULT", 1}, {"STATISTIC", 2}, {"SECURITY", 3}, {"BEHAVIOR", 4} | 37 | {"FAULT", 1}, {"STATISTIC", 2}, {"SECURITY", 3}, {"BEHAVIOR", 4} |
| 42 | }; | 38 | }; |
| 43 | 39 | ||
| 44 | -uint64_t GenerateHash(std::shared_ptr<SysEvent> event) | ||
| 45 | -{ | ||
| 46 | - constexpr size_t infoLenLimit = 256; | ||
| 47 | - size_t infoLen = event->rawData_->GetDataLength(); | ||
| 48 | - size_t hashLen = (infoLen < infoLenLimit) ? infoLen : infoLenLimit; | ||
| 49 | - const uint8_t* p = event->rawData_->GetData(); | ||
| 50 | - uint64_t ret {BASIS}; | ||
| 51 | - size_t i = 0; | ||
| 52 | - while (i < hashLen) { | ||
| 53 | - ret ^= *(p + i); | ||
| 54 | - ret *= PRIME; | ||
| 55 | - i++; | ||
| 56 | - } | ||
| 57 | - return ret; | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -void ParameterWatchCallback(const char* key, const char* value, void* context) | ||
| 61 | -{ | ||
| 62 | - if (context == nullptr) { | ||
| 63 | - HIVIEW_LOGE("context is null"); | ||
| 64 | - return; | ||
| 65 | - } | ||
| 66 | - auto parser = reinterpret_cast<EventJsonParser*>(context); | ||
| 67 | - if (parser == nullptr) { | ||
| 68 | - HIVIEW_LOGE("parser is null"); | ||
| 69 | - return; | ||
| 70 | - } | ||
| 71 | - size_t testTypeStrMaxLen = 256; | ||
| 72 | - std::string testTypeStr(value); | ||
| 73 | - if (testTypeStr.size() > testTypeStrMaxLen) { | ||
| 74 | - HIVIEW_LOGE("length of the test type string set exceeds the limit"); | ||
| 75 | - return; | ||
| 76 | - } | ||
| 77 | - HIVIEW_LOGI("test_type is set to be \"%{public}s\"", testTypeStr.c_str()); | ||
| 78 | - parser->UpdateTestType(testTypeStr); | ||
| 79 | -} | ||
| 80 | - | ||
| 81 | bool ReadSysEventDefFromFile(const std::string& path, Json::Value& hiSysEventDef) | 40 | bool ReadSysEventDefFromFile(const std::string& path, Json::Value& hiSysEventDef) |
| 82 | { | 41 | { |
| 83 | std::ifstream fin(path, std::ifstream::binary); | 42 | std::ifstream fin(path, std::ifstream::binary); |
| @@ -88,35 +47,12 @@ bool ReadSysEventDefFromFile(const std::string& path, Json::Value& hiSysEventDef | |||
| 88 | } | 47 | } |
| 89 | } | 48 | } |
| 90 | 49 | ||
| 91 | -bool DuplicateIdFilter::IsDuplicateEvent(const uint64_t sysEventId) | ||
| 92 | -{ | ||
| 93 | - for (auto iter = sysEventIds_.begin(); iter != sysEventIds_.end(); iter++) { | ||
| 94 | - if (*iter == sysEventId) { | ||
| 95 | - return true; | ||
| 96 | - } | ||
| 97 | - } | ||
| 98 | - FILTER_SIZE_TYPE maxSize { 5 }; // size of queue limit to 5 | ||
| 99 | - if (sysEventIds_.size() >= maxSize) { | ||
| 100 | - sysEventIds_.pop_front(); | ||
| 101 | - } | ||
| 102 | - sysEventIds_.emplace_back(sysEventId); | ||
| 103 | - return false; | ||
| 104 | -} | ||
| 105 | - | ||
| 106 | EventJsonParser::EventJsonParser(const std::string& defFilePath) | 50 | EventJsonParser::EventJsonParser(const std::string& defFilePath) |
| 107 | { | 51 | { |
| 108 | - WatchTestTypeParameter(); | ||
| 109 | // read json file | 52 | // read json file |
| 110 | ReadDefFile(defFilePath); | 53 | ReadDefFile(defFilePath); |
| 111 | } | 54 | } |
| 112 | 55 | ||
| 113 | -void EventJsonParser::WatchTestTypeParameter() | ||
| 114 | -{ | ||
| 115 | - if (WatchParameter(TEST_TYPE_PARAM_KEY, ParameterWatchCallback, this) != 0) { | ||
| 116 | - HIVIEW_LOGW("failed to watch the change of parameter %{public}s", TEST_TYPE_PARAM_KEY); | ||
| 117 | - } | ||
| 118 | -} | ||
| 119 | - | ||
| 120 | std::string EventJsonParser::GetTagByDomainAndName(const std::string& domain, const std::string& name) const | 56 | std::string EventJsonParser::GetTagByDomainAndName(const std::string& domain, const std::string& name) const |
| 121 | { | 57 | { |
| 122 | return GetDefinedBaseInfoByDomainName(domain, name).tag; | 58 | return GetDefinedBaseInfoByDomainName(domain, name).tag; |
| @@ -132,63 +68,6 @@ bool EventJsonParser::GetPreserveByDomainAndName(const std::string& domain, cons | |||
| 132 | return GetDefinedBaseInfoByDomainName(domain, name).preserve; | 68 | return GetDefinedBaseInfoByDomainName(domain, name).preserve; |
| 133 | } | 69 | } |
| 134 | 70 | ||
| 135 | -bool EventJsonParser::HandleEventJson(const std::shared_ptr<SysEvent>& event) | ||
| 136 | -{ | ||
| 137 | - if (!CheckEvent(event)) { | ||
| 138 | - return false; | ||
| 139 | - } | ||
| 140 | - AppendExtensiveInfo(event); | ||
| 141 | - return true; | ||
| 142 | -} | ||
| 143 | - | ||
| 144 | -void EventJsonParser::UpdateTestType(const std::string& testType) | ||
| 145 | -{ | ||
| 146 | - testType_ = testType; | ||
| 147 | -} | ||
| 148 | - | ||
| 149 | -bool EventJsonParser::CheckEvent(std::shared_ptr<SysEvent> event) | ||
| 150 | -{ | ||
| 151 | - if (event == nullptr) { | ||
| 152 | - HIVIEW_LOGW("event is null."); | ||
| 153 | - return false; | ||
| 154 | - } | ||
| 155 | - if (!CheckBaseInfo(event)) { | ||
| 156 | - return false; | ||
| 157 | - } | ||
| 158 | - if (!CheckDuplicate(event)) { | ||
| 159 | - return false; | ||
| 160 | - } | ||
| 161 | - return true; | ||
| 162 | -} | ||
| 163 | - | ||
| 164 | -bool EventJsonParser::CheckBaseInfo(std::shared_ptr<SysEvent> event) const | ||
| 165 | -{ | ||
| 166 | - if (event->domain_.empty() || event->eventName_.empty()) { | ||
| 167 | - HIVIEW_LOGW("domain=%{public}s or name=%{public}s is empty.", | ||
| 168 | - event->domain_.c_str(), event->eventName_.c_str()); | ||
| 169 | - return false; | ||
| 170 | - } | ||
| 171 | - auto baseInfo = GetDefinedBaseInfoByDomainName(event->domain_, event->eventName_); | ||
| 172 | - if (baseInfo.type == INVALID_EVENT_TYPE) { | ||
| 173 | - HIVIEW_LOGW("type defined for event[%{public}s|%{public}s|%{public}" PRIu64 "] is invalid.", | ||
| 174 | - event->domain_.c_str(), event->eventName_.c_str(), event->happenTime_); | ||
| 175 | - return false; | ||
| 176 | - } | ||
| 177 | - if (event->GetEventType() != baseInfo.type) { | ||
| 178 | - HIVIEW_LOGW("type=%{public}d of event[%{public}s|%{public}s|%{public}" PRIu64 "] is invalid.", | ||
| 179 | - event->GetEventType(), event->domain_.c_str(), event->eventName_.c_str(), event->happenTime_); | ||
| 180 | - return false; | ||
| 181 | - } | ||
| 182 | - if (!baseInfo.level.empty()) { | ||
| 183 | - event->SetLevel(baseInfo.level); | ||
| 184 | - } | ||
| 185 | - if (!baseInfo.tag.empty()) { | ||
| 186 | - event->SetTag(baseInfo.tag); | ||
| 187 | - } | ||
| 188 | - event->SetPrivacy(baseInfo.privacy); | ||
| 189 | - return true; | ||
| 190 | -} | ||
| 191 | - | ||
| 192 | BaseInfo EventJsonParser::GetDefinedBaseInfoByDomainName(const std::string& domain, | 71 | BaseInfo EventJsonParser::GetDefinedBaseInfoByDomainName(const std::string& domain, |
| 193 | const std::string& name) const | 72 | const std::string& name) const |
| 194 | { | 73 | { |
| @@ -210,30 +89,6 @@ BaseInfo EventJsonParser::GetDefinedBaseInfoByDomainName(const std::string& doma | |||
| 210 | return nameIter->second; | 89 | return nameIter->second; |
| 211 | } | 90 | } |
| 212 | 91 | ||
| 213 | -bool EventJsonParser::CheckDuplicate(std::shared_ptr<SysEvent> event) | ||
| 214 | -{ | ||
| 215 | - auto sysEventId = GenerateHash(event); | ||
| 216 | - if (filter_.IsDuplicateEvent(sysEventId)) { | ||
| 217 | - HIVIEW_LOGW("ignore duplicate event[%{public}s|%{public}s|%{public}" PRIu64 "].", | ||
| 218 | - event->domain_.c_str(), event->eventName_.c_str(), event->happenTime_); | ||
| 219 | - return false; | ||
| 220 | - } | ||
| 221 | - // hash code need to add | ||
| 222 | - event->SetId(sysEventId); | ||
| 223 | - return true; | ||
| 224 | -} | ||
| 225 | - | ||
| 226 | -void EventJsonParser::AppendExtensiveInfo(std::shared_ptr<SysEvent> event) const | ||
| 227 | -{ | ||
| 228 | - // add testtype configured as system property named persist.sys.hiview.testtype | ||
| 229 | - if (!testType_.empty()) { | ||
| 230 | - event->SetEventValue(TEST_TYPE_KEY, testType_); | ||
| 231 | - } | ||
| 232 | - | ||
| 233 | - event->SetTag(GetTagByDomainAndName(event->domain_, event->eventName_)); | ||
| 234 | - event->preserve_ = GetPreserveByDomainAndName(event->domain_, event->eventName_); | ||
| 235 | -} | ||
| 236 | - | ||
| 237 | bool EventJsonParser::HasIntMember(const Json::Value& jsonObj, const std::string& name) const | 92 | bool EventJsonParser::HasIntMember(const Json::Value& jsonObj, const std::string& name) const |
| 238 | { | 93 | { |
| 239 | return jsonObj.isMember(name.c_str()) && jsonObj[name.c_str()].isInt(); | 94 | return jsonObj.isMember(name.c_str()) && jsonObj[name.c_str()].isInt(); |
| @@ -214,7 +214,7 @@ bool SocketDevice::IsValidMsg(char* msg, int32_t len) | |||
| 214 | } | 214 | } |
| 215 | int32_t dataByteCnt = *(reinterpret_cast<int32_t*>(msg)); | 215 | int32_t dataByteCnt = *(reinterpret_cast<int32_t*>(msg)); |
| 216 | if (dataByteCnt != len) { | 216 | if (dataByteCnt != len) { |
| 217 | - HIVIEW_LOGW("the data lengths=%{public}d are not equal", len); | 217 | + HIVIEW_LOGW("the data byte count=%{public}d are not equal to read length %{public}d", dataByteCnt, len); |
| 218 | return false; | 218 | return false; |
| 219 | } | 219 | } |
| 220 | int32_t pid = *(reinterpret_cast<int32_t*>(msg + sizeof(int32_t) + EventRaw::POS_OF_PID_IN_HEADER)); | 220 | int32_t pid = *(reinterpret_cast<int32_t*>(msg + sizeof(int32_t) + EventRaw::POS_OF_PID_IN_HEADER)); |
| @@ -42,15 +42,6 @@ struct BaseInfo { | |||
| 42 | using NAME_INFO_MAP = std::unordered_map<std::string, BaseInfo>; | 42 | using NAME_INFO_MAP = std::unordered_map<std::string, BaseInfo>; |
| 43 | using DOMAIN_INFO_MAP = std::unordered_map<std::string, NAME_INFO_MAP>; | 43 | using DOMAIN_INFO_MAP = std::unordered_map<std::string, NAME_INFO_MAP>; |
| 44 | using JSON_VALUE_LOOP_HANDLER = std::function<void(const std::string&, const Json::Value&)>; | 44 | using JSON_VALUE_LOOP_HANDLER = std::function<void(const std::string&, const Json::Value&)>; |
| 45 | -using FILTER_SIZE_TYPE = std::list<std::string>::size_type; | ||
| 46 | - | ||
| 47 | -class DuplicateIdFilter { | ||
| 48 | -public: | ||
| 49 | - bool IsDuplicateEvent(const uint64_t sysEventId); | ||
| 50 | - | ||
| 51 | -private: | ||
| 52 | - std::list<uint64_t> sysEventIds_; | ||
| 53 | -}; | ||
| 54 | 45 | ||
| 55 | class EventJsonParser { | 46 | class EventJsonParser { |
| 56 | public: | 47 | public: |
| @@ -61,16 +52,10 @@ public: | |||
| 61 | std::string GetTagByDomainAndName(const std::string& domain, const std::string& name) const; | 52 | std::string GetTagByDomainAndName(const std::string& domain, const std::string& name) const; |
| 62 | int GetTypeByDomainAndName(const std::string& domain, const std::string& name) const; | 53 | int GetTypeByDomainAndName(const std::string& domain, const std::string& name) const; |
| 63 | bool GetPreserveByDomainAndName(const std::string& domain, const std::string& name) const; | 54 | bool GetPreserveByDomainAndName(const std::string& domain, const std::string& name) const; |
| 64 | - bool HandleEventJson(const std::shared_ptr<SysEvent>& event); | ||
| 65 | - void UpdateTestType(const std::string& testType); | ||
| 66 | void ReadDefFile(const std::string& defFilePath); | 55 | void ReadDefFile(const std::string& defFilePath); |
| 56 | + BaseInfo GetDefinedBaseInfoByDomainName(const std::string& domain, const std::string& name) const; | ||
| 67 | 57 | ||
| 68 | private: | 58 | private: |
| 69 | - void AppendExtensiveInfo(std::shared_ptr<SysEvent> event) const; | ||
| 70 | - bool CheckEvent(std::shared_ptr<SysEvent> event); | ||
| 71 | - bool CheckBaseInfo(std::shared_ptr<SysEvent> event) const; | ||
| 72 | - bool CheckDuplicate(std::shared_ptr<SysEvent> event); | ||
| 73 | - BaseInfo GetDefinedBaseInfoByDomainName(const std::string& domain, const std::string& name) const; | ||
| 74 | bool HasIntMember(const Json::Value& jsonObj, const std::string& name) const; | 59 | bool HasIntMember(const Json::Value& jsonObj, const std::string& name) const; |
| 75 | bool HasStringMember(const Json::Value& jsonObj, const std::string& name) const; | 60 | bool HasStringMember(const Json::Value& jsonObj, const std::string& name) const; |
| 76 | bool HasBoolMember(const Json::Value& jsonObj, const std::string& name) const; | 61 | bool HasBoolMember(const Json::Value& jsonObj, const std::string& name) const; |
| @@ -82,8 +67,6 @@ private: | |||
| 82 | 67 | ||
| 83 | private: | 68 | private: |
| 84 | std::shared_ptr<DOMAIN_INFO_MAP> hiSysEventDefMap_ = nullptr; | 69 | std::shared_ptr<DOMAIN_INFO_MAP> hiSysEventDefMap_ = nullptr; |
| 85 | - DuplicateIdFilter filter_; | ||
| 86 | - std::string testType_; | ||
| 87 | }; // EventJsonParser | 70 | }; // EventJsonParser |
| 88 | } // namespace HiviewDFX | 71 | } // namespace HiviewDFX |
| 89 | } // namespace OHOS | 72 | } // namespace OHOS |
| @@ -67,7 +67,7 @@ public: | |||
| 67 | private: | 67 | private: |
| 68 | void AccumulateTimeInterval(uint64_t costTime, std::map<int8_t, uint32_t> &stat); | 68 | void AccumulateTimeInterval(uint64_t costTime, std::map<int8_t, uint32_t> &stat); |
| 69 | void CalcOverBenckMarkPct(PerfMeasure &perfMeasure); | 69 | void CalcOverBenckMarkPct(PerfMeasure &perfMeasure); |
| 70 | - std::shared_ptr<SysEvent> CreateProfileReport(PerfMeasure &perfMeasure); | 70 | + void ReportProfile(const PerfMeasure& perfMeasure); |
| 71 | void GetCostTimeInterval(PerfMeasure &perfMeasure); | 71 | void GetCostTimeInterval(PerfMeasure &perfMeasure); |
| 72 | void GetDomainsStat(PerfMeasure &perfMeasure); | 72 | void GetDomainsStat(PerfMeasure &perfMeasure); |
| 73 | void GetMaxSpeed(PerfMeasure &perfMeasure) const; | 73 | void GetMaxSpeed(PerfMeasure &perfMeasure) const; |
| @@ -57,10 +57,14 @@ public: | |||
| 57 | bool PublishPipelineEvent(std::shared_ptr<PipelineEvent> event); | 57 | bool PublishPipelineEvent(std::shared_ptr<PipelineEvent> event); |
| 58 | void Dump(int fd, const std::vector<std::string>& cmds) override; | 58 | void Dump(int fd, const std::vector<std::string>& cmds) override; |
| 59 | void OnConfigUpdate(const std::string& localCfgPath, const std::string& cloudCfgPath) override; | 59 | void OnConfigUpdate(const std::string& localCfgPath, const std::string& cloudCfgPath) override; |
| 60 | + void UpdateTestType(const std::string& testType); | ||
| 60 | 61 | ||
| 61 | private: | 62 | private: |
| 62 | void InitController(); | 63 | void InitController(); |
| 64 | + bool IsValidSysEvent(const std::shared_ptr<SysEvent> event); | ||
| 63 | std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event); | 65 | std::shared_ptr<SysEvent> Convert2SysEvent(std::shared_ptr<Event>& event); |
| 66 | + void DecorateSysEvent(const std::shared_ptr<SysEvent> event, const BaseInfo& info, uint64_t id); | ||
| 67 | + bool IsDuplicateEvent(const uint64_t eventId); | ||
| 64 | 68 | ||
| 65 | private: | 69 | private: |
| 66 | EventServer eventServer_; | 70 | EventServer eventServer_; |
| @@ -69,6 +73,8 @@ private: | |||
| 69 | std::shared_ptr<EventJsonParser> sysEventParser_ = nullptr; | 73 | std::shared_ptr<EventJsonParser> sysEventParser_ = nullptr; |
| 70 | std::shared_ptr<IController> controller_; | 74 | std::shared_ptr<IController> controller_; |
| 71 | std::atomic<bool> isConfigUpdated_ { false }; | 75 | std::atomic<bool> isConfigUpdated_ { false }; |
| 76 | + std::string testType_; | ||
| 77 | + std::list<uint64_t> eventIdList_; | ||
| 72 | }; | 78 | }; |
| 73 | } // namespace HiviewDFX | 79 | } // namespace HiviewDFX |
| 74 | } // namespace OHOS | 80 | } // namespace OHOS |
| @@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | + | ||
| 24 | 25 | ||
| 25 | 26 | ||
| 26 | 27 | ||
| @@ -34,8 +35,8 @@ namespace HiviewDFX { | |||
| 34 | DEFINE_LOG_TAG("HiView-Monitor"); | 35 | DEFINE_LOG_TAG("HiView-Monitor"); |
| 35 | namespace { | 36 | namespace { |
| 36 | constexpr uint8_t SLEEP_TEN_SECONDS = 10; | 37 | constexpr uint8_t SLEEP_TEN_SECONDS = 10; |
| 37 | -constexpr char EVENT_SERVICE_PLUGIN[] = "SysEventService"; | ||
| 38 | }; | 38 | }; |
| 39 | + | ||
| 39 | void PlatformMonitor::AccumulateTimeInterval(uint64_t costTime, std::map<int8_t, uint32_t> &stat) | 40 | void PlatformMonitor::AccumulateTimeInterval(uint64_t costTime, std::map<int8_t, uint32_t> &stat) |
| 40 | { | 41 | { |
| 41 | std::lock_guard<std::mutex> lock(statMutex_); | 42 | std::lock_guard<std::mutex> lock(statMutex_); |
| @@ -220,29 +221,21 @@ void PlatformMonitor::GetMaxSpeed(PerfMeasure &perfMeasure) const | |||
| 220 | perfMeasure.maxSpeed = maxSpeed_; | 221 | perfMeasure.maxSpeed = maxSpeed_; |
| 221 | } | 222 | } |
| 222 | 223 | ||
| 223 | -std::shared_ptr<SysEvent> PlatformMonitor::CreateProfileReport(PerfMeasure &perfMeasure) | 224 | +void PlatformMonitor::ReportProfile(const PerfMeasure& perfMeasure) |
| 224 | { | 225 | { |
| 225 | - SysEventCreator eventCreator("HIVIEWDFX", "PROFILE_STAT", SysEventCreator::STATISTIC); | 226 | + int ret = HiSysEventWrite(HiSysEvent::Domain::HIVIEWDFX, "PROFILE_STAT", HiSysEvent::EventType::STATISTIC, |
| 226 | - eventCreator.SetKeyValue("MAX_TOTAL_COUNT", perfMeasure.maxTotalCount); | 227 | + "MAX_TOTAL_COUNT", perfMeasure.maxTotalCount, "MAX_TOTAL_SIZE", perfMeasure.maxTotalSize, |
| 227 | - eventCreator.SetKeyValue("MAX_TOTAL_SIZE", perfMeasure.maxTotalSize); | 228 | + "DOMAINS", perfMeasure.domains, "DOMAIN_DETAIL", perfMeasure.domainCounts, |
| 228 | - eventCreator.SetKeyValue("DOMAINS", perfMeasure.domains); | 229 | + "TOTAL_COUNT", perfMeasure.totalCount, "TOTAL_SIZE", perfMeasure.totalSize, |
| 229 | - eventCreator.SetKeyValue("DOMAIN_DETAIL", perfMeasure.domainCounts); | 230 | + "BREAK_COUNT", perfMeasure.breakCount, "BREAK_DURATION", perfMeasure.breakDuration, |
| 230 | - eventCreator.SetKeyValue("TOTAL_COUNT", perfMeasure.totalCount); | 231 | + "MIN_SPEED", perfMeasure.minSpeed, "MAX_SPEED", perfMeasure.maxSpeed, "REAL_COUNT", perfMeasure.realCounts, |
| 231 | - eventCreator.SetKeyValue("TOTAL_SIZE", perfMeasure.totalSize); | 232 | + "PROCESS_COUNT", perfMeasure.processCounts, "WAIT_COUNT", perfMeasure.waitCounts, |
| 232 | - eventCreator.SetKeyValue("BREAK_COUNT", perfMeasure.breakCount); | 233 | + "FINISHED_COUNT", perfMeasure.finishedCount, "OVER_REAL_COUNT", perfMeasure.overRealTotalCount, |
| 233 | - eventCreator.SetKeyValue("BREAK_DURATION", perfMeasure.breakDuration); | 234 | + "OVER_REAL_PCT", perfMeasure.realPercent, "OVER_PROC_COUNT", perfMeasure.overProcessTotalCount, |
| 234 | - eventCreator.SetKeyValue("MIN_SPEED", perfMeasure.minSpeed); | 235 | + "OVER_PROC_PCT", perfMeasure.processpercent); |
| 235 | - eventCreator.SetKeyValue("MAX_SPEED", perfMeasure.maxSpeed); | 236 | + if (ret != SUCCESS) { |
| 236 | - eventCreator.SetKeyValue("REAL_COUNT", perfMeasure.realCounts); | 237 | + HIVIEW_LOGE("failed to write PROFILE_STAT event, ret is %{public}d", ret); |
| 237 | - eventCreator.SetKeyValue("PROCESS_COUNT", perfMeasure.processCounts); | 238 | + } |
| 238 | - eventCreator.SetKeyValue("WAIT_COUNT", perfMeasure.waitCounts); | ||
| 239 | - eventCreator.SetKeyValue("FINISHED_COUNT", perfMeasure.finishedCount); | ||
| 240 | - eventCreator.SetKeyValue("OVER_REAL_COUNT", perfMeasure.overRealTotalCount); | ||
| 241 | - eventCreator.SetKeyValue("OVER_REAL_PCT", perfMeasure.realPercent); | ||
| 242 | - eventCreator.SetKeyValue("OVER_PROC_COUNT", perfMeasure.overProcessTotalCount); | ||
| 243 | - eventCreator.SetKeyValue("OVER_PROC_PCT", perfMeasure.processpercent); | ||
| 244 | - std::shared_ptr<SysEvent> sysEvent = std::make_shared<SysEvent>("", nullptr, eventCreator); | ||
| 245 | - return sysEvent; | ||
| 246 | } | 239 | } |
| 247 | 240 | ||
| 248 | void PlatformMonitor::ReportCycleProfile() | 241 | void PlatformMonitor::ReportCycleProfile() |
| @@ -267,13 +260,7 @@ void PlatformMonitor::ReportCycleProfile() | |||
| 267 | // report percent and total number of over benchmark | 260 | // report percent and total number of over benchmark |
| 268 | CalcOverBenckMarkPct(perfMeasure); | 261 | CalcOverBenckMarkPct(perfMeasure); |
| 269 | 262 | ||
| 270 | - std::shared_ptr<SysEvent> sysEvent = CreateProfileReport(perfMeasure); | 263 | + ReportProfile(perfMeasure); |
| 271 | - if (sysEvent == nullptr) { | ||
| 272 | - return; | ||
| 273 | - } | ||
| 274 | - HIVIEW_LOGI("report event[%{public}s|%{public}s|%{public}" PRIu64 "].", sysEvent->domain_.c_str(), | ||
| 275 | - sysEvent->eventName_.c_str(), sysEvent->GetEventUintValue("time_")); | ||
| 276 | - HiviewGlobal::GetInstance()->PostSyncEventToTarget(EVENT_SERVICE_PLUGIN, sysEvent); | ||
| 277 | HIVIEW_LOGI("report performance profile have done"); | 264 | HIVIEW_LOGI("report performance profile have done"); |
| 278 | } | 265 | } |
| 279 | 266 | ||
| @@ -357,34 +344,25 @@ void PlatformMonitor::ReportBreakProfile() | |||
| 357 | std::vector<std::string> domains; | 344 | std::vector<std::string> domains; |
| 358 | std::vector<uint32_t> domainCounts; | 345 | std::vector<uint32_t> domainCounts; |
| 359 | GetTopDomains(domains, domainCounts); | 346 | GetTopDomains(domains, domainCounts); |
| 360 | - SysEventCreator eventCreator("HIVIEWDFX", "BREAK", SysEventCreator::BEHAVIOR); | 347 | + int ret = HiSysEventWrite(HiSysEvent::Domain::HIVIEWDFX, "BREAK", HiSysEvent::EventType::BEHAVIOR, |
| 361 | - eventCreator.SetKeyValue("TOTAL_COUNT", curTotalCount_); | 348 | + "TOTAL_COUNT", curTotalCount_, "TOTAL_SIZE", curTotalSize_, "REAL_SPEED", curRealSpeed, |
| 362 | - eventCreator.SetKeyValue("TOTAL_SIZE", curTotalSize_); | 349 | + "PROC_SPEED", curProcessSpeed, "AVG_REAL_TIME", avgRealTime, "AVG_PROC_TIME", avgProcessTime, |
| 363 | - eventCreator.SetKeyValue("REAL_SPEED", curRealSpeed); | 350 | + "AVG_WAIT_TIME", avgWaitTime, "TOP_EVENT", events, "TOP_EVENT_COUNT", eventCounts, "TOP_DOMAIN", domains, |
| 364 | - eventCreator.SetKeyValue("PROC_SPEED", curProcessSpeed); | 351 | + "TOP_DOMAIN_COUNT", domainCounts); |
| 365 | - eventCreator.SetKeyValue("AVG_REAL_TIME", avgRealTime); | 352 | + if (ret != SUCCESS) { |
| 366 | - eventCreator.SetKeyValue("AVG_PROC_TIME", avgProcessTime); | 353 | + HIVIEW_LOGE("failed to write BREAK event, ret is %{public}d", ret); |
| 367 | - eventCreator.SetKeyValue("AVG_WAIT_TIME", avgWaitTime); | 354 | + } |
| 368 | - eventCreator.SetKeyValue("TOP_EVENT", events); | ||
| 369 | - eventCreator.SetKeyValue("TOP_EVENT_COUNT", eventCounts); | ||
| 370 | - eventCreator.SetKeyValue("TOP_DOMAIN", domains); | ||
| 371 | - eventCreator.SetKeyValue("TOP_DOMAIN_COUNT", domainCounts); | ||
| 372 | - std::shared_ptr<SysEvent> sysEvent = std::make_shared<SysEvent>("", nullptr, eventCreator); | ||
| 373 | - HIVIEW_LOGI("report event[%{public}s|%{public}s|%{public}" PRIu64 "].", sysEvent->domain_.c_str(), | ||
| 374 | - sysEvent->eventName_.c_str(), sysEvent->GetEventUintValue("time_")); | ||
| 375 | - HiviewGlobal::GetInstance()->PostSyncEventToTarget(EVENT_SERVICE_PLUGIN, sysEvent); | ||
| 376 | } | 355 | } |
| 377 | 356 | ||
| 378 | void PlatformMonitor::ReportRecoverProfile() | 357 | void PlatformMonitor::ReportRecoverProfile() |
| 379 | { | 358 | { |
| 380 | // report break duration when recovery | 359 | // report break duration when recovery |
| 381 | int64_t duration = static_cast<int64_t>(recoverTimestamp_ - breakTimestamp_); | 360 | int64_t duration = static_cast<int64_t>(recoverTimestamp_ - breakTimestamp_); |
| 382 | - SysEventCreator eventCreator("HIVIEWDFX", "RECOVER", SysEventCreator::BEHAVIOR); | 361 | + int ret = HiSysEventWrite(HiSysEvent::Domain::HIVIEWDFX, "RECOVER", HiSysEvent::EventType::BEHAVIOR, |
| 383 | - eventCreator.SetKeyValue("DURATION", duration); | 362 | + "DURATION", duration); |
| 384 | - std::shared_ptr<SysEvent> sysEvent = std::make_shared<SysEvent>("", nullptr, eventCreator); | 363 | + if (ret != SUCCESS) { |
| 385 | - HIVIEW_LOGI("report event[%{public}s|%{public}s|%{public}" PRIu64 "].", sysEvent->domain_.c_str(), | 364 | + HIVIEW_LOGE("failed to write RECOVER event, ret is %{public}d", ret); |
| 386 | - sysEvent->eventName_.c_str(), sysEvent->GetEventUintValue("time_")); | 365 | + } |
| 387 | - HiviewGlobal::GetInstance()->PostSyncEventToTarget(EVENT_SERVICE_PLUGIN, sysEvent); | ||
| 388 | } | 366 | } |
| 389 | 367 | ||
| 390 | void PlatformMonitor::Breaking() | 368 | void PlatformMonitor::Breaking() |
| @@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | + | ||
| 24 | 25 | ||
| 25 | 26 | ||
| 26 | 27 | ||
| @@ -29,6 +30,7 @@ | |||
| 29 | 30 | ||
| 30 | 31 | ||
| 31 | 32 | ||
| 33 | + | ||
| 32 | 34 | ||
| 33 | 35 | ||
| 34 | 36 | ||
| @@ -40,6 +42,48 @@ DEFINE_LOG_TAG("HiView-SysEventSource"); | |||
| 40 | constexpr char DEF_FILE_NAME[] = "hisysevent.def"; | 42 | constexpr char DEF_FILE_NAME[] = "hisysevent.def"; |
| 41 | constexpr char DEF_ZIP_NAME[] = "hisysevent.zip"; | 43 | constexpr char DEF_ZIP_NAME[] = "hisysevent.zip"; |
| 42 | constexpr char DEF_CFG_DIR[] = "sys_event_def"; | 44 | constexpr char DEF_CFG_DIR[] = "sys_event_def"; |
| 45 | +constexpr char TEST_TYPE_PARAM_KEY[] = "hiviewdfx.hiview.testtype"; | ||
| 46 | +constexpr char TEST_TYPE_KEY[] = "test_type_"; | ||
| 47 | + | ||
| 48 | +uint64_t GenerateHash(std::shared_ptr<SysEvent> event) | ||
| 49 | +{ | ||
| 50 | + if (event == nullptr) { | ||
| 51 | + return 0; | ||
| 52 | + } | ||
| 53 | + constexpr size_t infoLenLimit = 256; | ||
| 54 | + size_t infoLen = event->rawData_->GetDataLength(); | ||
| 55 | + size_t hashLen = (infoLen < infoLenLimit) ? infoLen : infoLenLimit; | ||
| 56 | + const uint8_t* p = event->rawData_->GetData(); | ||
| 57 | + uint64_t ret { 0xCBF29CE484222325ULL }; // basis value | ||
| 58 | + size_t i = 0; | ||
| 59 | + while (i < hashLen) { | ||
| 60 | + ret ^= *(p + i); | ||
| 61 | + ret *= 0x100000001B3ULL; // prime value | ||
| 62 | + i++; | ||
| 63 | + } | ||
| 64 | + return ret; | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +void ParameterWatchCallback(const char* key, const char* value, void* context) | ||
| 68 | +{ | ||
| 69 | + if (context == nullptr) { | ||
| 70 | + HIVIEW_LOGE("context is null"); | ||
| 71 | + return; | ||
| 72 | + } | ||
| 73 | + auto eventSourcePlugin = reinterpret_cast<SysEventSource*>(context); | ||
| 74 | + if (eventSourcePlugin == nullptr) { | ||
| 75 | + HIVIEW_LOGE("eventsource plugin is null"); | ||
| 76 | + return; | ||
| 77 | + } | ||
| 78 | + size_t testTypeStrMaxLen = 256; | ||
| 79 | + std::string testTypeStr(value); | ||
| 80 | + if (testTypeStr.size() > testTypeStrMaxLen) { | ||
| 81 | + HIVIEW_LOGE("length of the test type string set exceeds the limit"); | ||
| 82 | + return; | ||
| 83 | + } | ||
| 84 | + HIVIEW_LOGI("test_type is set to be \"%{public}s\"", testTypeStr.c_str()); | ||
| 85 | + eventSourcePlugin->UpdateTestType(testTypeStr); | ||
| 86 | +} | ||
| 43 | } | 87 | } |
| 44 | 88 | ||
| 45 | void SysEventReceiver::HandlerEvent(std::shared_ptr<EventRaw::RawData> rawData) | 89 | void SysEventReceiver::HandlerEvent(std::shared_ptr<EventRaw::RawData> rawData) |
| @@ -83,6 +127,11 @@ void SysEventSource::OnLoad() | |||
| 83 | [this] (const std::string& domain, const std::string& name) { | 127 | [this] (const std::string& domain, const std::string& name) { |
| 84 | return this->sysEventParser_->GetTypeByDomainAndName(domain, name); | 128 | return this->sysEventParser_->GetTypeByDomainAndName(domain, name); |
| 85 | }); | 129 | }); |
| 130 | + | ||
| 131 | + // watch parameter | ||
| 132 | + if (WatchParameter(TEST_TYPE_PARAM_KEY, ParameterWatchCallback, this) != 0) { | ||
| 133 | + HIVIEW_LOGW("failed to watch the change of parameter %{public}s", TEST_TYPE_PARAM_KEY); | ||
| 134 | + } | ||
| 86 | } | 135 | } |
| 87 | 136 | ||
| 88 | void SysEventSource::InitController() | 137 | void SysEventSource::InitController() |
| @@ -169,7 +218,7 @@ bool SysEventSource::CheckEvent(std::shared_ptr<Event> event) | |||
| 169 | return false; | 218 | return false; |
| 170 | } | 219 | } |
| 171 | EventStore::SysEventDao::CheckRepeat(sysEvent); | 220 | EventStore::SysEventDao::CheckRepeat(sysEvent); |
| 172 | - if (!sysEventParser_->HandleEventJson(sysEvent)) { | 221 | + if (!IsValidSysEvent(sysEvent)) { |
| 173 | sysEventStat_->AccumulateEvent(sysEvent->domain_, sysEvent->eventName_, false); | 222 | sysEventStat_->AccumulateEvent(sysEvent->domain_, sysEvent->eventName_, false); |
| 174 | return false; | 223 | return false; |
| 175 | } | 224 | } |
| @@ -226,5 +275,71 @@ void SysEventSource::OnConfigUpdate(const std::string& localCfgPath, const std:: | |||
| 226 | { | 275 | { |
| 227 | this->isConfigUpdated_.store(true); | 276 | this->isConfigUpdated_.store(true); |
| 228 | } | 277 | } |
| 278 | + | ||
| 279 | +bool SysEventSource::IsValidSysEvent(const std::shared_ptr<SysEvent> event) | ||
| 280 | +{ | ||
| 281 | + if (event->domain_.empty() || event->eventName_.empty()) { | ||
| 282 | + HIVIEW_LOGW("domain=%{public}s or name=%{public}s is empty.", | ||
| 283 | + event->domain_.c_str(), event->eventName_.c_str()); | ||
| 284 | + return false; | ||
| 285 | + } | ||
| 286 | + auto baseInfo = sysEventParser_->GetDefinedBaseInfoByDomainName(event->domain_, event->eventName_); | ||
| 287 | + if (baseInfo.type == INVALID_EVENT_TYPE) { | ||
| 288 | + HIVIEW_LOGW("type defined for event[%{public}s|%{public}s|%{public}" PRIu64 "] is invalid.", | ||
| 289 | + event->domain_.c_str(), event->eventName_.c_str(), event->happenTime_); | ||
| 290 | + return false; | ||
| 291 | + } | ||
| 292 | + if (event->GetEventType() != baseInfo.type) { | ||
| 293 | + HIVIEW_LOGW("type=%{public}d of event[%{public}s|%{public}s|%{public}" PRIu64 "] is invalid.", | ||
| 294 | + event->GetEventType(), event->domain_.c_str(), event->eventName_.c_str(), event->happenTime_); | ||
| 295 | + return false; | ||
| 296 | + } | ||
| 297 | + // append id | ||
| 298 | + auto eventId = GenerateHash(event); | ||
| 299 | + if (IsDuplicateEvent(eventId)) { | ||
| 300 | + HIVIEW_LOGW("ignore duplicate event[%{public}s|%{public}s|%{public}" PRIu64 "].", | ||
| 301 | + event->domain_.c_str(), event->eventName_.c_str(), eventId); | ||
| 302 | + return false; | ||
| 303 | + } | ||
| 304 | + DecorateSysEvent(event, baseInfo, eventId); | ||
| 305 | + return true; | ||
| 306 | +} | ||
| 307 | + | ||
| 308 | +void SysEventSource::UpdateTestType(const std::string& testType) | ||
| 309 | +{ | ||
| 310 | + testType_ = testType; | ||
| 311 | +} | ||
| 312 | + | ||
| 313 | +void SysEventSource::DecorateSysEvent(const std::shared_ptr<SysEvent> event, const BaseInfo& baseInfo, uint64_t id) | ||
| 314 | +{ | ||
| 315 | + if (!baseInfo.level.empty()) { | ||
| 316 | + event->SetLevel(baseInfo.level); | ||
| 317 | + } | ||
| 318 | + if (!baseInfo.tag.empty()) { | ||
| 319 | + event->SetTag(baseInfo.tag); | ||
| 320 | + } | ||
| 321 | + event->SetPrivacy(baseInfo.privacy); | ||
| 322 | + if (!testType_.empty()) { | ||
| 323 | + event->SetEventValue(TEST_TYPE_KEY, testType_); | ||
| 324 | + } | ||
| 325 | + event->preserve_ = baseInfo.preserve; | ||
| 326 | + // add hashcode id | ||
| 327 | + event->SetId(id); | ||
| 328 | +} | ||
| 329 | + | ||
| 330 | +bool SysEventSource::IsDuplicateEvent(const uint64_t eventId) | ||
| 331 | +{ | ||
| 332 | + for (auto iter = eventIdList_.begin(); iter != eventIdList_.end(); iter++) { | ||
| 333 | + if (*iter == eventId) { | ||
| 334 | + return true; | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + std::list<std::string>::size_type maxSize { 5 }; // size of queue limit to 5 | ||
| 338 | + if (eventIdList_.size() >= maxSize) { | ||
| 339 | + eventIdList_.pop_front(); | ||
| 340 | + } | ||
| 341 | + eventIdList_.emplace_back(eventId); | ||
| 342 | + return false; | ||
| 343 | +} | ||
| 229 | } // namespace HiviewDFX | 344 | } // namespace HiviewDFX |
| 230 | } // namespace OHOS | 345 | } // namespace OHOS |
| @@ -0,0 +1,32 @@ | |||
| 1 | +{ | ||
| 2 | + "FIRST_TEST_DOMAIN": { | ||
| 3 | + "FIRST_TEST_NAME": { | ||
| 4 | + "__BASE": { | ||
| 5 | + "type": "BEHAVIOR", | ||
| 6 | + "level": "CRITICAL", | ||
| 7 | + "tag": "FIRST_TEST_CASE", | ||
| 8 | + "desc": "test", | ||
| 9 | + "privacy": 1, | ||
| 10 | + "preserve": false | ||
| 11 | + }, | ||
| 12 | + "FIRST_TEST_PARAM": { | ||
| 13 | + "type": "INT32", | ||
| 14 | + "desc": "param1" | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + }, | ||
| 18 | + "SECOND_TEST_DOMAIN": { | ||
| 19 | + "SECOND_TEST_NAME": { | ||
| 20 | + "__BASE": { | ||
| 21 | + "type": "FAULT", | ||
| 22 | + "level": "CRITICAL", | ||
| 23 | + "tag": "SECOND_TEST_CASE", | ||
| 24 | + "desc": "test" | ||
| 25 | + }, | ||
| 26 | + "SECOND_TEST_PARAM": { | ||
| 27 | + "type": "INT32", | ||
| 28 | + "desc": "second_param" | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + } | ||
| 32 | +} | ||
| @@ -21,4 +21,12 @@ | |||
| 21 | <option name="shell" value="rm -rf /data/test/hiview/daily_control"/> | 21 | <option name="shell" value="rm -rf /data/test/hiview/daily_control"/> |
| 22 | </cleaner> | 22 | </cleaner> |
| 23 | </target> | 23 | </target> |
| 24 | + <target name="EventJsonParserTest"> | ||
| 25 | + <preparer> | ||
| 26 | + <option name="push" value="config/hisysevent.def -> /data/test/hiview/sys_def_parser" src="res"/> | ||
| 27 | + </preparer> | ||
| 28 | + <cleaner> | ||
| 29 | + <option name="shell" value="rm -rf /data/test/hiview/sys_def_parser"/> | ||
| 30 | + </cleaner> | ||
| 31 | + </target> | ||
| 24 | </configuration> | 32 | </configuration> |
| @@ -113,4 +113,7 @@ ohos_unittest("EventJsonParserTest") { | |||
| 113 | "hilog:libhilog", | 113 | "hilog:libhilog", |
| 114 | "jsoncpp:jsoncpp", | 114 | "jsoncpp:jsoncpp", |
| 115 | ] | 115 | ] |
| 116 | + | ||
| 117 | + resource_config_file = | ||
| 118 | + "$hiview_plugin/sysevent_source/test/resource/ohos_test.xml" | ||
| 116 | } | 119 | } |
| @@ -14,12 +14,22 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | - | ||
| 18 | - | ||
| 19 | 17 | ||
| 20 | 18 | ||
| 21 | namespace OHOS { | 19 | namespace OHOS { |
| 22 | namespace HiviewDFX { | 20 | namespace HiviewDFX { |
| 21 | +namespace { | ||
| 22 | +constexpr char TEST_DEF_FILE_PATH[] = "/data/test/hiview/sys_def_parser/hisysevent.def"; | ||
| 23 | +constexpr char INVALID_TEST_DEF_FILE_PATH[] = "/data/test/hiview/sys_def_parser/hisysevent_.def"; | ||
| 24 | +constexpr char FIRST_TEST_DOMAIN[] = "FIRST_TEST_DOMAIN"; | ||
| 25 | +constexpr char FIRST_TEST_NAME[] = "FIRST_TEST_NAME"; | ||
| 26 | +constexpr int FIRST_TEST_EVENT_TYPE = 4; | ||
| 27 | +constexpr char SECOND_TEST_DOMAIN[] = "SECOND_TEST_DOMAIN"; | ||
| 28 | +constexpr char SECOND_TEST_NAME[] = "SECOND_TEST_NAME"; | ||
| 29 | +constexpr int SECOND_TEST_EVENT_TYPE = 1; | ||
| 30 | +constexpr int TEST_PRIVACY = 1; | ||
| 31 | +} | ||
| 32 | + | ||
| 23 | void EventJsonParserTest::SetUpTestCase() {} | 33 | void EventJsonParserTest::SetUpTestCase() {} |
| 24 | 34 | ||
| 25 | void EventJsonParserTest::TearDownTestCase() {} | 35 | void EventJsonParserTest::TearDownTestCase() {} |
| @@ -32,35 +42,31 @@ void EventJsonParserTest::TearDown() {} | |||
| 32 | * @tc.name: EventJsonParserTest001 | 42 | * @tc.name: EventJsonParserTest001 |
| 33 | * @tc.desc: parse a event and check Json info | 43 | * @tc.desc: parse a event and check Json info |
| 34 | * @tc.type: FUNC | 44 | * @tc.type: FUNC |
| 35 | - * @tc.require: issueI62WJT | 45 | + * @tc.require: issueIAKF5E |
| 36 | */ | 46 | */ |
| 37 | HWTEST_F(EventJsonParserTest, EventJsonParserTest001, testing::ext::TestSize.Level0) | 47 | HWTEST_F(EventJsonParserTest, EventJsonParserTest001, testing::ext::TestSize.Level0) |
| 38 | { | 48 | { |
| 39 | - printf("start EventJsonParserTest001\n"); | 49 | + EventJsonParser jsonParser(INVALID_TEST_DEF_FILE_PATH); |
| 40 | - std::string defFilePath = "/system/etc/hiview/hisysevent.def"; | 50 | + ASSERT_EQ(jsonParser.GetTagByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), ""); |
| 41 | - auto sysEventParser = std::make_unique<EventJsonParser>(defFilePath); | 51 | + ASSERT_EQ(jsonParser.GetTypeByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), INVALID_EVENT_TYPE); |
| 52 | + ASSERT_EQ(jsonParser.GetPreserveByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), true); | ||
| 53 | + auto configBaseInfo = jsonParser.GetDefinedBaseInfoByDomainName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME); | ||
| 54 | + ASSERT_TRUE(configBaseInfo.preserve); | ||
| 42 | 55 | ||
| 43 | - std::shared_ptr<SysEvent> sysEvent = nullptr; | 56 | + jsonParser.ReadDefFile(TEST_DEF_FILE_PATH); |
| 44 | - ASSERT_FALSE(sysEventParser->HandleEventJson(sysEvent)); | 57 | + ASSERT_EQ(jsonParser.GetTagByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), "FIRST_TEST_CASE"); |
| 45 | - constexpr char invalidJsonStr[] = "{\"domain_\":\"HIVIEWDFX\", \"type_\":4,\ | 58 | + ASSERT_EQ(jsonParser.GetTypeByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), FIRST_TEST_EVENT_TYPE); |
| 46 | - \"PARAM_A\":\"param a\", \"PARAM_B\":\"param b\"}"; | 59 | + ASSERT_EQ(jsonParser.GetPreserveByDomainAndName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME), false); |
| 47 | - sysEvent = std::make_shared<SysEvent>("SysEventService", nullptr, invalidJsonStr); | 60 | + configBaseInfo = jsonParser.GetDefinedBaseInfoByDomainName(FIRST_TEST_DOMAIN, FIRST_TEST_NAME); |
| 48 | - ASSERT_FALSE(sysEventParser->HandleEventJson(sysEvent)); | 61 | + ASSERT_FALSE(configBaseInfo.preserve); |
| 49 | - constexpr char jsonStr[] = "{\"domain_\":\"HIVIEWDFX\", \"name_\":\"PLUGIN_LOAD\", \"type_\":4,\ | 62 | + ASSERT_EQ(configBaseInfo.privacy, TEST_PRIVACY); |
| 50 | - \"PARAM_A\":\"param a\", \"PARAM_B\":\"param b\"}"; | ||
| 51 | - sysEvent = std::make_shared<SysEvent>("SysEventService", nullptr, jsonStr); | ||
| 52 | 63 | ||
| 53 | - ASSERT_TRUE(sysEventParser->HandleEventJson(sysEvent)); | 64 | + ASSERT_EQ(jsonParser.GetTagByDomainAndName(SECOND_TEST_DOMAIN, SECOND_TEST_NAME), "SECOND_TEST_CASE"); |
| 54 | - ASSERT_TRUE(sysEventParser->GetTagByDomainAndName("abc", "abc") == ""); | 65 | + ASSERT_EQ(jsonParser.GetTypeByDomainAndName(SECOND_TEST_DOMAIN, SECOND_TEST_NAME), SECOND_TEST_EVENT_TYPE); |
| 55 | - ASSERT_TRUE(sysEventParser->GetTagByDomainAndName("DEMO", "abc") == ""); | 66 | + ASSERT_EQ(jsonParser.GetPreserveByDomainAndName(SECOND_TEST_DOMAIN, SECOND_TEST_NAME), true); |
| 56 | - ASSERT_TRUE(sysEventParser->GetTypeByDomainAndName("DEMO", "abc") == 0); | 67 | + configBaseInfo = jsonParser.GetDefinedBaseInfoByDomainName(SECOND_TEST_DOMAIN, SECOND_TEST_NAME); |
| 57 | - | 68 | + ASSERT_TRUE(configBaseInfo.preserve); |
| 58 | - sysEventParser->UpdateTestType("test_param"); | 69 | + ASSERT_EQ(configBaseInfo.privacy, DEFAULT_PRIVACY); |
| 59 | - | ||
| 60 | - DuplicateIdFilter filter; | ||
| 61 | - ASSERT_FALSE(filter.IsDuplicateEvent(0)); | ||
| 62 | - ASSERT_FALSE(filter.IsDuplicateEvent(1)); | ||
| 63 | - ASSERT_TRUE(filter.IsDuplicateEvent(1)); | ||
| 64 | } | 70 | } |
| 65 | } // namespace HiviewDFX | 71 | } // namespace HiviewDFX |
| 66 | } // namespace OHOS | 72 | } // namespace OHOS |