1 /* 2 * Copyright (c) 2023-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 OHOS_CAMERA_DPS_DEFERRED_EVENT_REPORT_H 17 #define OHOS_CAMERA_DPS_DEFERRED_EVENT_REPORT_H 18 19 #include "basic_definitions.h" 20 21 namespace OHOS { 22 namespace CameraStandard { 23 namespace DeferredProcessing { 24 const std::string EVENT_KEY_IMAGEID = "IMAGEID"; 25 const std::string EVENT_KEY_USERID = "USERID"; 26 const std::string EVENT_KEY_DEFEVENTTYPE = "DEFEVENTTYPE"; 27 const std::string EVENT_KEY_DISCARDABLE = "DISCARDABLE"; 28 const std::string EVENT_KEY_TRIGGERMODE = "TRIGGERMODE"; 29 const std::string EVENT_KEY_HIGHJOBNUM = "HIGHJOBNUM"; 30 const std::string EVENT_KEY_NORMALJOBNUM = "NORMALJOBNUM"; 31 const std::string EVENT_KEY_LOWJOBNUM = "LOWJOBNUM"; 32 const std::string EVENT_KEY_TEMPERATURELEVEL = "TEMPERATURELEVEL"; 33 const std::string EVENT_KEY_SYNCHRONIZETIME = "SYNCHRONIZETIME"; 34 const std::string EVENT_KEY_DISPATCHTIME = "DISPATCHTIME"; 35 const std::string EVENT_KEY_PROCESSTIME = "PROCESSTIME"; 36 const std::string EVENT_KEY_IMAGEDONETIME = "IMAGEDONETIME"; 37 const std::string EVENT_KEY_RESTORETIME = "RESTORETIME"; 38 const std::string EVENT_KEY_REMOVETIME = "CANCELTIME"; 39 const std::string EVENT_KEY_TRAILINGTIME = "TRAILINGTIME"; 40 const std::string EVENT_KEY_PHOTOJOBTYPE = "PHOTOJOBTYPE"; 41 const std::string EVENT_KEY_EXCUTIONMODE = "EXCUTIONMODE"; 42 const std::string EVENT_KEY_CHANGEREASON = "CHANGEREASON"; 43 const std::string EVENT_KEY_EXCEPTIONSOURCE = "EXCEPTIONSOURCE"; 44 const std::string EVENT_KEY_EXCEPTIONCAUSE = "EXCEPTIONCAUSE"; 45 const std::string EVENT_KEY_EXECUTIONMODE = "EXECUTIONMODE"; 46 const std::string EVENT_KEY_COMPONENT_NAME = "COMPONENT_NAME"; 47 const std::string EVENT_KEY_PARTITION_NAME = "PARTITION_NAME"; 48 const std::string EVENT_KEY_REMAIN_PARTITION_SIZE = "REMAIN_PARTITION_SIZE"; 49 const std::string EVENT_KEY_FILE_OR_FOLDER_PAT = "FILE_OR_FOLDER_PATH"; 50 const std::string EVENT_KEY_FILE_OR_FOLDER_SIZE = "FILE_OR_FOLDER_SIZE"; 51 const std::string COMPONENT_NAME = "camera_framework"; 52 const std::string PARTITION_NAME = "/data"; 53 54 struct DPSEventInfo { 55 std::string imageId; 56 int32_t userId; 57 TrigerMode triggerMode; 58 uint32_t operatorStage; 59 bool discardable; 60 uint64_t synchronizeTimeBeginTime; 61 uint64_t synchronizeTimeEndTime; 62 uint64_t dispatchTimeBeginTime; 63 uint64_t dispatchTimeEndTime; 64 uint64_t processTimeBeginTime; 65 uint64_t processTimeEndTime; 66 uint64_t imageDoneTimeBeginTime; 67 uint64_t imageDoneTimeEndTime; 68 uint64_t restoreTimeBeginTime; 69 uint64_t restoreTimeEndTime; 70 uint64_t removeTimeBeginTime; 71 uint64_t removeTimeEndTime; 72 uint64_t trailingTimeBeginTime; 73 uint64_t trailingTimeEndTime; 74 int32_t highJobNum; 75 int32_t normalJobNum; 76 int32_t lowJobNum; 77 int temperatureLevel; 78 PhotoJobType photoJobType; 79 EventType changeReason; 80 ExceptionSource exceptionSource; 81 ExceptionCause exceptionCause; 82 ExecutionMode executionMode = ExecutionMode::DUMMY; 83 }; 84 85 class DPSEventReport { 86 public: GetInstance()87 static DPSEventReport &GetInstance() 88 { 89 static DPSEventReport instance; 90 return instance; 91 } 92 void ReportOperateImage(const std::string& imageId, int32_t userId, DPSEventInfo& dpsEventInfo); 93 void ReportImageProcessResult(const std::string& imageId, int32_t userId, uint64_t endTime = 0); 94 void ReportImageModeChange(ExecutionMode executionMode); 95 void ReportImageException(const std::string& imageId, int32_t userId); 96 void ReportPartitionUsage(); 97 void SetEventInfo(const std::string& imageId, int32_t userId); 98 void SetEventInfo(DPSEventInfo& dpsEventInfo); 99 void RemoveEventInfo(const std::string& imageId, int32_t userId); 100 101 void SetTemperatureLevel(int temperatureLevel); 102 void SetExecutionMode(ExecutionMode executionMode); 103 void SetEventType(EventType eventType_); 104 void UpdateEventInfo(DPSEventInfo& dpsEventInfo); 105 void UpdateProcessDoneTime(const std::string& imageId, int32_t userId); 106 void UpdateRemoveTime(const std::string& imageId, int32_t userId); 107 void UpdateExecutionMode(const std::string& imageId, int32_t userId, ExecutionMode executionMode); 108 109 private: 110 DPSEventInfo GetEventInfo(const std::string& imageId, int32_t userId); 111 void UpdateSynchronizeTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 112 void UpdateDispatchTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 113 void UpdateProcessTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 114 void UpdateImageDoneTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 115 void UpdateRestoreTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 116 void UpdateRemoveTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 117 void UpdateTrailingTime(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 118 void UpdateExecutionMode(DPSEventInfo& dpsEventInfo, DPSEventInfo& dpsEventInfoSrc); 119 int GetTotalTime (uint64_t beginTime, uint64_t endTime); 120 bool GetDeviceValidSize(const std::string& path, double& size); 121 uint64_t GetFolderSize(const std::string& path); 122 std::recursive_mutex mutex_; 123 std::map<int32_t, std::map<std::string, DPSEventInfo>> userIdToImageIdEventInfo; //userid--imageid--eventinfo 124 ExecutionMode executionMode_; 125 int temperatureLevel_; 126 EventType eventType_; 127 }; 128 } // namespace DeferredProcessingService 129 } // namespace CameraStandard 130 } // namespace OHOS 131 #endif // OHOS_CAMERA_DPS_DEFERRED_PROCESSING_SERVICE_H