• 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 "socperf_server.h"
17 
18 namespace OHOS {
19 namespace SOCPERF {
20 const bool REGISTER_RESULT =
21     SystemAbility::MakeAndRegisterAbility(DelayedSingleton<SocPerfServer>::GetInstance().get());
22 
SocPerfServer()23 SocPerfServer::SocPerfServer() : SystemAbility(SOC_PERF_SERVICE_SA_ID, true)
24 {
25 }
26 
~SocPerfServer()27 SocPerfServer::~SocPerfServer()
28 {
29 }
30 
OnStart()31 void SocPerfServer::OnStart()
32 {
33     if (!Publish(DelayedSingleton<SocPerfServer>::GetInstance().get())) {
34         SOC_PERF_LOGE("%{public}s, Register SystemAbility for SocPerf FAILED.", __func__);
35         return;
36     }
37     if (!socPerf.Init()) {
38         SOC_PERF_LOGE("%{public}s, SocPerf Init FAILED", __func__);
39         return;
40     }
41 }
42 
OnStop()43 void SocPerfServer::OnStop()
44 {
45 }
46 
Dump(int32_t fd,const std::vector<std::u16string> & args)47 int32_t SocPerfServer::Dump(int32_t fd, const std::vector<std::u16string>& args)
48 {
49     std::vector<std::string> argsInStr;
50     std::transform(args.begin(), args.end(), std::back_inserter(argsInStr),
51         [](const std::u16string &arg) {
52         return Str16ToStr8(arg);
53     });
54     std::string result;
55     result.append("usage: soc_perf service dump [<options>]\n")
56         .append("    1. PerfRequest(cmdId, msg)\n")
57         .append("    2. PerfRequestEx(cmdId, onOffTag, msg)\n")
58         .append("    3. LimitRequest(clientId, tags, configs, msg)\n")
59         .append("    -h: show the help.\n")
60         .append("    -a: show all info.\n");
61     if (!SaveStringToFd(fd, result)) {
62         SOC_PERF_LOGE("%{public}s, Dump FAILED", __func__);
63     }
64     return ERR_OK;
65 }
66 
PerfRequest(int32_t cmdId,const std::string & msg)67 void SocPerfServer::PerfRequest(int32_t cmdId, const std::string& msg)
68 {
69     socPerf.PerfRequest(cmdId, msg);
70 }
71 
PerfRequestEx(int32_t cmdId,bool onOffTag,const std::string & msg)72 void SocPerfServer::PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg)
73 {
74     socPerf.PerfRequestEx(cmdId, onOffTag, msg);
75 }
76 
PowerLimitBoost(bool onOffTag,const std::string & msg)77 void SocPerfServer::PowerLimitBoost(bool onOffTag, const std::string& msg)
78 {
79     socPerf.PowerLimitBoost(onOffTag, msg);
80 }
81 
ThermalLimitBoost(bool onOffTag,const std::string & msg)82 void SocPerfServer::ThermalLimitBoost(bool onOffTag, const std::string& msg)
83 {
84     socPerf.ThermalLimitBoost(onOffTag, msg);
85 }
86 
LimitRequest(int32_t clientId,const std::vector<int32_t> & tags,const std::vector<int64_t> & configs,const std::string & msg)87 void SocPerfServer::LimitRequest(int32_t clientId,
88     const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg)
89 {
90     socPerf.LimitRequest(clientId, tags, configs, msg);
91 }
92 } // namespace SOCPERF
93 } // namespace OHOS
94