1 /* 2 * Copyright (c) 2025 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 HIVIEW_PLUGINS_EVENT_PERIOD_INFO_UTIL_H 17 #define HIVIEW_PLUGINS_EVENT_PERIOD_INFO_UTIL_H 18 19 #include "sys_event.h" 20 #include "period_file_operator.h" 21 #include "plugin.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 constexpr uint64_t DEFAULT_PERIOD_SEQ = 1; // period seq begins with 1 26 27 struct EventPeriodInfo { 28 // format: YYYYMMDDHH 29 std::string timeStamp; 30 31 // count of event which will be preserve into db file in 1 hour 32 uint64_t preserveCnt = 0; 33 34 // count of event which will be exported in 1 hour 35 uint64_t exportCnt = 0; 36 EventPeriodInfoEventPeriodInfo37 EventPeriodInfo(const std::string& timeStamp, uint64_t preserveCnt, uint64_t exportCnt) 38 : timeStamp(timeStamp), preserveCnt(preserveCnt), exportCnt(exportCnt) {} 39 }; 40 41 class EventPeriodInfoUtil { 42 public: 43 void Init(HiviewContext* context); 44 void UpdatePeriodInfo(const std::shared_ptr<SysEvent> event); 45 46 private: 47 void ClearPeriodInfoList(); 48 void RecordEventPeriodInfo(); 49 50 private: 51 uint64_t periodSeq_ = DEFAULT_PERIOD_SEQ; 52 std::list<std::shared_ptr<EventPeriodInfo>> periodInfoList_; 53 std::unique_ptr<PeriodInfoFileOperator> periodFileOpt_; 54 }; 55 } // namespace HiviewDFX 56 } // namespace OHOS 57 #endif // HIVIEW_PLUGINS_EVENT_PERIOD_INFO_UTIL_H 58