• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "soc_perf_client_adapter_impl.h"
17 
18 #include "nweb_log.h"
19 #if defined(NWEB_SOC_PERF)
20 #include "res_sched_client.h"
21 #include "res_type.h"
22 #include "socperf_client.h"
23 #endif
24 
25 namespace OHOS::NWeb {
26 namespace {
27 #if defined(NWEB_SOC_PERF)
28     const int32_t SOC_PERF_WEB_DRAG_RESIZE_ID = 10073;
29     const uint32_t SOC_PERF_INVALID = UINT32_MAX;
30 #endif
31 }
32 
SocPerfClientAdapterImpl()33 SocPerfClientAdapterImpl::SocPerfClientAdapterImpl()
34 {
35 #if defined(NWEB_SOC_PERF)
36     convertMap_ = {
37         { SOC_PERF_WEB_GESTURE_ID, ResourceSchedule::ResType::RES_TYPE_WEB_GESTURE },
38         { SOC_PERF_WEB_GESTURE_MOVE_ID, ResourceSchedule::ResType::RES_TYPE_WEB_GESTURE_MOVE },
39         { SOC_PERF_SLIDE_NORMAL_ID, ResourceSchedule::ResType::RES_TYPE_WEB_SLIDE_NORMAL },
40         { SOC_PERF_LOAD_URL_ID, ResourceSchedule::ResType::RES_TYPE_LOAD_URL },
41         { SOC_PERF_MOUSEWHEEL_ID, ResourceSchedule::ResType::RES_TYPE_MOUSEWHEEL },
42         { SOC_PERF_WEB_DRAG_RESIZE_ID, ResourceSchedule::ResType::RES_TYPE_WEB_DRAG_RESIZE },
43     };
44 #endif
45 }
46 
~SocPerfClientAdapterImpl()47 SocPerfClientAdapterImpl::~SocPerfClientAdapterImpl()
48 {
49     convertMap_.clear();
50 }
51 
ApplySocPerfConfigById(int32_t id)52 void SocPerfClientAdapterImpl::ApplySocPerfConfigById(int32_t id)
53 {
54 #if defined(NWEB_SOC_PERF)
55     uint32_t resType = ConvertId(id);
56     if (resType == SOC_PERF_INVALID) {
57         return;
58     }
59 
60     std::unordered_map<std::string, std::string> mapPayload;
61     OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, SOC_PERF_START, mapPayload);
62 #endif
63 }
64 
ApplySocPerfConfigByIdEx(int32_t id,bool onOffTag)65 void SocPerfClientAdapterImpl::ApplySocPerfConfigByIdEx(int32_t id, bool onOffTag)
66 {
67 #if defined(NWEB_SOC_PERF)
68     uint32_t resType = ConvertId(id);
69     if (resType == SOC_PERF_INVALID) {
70         return;
71     }
72 
73     std::unordered_map<std::string, std::string> mapPayload;
74     int64_t value = onOffTag ? SOC_PERF_START : SOC_PERF_END;
75     OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, value, mapPayload);
76 #endif
77 }
78 
ConvertId(int32_t id)79 uint32_t SocPerfClientAdapterImpl::ConvertId(int32_t id)
80 {
81 #if defined(NWEB_SOC_PERF)
82     auto mit = convertMap_.find(id);
83     if (mit == convertMap_.end()) {
84         WVLOG_E("invalid id: %{public}d", id);
85         return SOC_PERF_INVALID;
86     }
87     return mit->second;
88 #else
89     return 0;
90 #endif
91 }
92 }  // namespace OHOS::NWeb
93