1 /*
2 * Copyright (c) 2022-2023 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
17 #include <cstdint> // for int32_t
18 #include <cstdlib> // for atoi
19 #include <vector> // for vector
20 #include <cstring> // for strcmp
21 #include "socperf_client.h" // for SocPerfClient
22
23 const static int32_t PARAMETERS_NUM_MIN = 2;
24 const static int32_t PARAMETERS_NUM_WITHOUT_EX = 3;
25 const static int32_t PARAMETERS_NUM_WITH_EX = 4;
26 const static int32_t PARAMETERS_NUM_LIMIT = 5;
27
PerfRequest(int32_t argc,char * argv[])28 static void PerfRequest(int32_t argc, char *argv[])
29 {
30 if (argc == PARAMETERS_NUM_WITHOUT_EX) {
31 char* cmdId = argv[2];
32 if (cmdId) {
33 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequest(atoi(cmdId), "");
34 }
35 }
36 }
37
PerfRequestEx(int32_t argc,char * argv[])38 static void PerfRequestEx(int32_t argc, char *argv[])
39 {
40 if (argc == PARAMETERS_NUM_WITH_EX) {
41 char* cmdId = argv[2];
42 char* onOffTag = argv[3];
43 if (cmdId && onOffTag) {
44 if (strcmp(onOffTag, "true") == 0) {
45 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(atoi(cmdId), true, "");
46 } else if (strcmp(onOffTag, "false") == 0) {
47 OHOS::SOCPERF::SocPerfClient::GetInstance().PerfRequestEx(atoi(cmdId), false, "");
48 }
49 }
50 }
51 }
52
PowerLimitBoost(int32_t argc,char * argv[])53 static void PowerLimitBoost(int32_t argc, char *argv[])
54 {
55 if (argc == PARAMETERS_NUM_WITHOUT_EX) {
56 char* onOffTag = argv[2];
57 if (onOffTag) {
58 if (strcmp(onOffTag, "true") == 0) {
59 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(true, "");
60 } else if (strcmp(onOffTag, "false") == 0) {
61 OHOS::SOCPERF::SocPerfClient::GetInstance().PowerLimitBoost(false, "");
62 }
63 }
64 }
65 }
66
ThermalLimitBoost(int32_t argc,char * argv[])67 static void ThermalLimitBoost(int32_t argc, char *argv[])
68 {
69 if (argc == PARAMETERS_NUM_WITHOUT_EX) {
70 char* onOffTag = argv[2];
71 if (onOffTag) {
72 if (strcmp(onOffTag, "true") == 0) {
73 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(true, "");
74 } else if (strcmp(onOffTag, "false") == 0) {
75 OHOS::SOCPERF::SocPerfClient::GetInstance().ThermalLimitBoost(false, "");
76 }
77 }
78 }
79 }
80
LimitRequest(int32_t argc,char * argv[])81 static void LimitRequest(int32_t argc, char *argv[])
82 {
83 if (argc == PARAMETERS_NUM_LIMIT) {
84 char* clientId = argv[2];
85 char* tags = argv[3];
86 char* configs = argv[4];
87 std::vector<int32_t> tagsVector = { atoi(tags) };
88 std::vector<int64_t> configsVector = { atoll(configs) };
89 OHOS::SOCPERF::SocPerfClient::GetInstance().LimitRequest(atoi(clientId), tagsVector, configsVector, "");
90 }
91 }
92
main(int32_t argc,char * argv[])93 int32_t main(int32_t argc, char *argv[])
94 {
95 if (argc >= PARAMETERS_NUM_MIN && argv) {
96 char* function = argv[1];
97 if (strcmp(function, "PerfRequest") == 0) {
98 PerfRequest(argc, argv);
99 } else if (strcmp(function, "PerfRequestEx") == 0) {
100 PerfRequestEx(argc, argv);
101 } else if (strcmp(function, "PowerLimitBoost") == 0) {
102 PowerLimitBoost(argc, argv);
103 } else if (strcmp(function, "ThermalLimitBoost") == 0) {
104 ThermalLimitBoost(argc, argv);
105 } else if (strcmp(function, "LimitRequest") == 0) {
106 LimitRequest(argc, argv);
107 }
108 }
109 return 0;
110 }
111