• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 TASK_STATISTICS_H
17 #define TASK_STATISTICS_H
18 
19 #include <atomic>
20 #include <cstdint>
21 
22 namespace OHOS::Request::Download {
23 class TaskStatistics {
24 public:
25     static TaskStatistics &GetInstance();
26     void ReportTasksSize(uint64_t totalSize);
27     void ReportTasksNumber();
28     void StartTimerThread();
29 
30 private:
31     TaskStatistics() = default;
32     ~TaskStatistics() = default;
33     TaskStatistics(const TaskStatistics &) = delete;
34     TaskStatistics(TaskStatistics &&) = delete;
35     TaskStatistics &operator=(const TaskStatistics &) = delete;
36     TaskStatistics &operator=(TaskStatistics &&) = delete;
37     int32_t GetNextReportInterval() const;
38     void ReportStatistics() const;
39 private:
40     static constexpr const char *REQUEST_TASK_INFO_STATISTICS = "REQUEST_TASK_INFO_STATISTICS";
41     static constexpr const char *TASKS_SIZE = "TASKS_SIZE";
42     static constexpr const char *TASKS_NUMBER = "TASKS_NUMBER";
43     static constexpr int32_t ONE_DAY_SEC = 24 * 3600;
44     static constexpr int32_t ONE_HOUR_SEC = 3600;
45     static constexpr int32_t ONE_MINUTE_SEC = 60;
46 
47     std::atomic<uint32_t> dayTasksNumber_ {0};
48     std::atomic<uint64_t> dayTasksSize_ {0};
49     bool running_ { false };
50 };
51 }
52 #endif // TASK_STATISTICS_H
53