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