• 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 ohos.devtools.datasources.transport.grpc.service.NativeHookConfigOuterClass;
19 import ohos.devtools.datasources.utils.monitorconfig.entity.ConfigInfo;
20 import ohos.devtools.datasources.utils.monitorconfig.entity.NativeHookConfigInfo;
21 import ohos.devtools.datasources.utils.plugin.IPluginConfig;
22 import ohos.devtools.datasources.utils.plugin.entity.AnalysisType;
23 import ohos.devtools.datasources.utils.plugin.entity.DPlugin;
24 import ohos.devtools.datasources.utils.plugin.entity.HiProfilerPluginConfig;
25 import ohos.devtools.datasources.utils.plugin.entity.PluginBufferConfig;
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 org.apache.logging.log4j.LogManager;
30 import org.apache.logging.log4j.Logger;
31 
32 import static ohos.devtools.datasources.utils.device.entity.DeviceType.LEAN_HOS_DEVICE;
33 
34 /**
35  * AgentConfig
36  *
37  * @since 2021/11/22
38  */
39 @DPlugin
40 public class NativeConfig extends IPluginConfig {
41     /**
42      * NATIVE_HOOK_PLUGIN_NAME
43      */
44     public static final String NATIVE_HOOK_PLUGIN_NAME = "/data/local/data/libnative_hook.z.so";
45     private static final Logger LOGGER = LogManager.getLogger(NativeConfig.class);
46 
47     @Override
createConfig()48     public PluginConf createConfig() {
49         if (ProfilerLogManager.isInfoEnabled()) {
50             LOGGER.info("createConfig");
51         }
52         PluginConf nativeConfig =
53             new PluginConf(NATIVE_HOOK_PLUGIN_NAME, "hookdaemon", null, false, null);
54         nativeConfig.setICreatePluginConfig((deviceIPPortInfo, processInfo) -> {
55             NativeHookConfigInfo nativeHookConfigInfo = ConfigInfo.getInstance().getNativeHookConfigInfo();
56             String fileName = "/data/local/tmp/" + processInfo.getProcessId() + ".nativeHeap";
57             NativeHookConfigOuterClass.NativeHookConfig nativeHookConfig = NativeHookConfigOuterClass.NativeHookConfig
58                 .newBuilder().setPid(processInfo.getProcessId()).setSaveFile(true)
59                 .setFileName(fileName).setFilterSize(nativeHookConfigInfo.getFilterSizeValue())
60                 .setSmbPages(nativeHookConfigInfo.getSharedMemorySizeValue())
61                 .setMaxStackDepth(nativeHookConfigInfo.getUnwind()).build();
62             LOGGER.error("nativeHookConfig {}", nativeHookConfig.toString());
63             return new HiProfilerPluginConfig(40, nativeHookConfig.toByteString());
64         });
65         nativeConfig.setPluginBufferConfig(new PluginBufferConfig(3000, PluginBufferConfig.Policy.RECYCLE));
66         nativeConfig.setOperationStart(true);
67         nativeConfig.setPluginMode(PluginMode.ONLINE);
68         nativeConfig.addSupportDeviceTypes(LEAN_HOS_DEVICE);
69         nativeConfig.addAnalysisTypes(AnalysisType.APPLICATION_TYPE);
70         return nativeConfig;
71     }
72 }
73