• 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_GESTURE_ID = 10012;
29     const int32_t SOC_PERF_WEB_GESTURE_MOVE_ID = 10020;
30     const int32_t SOC_PERF_SLIDE_NORMAL_ID = 10025;
31     const int32_t SOC_PERF_LOAD_URL_ID = 10070;
32     const int32_t SOC_PERF_MOUSEWHEEL_ID = 10071;
33 
34     const int64_t SOC_PERF_START = 0;
35     const int64_t SOC_PERF_END = 1;
36 
37     const uint32_t SOC_PERF_INVALID = UINT32_MAX;
38 #endif
39 }
40 
SocPerfClientAdapterImpl()41 SocPerfClientAdapterImpl::SocPerfClientAdapterImpl()
42 {
43 #if defined(NWEB_SOC_PERF)
44     convertMap_ = {
45         { SOC_PERF_WEB_GESTURE_ID, ResourceSchedule::ResType::RES_TYPE_WEB_GESTURE },
46         { SOC_PERF_WEB_GESTURE_MOVE_ID, ResourceSchedule::ResType::RES_TYPE_WEB_GESTURE_MOVE },
47         { SOC_PERF_SLIDE_NORMAL_ID, ResourceSchedule::ResType::RES_TYPE_WEB_SLIDE_NORMAL },
48         { SOC_PERF_LOAD_URL_ID, ResourceSchedule::ResType::RES_TYPE_LOAD_URL },
49         { SOC_PERF_MOUSEWHEEL_ID, ResourceSchedule::ResType::RES_TYPE_MOUSEWHEEL },
50     };
51 #endif
52 }
53 
~SocPerfClientAdapterImpl()54 SocPerfClientAdapterImpl::~SocPerfClientAdapterImpl()
55 {
56     convertMap_.clear();
57 }
58 
ApplySocPerfConfigById(int32_t id)59 void SocPerfClientAdapterImpl::ApplySocPerfConfigById(int32_t id)
60 {
61 #if defined(NWEB_SOC_PERF)
62     uint32_t resType = ConvertId(id);
63     if (resType == SOC_PERF_INVALID) {
64         return;
65     }
66 
67     std::unordered_map<std::string, std::string> mapPayload;
68     OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, SOC_PERF_START, mapPayload);
69 #endif
70 }
71 
ApplySocPerfConfigByIdEx(int32_t id,bool onOffTag)72 void SocPerfClientAdapterImpl::ApplySocPerfConfigByIdEx(int32_t id, bool onOffTag)
73 {
74 #if defined(NWEB_SOC_PERF)
75     uint32_t resType = ConvertId(id);
76     if (resType == SOC_PERF_INVALID) {
77         return;
78     }
79 
80     std::unordered_map<std::string, std::string> mapPayload;
81     int64_t value = onOffTag ? SOC_PERF_START : SOC_PERF_END;
82     OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, value, mapPayload);
83 #endif
84 }
85 
ConvertId(int32_t id)86 uint32_t SocPerfClientAdapterImpl::ConvertId(int32_t id)
87 {
88 #if defined(NWEB_SOC_PERF)
89     auto mit = convertMap_.find(id);
90     if (mit == convertMap_.end()) {
91         WVLOG_E("invalid id: %{public}d", id);
92         return SOC_PERF_INVALID;
93     }
94     return mit->second;
95 #else
96     return 0;
97 #endif
98 }
99 }  // namespace OHOS::NWeb
100