• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 package ohos.devtools.pluginconfig;
17 
18 import com.google.protobuf.ByteString;
19 
20 import model.AbstractSdk;
21 import ohos.devtools.datasources.utils.datahandler.datapoller.UserDataConsumer;
22 import ohos.devtools.datasources.utils.plugin.IPluginConfig;
23 import ohos.devtools.datasources.utils.plugin.entity.AnalysisType;
24 import ohos.devtools.datasources.utils.plugin.entity.DPlugin;
25 import ohos.devtools.datasources.utils.plugin.entity.HiProfilerPluginConfig;
26 import ohos.devtools.datasources.utils.plugin.entity.PluginConf;
27 import ohos.devtools.datasources.utils.plugin.entity.PluginMode;
28 import ohos.devtools.datasources.utils.profilerlog.ProfilerLogManager;
29 import ohos.devtools.views.layout.chartview.ProfilerMonitorItem;
30 import ohos.devtools.views.layout.chartview.user.UserItemView;
31 import ohos.devtools.views.user.UserManager;
32 import org.apache.logging.log4j.LogManager;
33 import org.apache.logging.log4j.Logger;
34 
35 import java.util.Optional;
36 
37 /**
38  * Sdk Config
39  *
40  * @since 2021/11/25
41  */
42 @DPlugin
43 public class UserConfig extends IPluginConfig {
44     private static final Logger LOGGER = LogManager.getLogger(UserConfig.class);
45     private static final String BASEPATH = "/data/local/tmp/";
46 
47     /**
48      * createConfig
49      *
50      * @return PluginConf
51      */
52     @Override
createConfig()53     public PluginConf createConfig() {
54         if (ProfilerLogManager.isInfoEnabled()) {
55             LOGGER.info("createConfig");
56         }
57         UserManager management = UserManager.getInstance();
58         Optional<AbstractSdk> abstractSdk = management.getSdkImpl();
59         AbstractSdk sdkImpl = abstractSdk.get();
60         ProfilerMonitorItem sdkItem = new ProfilerMonitorItem(20, sdkImpl.getTitleName(), UserItemView.class);
61         String path = sdkImpl.getPluginFileName();
62         if (!path.contains(BASEPATH)) {
63             path = BASEPATH + sdkImpl.getPluginFileName();
64         }
65         PluginConf sdkConf = new PluginConf(path, sdkImpl.getPluginDataName(), UserDataConsumer.class, true, sdkItem);
66         sdkConf.setICreatePluginConfig((deviceIPPortInfo, processInfo) -> {
67             ByteString pluginByteString = sdkImpl.getPluginByteString(processInfo.getProcessId());
68             return new HiProfilerPluginConfig(40, pluginByteString);
69         });
70         sdkConf.setPluginMode(PluginMode.ONLINE);
71         sdkConf.addAnalysisTypes(AnalysisType.APPLICATION_TYPE);
72         return sdkConf;
73     }
74 }
75