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.datasources.utils.monitorconfig.entity; 17 18 /** 19 * Config Struct 20 * 21 * @since 2021/11/02 22 */ 23 public class ConfigInfo { 24 private static final ConfigInfo CONFIG_INFO = new ConfigInfo(); 25 26 private PerfConfig perfConfig; 27 private AppTraceConfig appTraceConfig; 28 private NativeHookConfigInfo nativeHookConfigInfo; 29 30 /** 31 * single instance 32 * 33 * @return this 34 */ getInstance()35 public static ConfigInfo getInstance() { 36 return ConfigInfo.CONFIG_INFO; 37 } 38 39 /** 40 * get Perf config 41 * 42 * @param isLeakOhos isLeakOhos 43 * @return perf config struct 44 */ getPerfConfig(boolean isLeakOhos)45 public PerfConfig getPerfConfig(boolean isLeakOhos) { 46 if (perfConfig == null) { 47 restorePerfDefault(isLeakOhos); 48 } 49 return perfConfig; 50 } 51 52 /** 53 * set perfConfig 54 * 55 * @param perfConfig perf config struct 56 */ setPerfConfig(PerfConfig perfConfig)57 public void setPerfConfig(PerfConfig perfConfig) { 58 this.perfConfig = perfConfig; 59 } 60 61 /** 62 * init struct 63 * 64 * @param isLeakOhos isLeakOhos 65 * @return new PerfConfig 66 */ restorePerfDefault(boolean isLeakOhos)67 public PerfConfig restorePerfDefault(boolean isLeakOhos) { 68 PerfConfig config = new PerfConfig(); 69 if (isLeakOhos) { 70 config.setCallStack(PerfConfig.CallStack.DWARF.getIndex()); 71 config.setOffCpu(true); 72 } else { 73 config.setCallStack(PerfConfig.CallStack.NONE.getIndex()); 74 config.setOffCpu(false); 75 } 76 setPerfConfig(config); 77 return perfConfig; 78 } 79 80 /** 81 * restoreAppTraceDefault 82 * 83 * @return AppTraceConfig 84 */ restoreAppTraceDefault()85 public AppTraceConfig restoreAppTraceDefault() { 86 setAppTraceConfig(new AppTraceConfig()); 87 return appTraceConfig; 88 } 89 90 /** 91 * getAppTraceConfig 92 * 93 * @return appTraceConfig 94 */ getAppTraceConfig()95 public AppTraceConfig getAppTraceConfig() { 96 if (appTraceConfig == null) { 97 appTraceConfig = restoreAppTraceDefault(); 98 } 99 return appTraceConfig; 100 } 101 102 /** 103 * setAppTraceConfig 104 * 105 * @param appTraceConfig appTraceConfig 106 */ setAppTraceConfig(AppTraceConfig appTraceConfig)107 public void setAppTraceConfig(AppTraceConfig appTraceConfig) { 108 this.appTraceConfig = appTraceConfig; 109 } 110 111 /** 112 * restoreNativeHookConfigInfoDefault 113 * 114 * @return NativeHookConfigInfo 115 */ restoreNativeHookConfigInfoDefault()116 public NativeHookConfigInfo restoreNativeHookConfigInfoDefault() { 117 setNativeHookConfigInfo(new NativeHookConfigInfo()); 118 return nativeHookConfigInfo; 119 } 120 121 /** 122 * getAppTraceConfig 123 * 124 * @return appTraceConfig 125 */ getNativeHookConfigInfo()126 public NativeHookConfigInfo getNativeHookConfigInfo() { 127 if (nativeHookConfigInfo == null) { 128 nativeHookConfigInfo = restoreNativeHookConfigInfoDefault(); 129 } 130 return nativeHookConfigInfo; 131 } 132 133 /** 134 * setNativeHookInfoConfig 135 * 136 * @param nativeHookConfigInfo nativeHookConfigInfo 137 */ setNativeHookConfigInfo(NativeHookConfigInfo nativeHookConfigInfo)138 public void setNativeHookConfigInfo(NativeHookConfigInfo nativeHookConfigInfo) { 139 this.nativeHookConfigInfo = nativeHookConfigInfo; 140 } 141 } 142