1 /* 2 * Copyright (c) 2024 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 CLOUD_DAEMON_STATISTIC_H 17 #define CLOUD_DAEMON_STATISTIC_H 18 19 #include <mutex> 20 #include <string> 21 22 #define FILE_TYPE_MAX 3 23 #define OPEN_SIZE_MAX 9 24 #define OPEN_TIME_MAX 7 25 #define READ_SIZE_MAX 6 26 #define READ_TIME_MAX 10 27 28 namespace OHOS { 29 namespace FileManagement { 30 namespace CloudFile { 31 using namespace std; 32 33 class CloudDaemonStatistic final { 34 public: 35 static CloudDaemonStatistic &GetInstance(); 36 CloudDaemonStatistic(const CloudDaemonStatistic&) = delete; 37 CloudDaemonStatistic& operator=(const CloudDaemonStatistic&) = delete; 38 39 /* size should be BYTE based, time should be MS based */ 40 void UpdateOpenSizeStat(uint64_t size); 41 void UpdateOpenTimeStat(uint32_t type, uint64_t time); 42 void UpdateReadSizeStat(uint64_t size); 43 void UpdateReadTimeStat(uint64_t size, uint64_t time); 44 void UpdateStatData(); 45 mutex mutex_; 46 private: 47 CloudDaemonStatistic() = default; 48 ~CloudDaemonStatistic() = default; 49 void AddFileData(); 50 void ClearStat(); 51 void OutputToFile(); 52 vector<uint64_t> openSizeStat_ = vector<uint64_t>(OPEN_SIZE_MAX, 0); 53 vector<vector<uint64_t>> openTimeStat_ = 54 vector<vector<uint64_t>>(FILE_TYPE_MAX, vector<uint64_t>(OPEN_TIME_MAX, 0)); 55 vector<uint64_t> readSizeStat_ = vector<uint64_t>(READ_SIZE_MAX, 0); 56 vector<vector<uint64_t>> readTimeStat_ = 57 vector<vector<uint64_t>>(READ_SIZE_MAX, vector<uint64_t>(READ_TIME_MAX, 0)); 58 }; 59 } // namespace CloudFile 60 } // namespace FileManagement 61 } // namespace OHOS 62 63 #endif // CLOUD_DAEMON_STATISTIC_H 64