• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FFRT_QUEUE_TRAFFIC_RECORD_H
17 #define FFRT_QUEUE_TRAFFIC_RECORD_H
18 
19 #include <vector>
20 #include "queue/serial_queue.h"
21 
22 namespace ffrt {
23 constexpr uint64_t DEFAULT_TRAFFIC_INTERVAL = 6000000;
24 
25 class QueueHandler;
26 class TrafficRecord {
27 public:
28     explicit TrafficRecord();
29     void SetTimeInterval(const uint64_t timeInterval);
30     void SubmitTraffic(QueueHandler* handler);
31     void DoneTraffic();
32     void DoneTraffic(uint32_t count);
33     static std::string DumpTrafficInfo(bool withLock = true);
34 
35     static std::vector<std::pair<uint64_t, std::string>> trafficRecordInfo;
36 private:
37     void CalculateTraffic(QueueHandler* handler, const uint64_t& time);
38     void ReportOverload(std::stringstream& ss);
39     void DetectCountThreshold();
40 
41     uint64_t timeInterval_ = DEFAULT_TRAFFIC_INTERVAL;
42     uint64_t lastCheckTime_ = 0;
43     uint64_t lastReportTime_ = 0;
44     std::atomic_uint32_t detectCnt_ = 0;
45     std::atomic_uint64_t nextUpdateTime_ = 0;
46 
47     std::atomic_uint32_t submitCnt_ = 0;
48     std::atomic_uint32_t doneCnt_ = 0;
49 
50     std::atomic_uint32_t doneCntOld_ = 0;
51     std::atomic_uint32_t submitCntOld_ = 0;
52 
53     static std::mutex mtx_;
54     int recordIndex_ = 0;
55 };
56 } // namespace ffrt
57 
58 #endif // FFRT_QUEUE_TRAFFIC_RECORD_H
59