1 /*
2 * Copyright (c) 2023-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 #include "frame_rate_report.h"
16 #include <string>
17 #ifdef QOS_MANAGER
18 #include "concurrent_task_client.h"
19 #endif
20 #ifdef RES_SCHED_ENABLE
21 #include "res_sched_client.h"
22 #include "res_type.h"
23 #endif
24
25 namespace FRAME_TRACE {
26
27 FrameRateReport* FrameRateReport::instance_ = nullptr;
SendFrameRates(const std::unordered_map<int,uint32_t> & rates)28 bool FrameRateReport::SendFrameRates(const std::unordered_map<int, uint32_t>& rates)
29 {
30 if (rates.empty()) {
31 return true;
32 }
33 #ifdef QOS_MANAGER
34 OHOS::ConcurrentTask::DeadlineReply ddlReply;
35 OHOS::ConcurrentTask::ConcurrentTaskClient::GetInstance().QueryDeadline(
36 OHOS::ConcurrentTask::DDL_RATE, ddlReply, rates);
37 return ddlReply.setStatus;
38 #else
39 return true;
40 #endif
41 }
42
SendFrameRatesToRss(const std::unordered_map<int,uint32_t> rates)43 void FrameRateReport::SendFrameRatesToRss(const std::unordered_map<int, uint32_t> rates)
44 {
45 if (rates.empty()) {
46 return;
47 }
48 #ifdef RES_SCHED_ENABLE
49 std::unordered_map<std::string, std::string> mapPayload;
50 for (auto it = rates.begin(); it != rates.end(); ++it) {
51 mapPayload[std::to_string(it->first)] = std::to_string(it->second);
52 }
53 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(
54 OHOS::ResourceSchedule::ResType::RES_TYPE_FRAME_RATE_REPORT, 0, mapPayload);
55 #endif
56 }
57
58 } // namespace FRAME_TRACE