1 /*
2 * Copyright (C) 2025 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 "AI_schedule.h"
16
17 #include <string>
18 #include <map>
19 #include <service_plugin.h>
20 #include <sp_log.h>
21 #include <dlfcn.h>
22
23 namespace OHOS {
24 namespace SmartPerf {
ItemData()25 std::map<std::string, std::string> AISchedule::ItemData()
26 {
27 if (processId.empty()) {
28 WLOGE("AISchedule need processId.");
29 return std::map<std::string, std::string>();
30 }
31 aiScheduleParams[aiScheduleParamPid] = processId;
32 aiScheduleParams[aiScheduleParamType] = "1";
33 ServicePluginHandler &servicePluginHandler = ServicePluginHandler::GetInstance();
34
35 void* handle = servicePluginHandler.GetSoHandler(ServicePluginHandler::ServicePluginType::GAME_PLUGIN);
36 if (handle == nullptr) {
37 WLOGE("Get service plugin handler failed.");
38 return std::map<std::string, std::string>();
39 }
40
41 typedef GameServicePlugin *(*GetServicePlugin)();
42 GetServicePlugin servicePlugin = (GetServicePlugin)dlsym(handle, createPlugin.c_str());
43 if (!servicePlugin) {
44 WLOGE("GameServicePlugin Error loading symbol");
45 return std::map<std::string, std::string>();
46 }
47 return servicePlugin()->GetSystemFunctionStatus(aiScheduleParams);
48 }
49
SetProcessId(const std::string & pid)50 void AISchedule::SetProcessId(const std::string &pid)
51 {
52 processId = pid;
53 }
54 } // namespace SmartPerf
55 } // namespace OHOS