当前位置:   article > 正文

jmeter5.6.3源码解析_jmeter 源码分析

jmeter 源码分析

JMeter是一款开源的Java应用,用于进行性能测试和功能测试。它允许用户创建测试计划,模拟多个用户并发地访问应用程序,以测量应用程序的性能。JMeter的源码结构相当复杂,但以下是对其核心部分的简要解析:

1.入口类:NewDriver

  • NewDriver是整个JMeter的入口类,它的主要任务是启动JMeter测试。
  • 该类包含了一些静态方法,如jar包的扫描、命令解析、全局参数定义以及类加载器路径操作等。
  • 最重要的是它的main方法,该方法通过反射调用JMeter类,并启动其start方法。根据传入的参数,main方法会判断执行GUI模式还是NON_GUI模式。官方日志特别强调,若要执行发压工作,应使用命令行模式,因为这会影响发压效率和资源消耗。
    1. /*
    2. * Licensed to the Apache Software Foundation (ASF) under one or more
    3. * contributor license agreements. See the NOTICE file distributed with
    4. * this work for additional information regarding copyright ownership.
    5. * The ASF licenses this file to you under the Apache License, Version 2.0
    6. * (the "License"); you may not use this file except in compliance with
    7. * the License. You may obtain a copy of the License at
    8. *
    9. * http://www.apache.org/licenses/LICENSE-2.0
    10. *
    11. * Unless required by applicable law or agreed to in writing, software
    12. * distributed under the License is distributed on an "AS IS" BASIS,
    13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. * See the License for the specific language governing permissions and
    15. * limitations under the License.
    16. */
    17. package org.apache.jmeter;
    18. // N.B. this must only use standard Java packages
    19. import java.io.File;
    20. import java.io.IOException;
    21. import java.io.PrintWriter;
    22. import java.io.StringWriter;
    23. import java.lang.reflect.Method;
    24. import java.net.MalformedURLException;
    25. import java.net.URL;
    26. import java.time.Instant;
    27. import java.time.ZoneId;
    28. import java.time.format.DateTimeFormatter;
    29. import java.util.ArrayList;
    30. import java.util.Arrays;
    31. import java.util.List;
    32. import java.util.StringTokenizer;
    33. /**
    34. * Main class for JMeter - sets up initial classpath and the loader.
    35. *
    36. */
    37. public final class NewDriver {
    38. private static final String CLASSPATH_SEPARATOR = File.pathSeparator;
    39. private static final String OS_NAME = System.getProperty("os.name");// $NON-NLS-1$
    40. private static final String OS_NAME_LC = OS_NAME.toLowerCase(java.util.Locale.ENGLISH);
    41. private static final String JAVA_CLASS_PATH = "java.class.path";// $NON-NLS-1$
    42. private static final String JMETER_LOGFILE_SYSTEM_PROPERTY = "jmeter.logfile";// $NON-NLS-1$
    43. private static final String HEADLESS_MODE_PROPERTY = "java.awt.headless";// $NON-NLS-1$
    44. /** The class loader to use for loading JMeter classes. */
    45. private static final DynamicClassLoader loader;
    46. /** The directory JMeter is installed in. */
    47. private static final String JMETER_INSTALLATION_DIRECTORY;
    48. private static final List<Exception> EXCEPTIONS_IN_INIT = new ArrayList<>();
    49. static {
    50. final List<URL> jars = new ArrayList<>();
    51. final String initiaClasspath = System.getProperty(JAVA_CLASS_PATH);
    52. // Find JMeter home dir from the initial classpath
    53. String tmpDir;
    54. StringTokenizer tok = new StringTokenizer(initiaClasspath, File.pathSeparator);
    55. if (tok.countTokens() == 1
    56. || (tok.countTokens() == 2 // Java on Mac OS can add a second entry to the initial classpath
    57. && OS_NAME_LC.startsWith("mac os x")// $NON-NLS-1$
    58. )
    59. ) {
    60. File jar = new File(tok.nextToken());
    61. try {
    62. tmpDir = jar.getCanonicalFile().getParentFile().getParent();
    63. } catch (IOException e) {
    64. tmpDir = null;
    65. }
    66. } else {// e.g. started from IDE with full classpath
    67. tmpDir = System.getProperty("jmeter.home", System.getenv("JMETER_HOME"));// Allow override $NON-NLS-1$ $NON-NLS-2$
    68. if (tmpDir == null || tmpDir.length() == 0) {
    69. File userDir = new File(System.getProperty("user.dir"));// $NON-NLS-1$
    70. tmpDir = userDir.getAbsoluteFile().getParent();
    71. }
    72. }
    73. if (tmpDir == null) {
    74. tmpDir = System.getenv("JMETER_HOME");
    75. }
    76. JMETER_INSTALLATION_DIRECTORY=tmpDir;
    77. /*
    78. * Does the system support UNC paths? If so, may need to fix them up
    79. * later
    80. */
    81. boolean usesUNC = OS_NAME_LC.startsWith("windows");// $NON-NLS-1$
    82. // Add standard jar locations to initial classpath
    83. StringBuilder classpath = new StringBuilder();
    84. File[] libDirs = new File[] { new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib"),// $NON-NLS-1$ $NON-NLS-2$
    85. new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib" + File.separator + "ext"),// $NON-NLS-1$ $NON-NLS-2$
    86. new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib" + File.separator + "junit")};// $NON-NLS-1$ $NON-NLS-2$
    87. for (File libDir : libDirs) {
    88. File[] libJars = libDir.listFiles((dir, name) -> name.endsWith(".jar"));
    89. if (libJars == null) {
    90. new Throwable("Could not access " + libDir).printStackTrace(); // NOSONAR No logging here
    91. continue;
    92. }
    93. Arrays.sort(libJars); // Bug 50708 Ensure predictable order of jars
    94. for (File libJar : libJars) {
    95. try {
    96. String s = libJar.getPath();
    97. // Fix path to allow the use of UNC URLs
    98. if (usesUNC) {
    99. if (s.startsWith("\\\\") && !s.startsWith("\\\\\\")) {// $NON-NLS-1$ $NON-NLS-2$
    100. s = "\\\\" + s;// $NON-NLS-1$
    101. } else if (s.startsWith("//") && !s.startsWith("///")) {// $NON-NLS-1$ $NON-NLS-2$
    102. s = "//" + s;// $NON-NLS-1$
    103. }
    104. } // usesUNC
    105. jars.add(new File(s).toURI().toURL());// See Java bug 4496398
    106. classpath.append(CLASSPATH_SEPARATOR);
    107. classpath.append(s);
    108. } catch (MalformedURLException e) { // NOSONAR
    109. EXCEPTIONS_IN_INIT.add(new Exception("Error adding jar:"+libJar.getAbsolutePath(), e));
    110. }
    111. }
    112. }
    113. // ClassFinder needs the classpath
    114. System.setProperty(JAVA_CLASS_PATH, initiaClasspath + classpath.toString());
    115. loader = createClassLoader(jars);
    116. }
    117. @SuppressWarnings("removal")
    118. private static DynamicClassLoader createClassLoader(List<URL> jars) {
    119. return java.security.AccessController.doPrivileged(
    120. (java.security.PrivilegedAction<DynamicClassLoader>) () ->
    121. new DynamicClassLoader(jars.toArray(new URL[jars.size()]))
    122. );
    123. }
    124. /**
    125. * Prevent instantiation.
    126. */
    127. private NewDriver() {
    128. }
    129. /**
    130. * Generate an array of jar files located in a directory.
    131. * Jar files located in sub directories will not be added.
    132. *
    133. * @param dir to search for the jar files.
    134. */
    135. private static File[] listJars(File dir) {
    136. if (dir.isDirectory()) {
    137. return dir.listFiles((f, name) -> {
    138. if (name.endsWith(".jar")) {// $NON-NLS-1$
    139. File jar = new File(f, name);
    140. return jar.isFile() && jar.canRead();
    141. }
    142. return false;
    143. });
    144. }
    145. return new File[0];
    146. }
    147. /**
    148. * Add a URL to the loader classpath only; does not update the system classpath.
    149. *
    150. * @param path to be added.
    151. * @throws MalformedURLException when <code>path</code> points to an invalid url
    152. */
    153. public static void addURL(String path) throws MalformedURLException {
    154. File furl = new File(path);
    155. loader.addURL(furl.toURI().toURL()); // See Java bug 4496398
    156. File[] jars = listJars(furl);
    157. for (File jar : jars) {
    158. loader.addURL(jar.toURI().toURL()); // See Java bug 4496398
    159. }
    160. }
    161. /**
    162. * Add a URL to the loader classpath only; does not update the system
    163. * classpath.
    164. *
    165. * @param url
    166. * The {@link URL} to add to the classpath
    167. */
    168. public static void addURL(URL url) {
    169. loader.addURL(url);
    170. }
    171. /**
    172. * Add a directory or jar to the loader and system classpaths.
    173. *
    174. * @param path
    175. * to add to the loader and system classpath
    176. * @throws MalformedURLException
    177. * if <code>path</code> can not be transformed to a valid
    178. * {@link URL}
    179. */
    180. public static void addPath(String path) throws MalformedURLException {
    181. File file = new File(path);
    182. // Ensure that directory URLs end in "/"
    183. if (file.isDirectory() && !path.endsWith("/")) {// $NON-NLS-1$
    184. file = new File(path + "/");// $NON-NLS-1$
    185. }
    186. loader.addURL(file.toURI().toURL()); // See Java bug 4496398
    187. StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH));
    188. sb.append(CLASSPATH_SEPARATOR);
    189. sb.append(path);
    190. File[] jars = listJars(file);
    191. for (File jar : jars) {
    192. loader.addURL(jar.toURI().toURL()); // See Java bug 4496398
    193. sb.append(CLASSPATH_SEPARATOR);
    194. sb.append(jar.getPath());
    195. }
    196. // ClassFinder needs this
    197. System.setProperty(JAVA_CLASS_PATH,sb.toString());
    198. }
    199. /**
    200. * Get the directory where JMeter is installed. This is the absolute path
    201. * name.
    202. *
    203. * @return the directory where JMeter is installed.
    204. */
    205. public static String getJMeterDir() {
    206. return JMETER_INSTALLATION_DIRECTORY;
    207. }
    208. /**
    209. * The main program which actually runs JMeter.
    210. *
    211. * @param args
    212. * the command line arguments
    213. */
    214. public static void main(String[] args) {
    215. if(!EXCEPTIONS_IN_INIT.isEmpty()) {
    216. System.err.println("Configuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT)); // NOSONAR Intentional System.err use
    217. } else {
    218. Thread.currentThread().setContextClassLoader(loader);
    219. setLoggingProperties(args);
    220. try {
    221. // Only set property if it has not been set explicitely
    222. if(System.getProperty(HEADLESS_MODE_PROPERTY) == null && shouldBeHeadless(args)) {
    223. System.setProperty(HEADLESS_MODE_PROPERTY, "true");
    224. }
    225. Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$
    226. Object instance = initialClass.getDeclaredConstructor().newInstance();
    227. Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$
    228. startup.invoke(instance, new Object[] { args });
    229. } catch(Throwable e){ // NOSONAR We want to log home directory in case of exception
    230. e.printStackTrace(); // NOSONAR No logger at this step
    231. System.err.println("JMeter home directory was detected as: "+JMETER_INSTALLATION_DIRECTORY); // NOSONAR Intentional System.err use
    232. }
    233. }
    234. }
    235. /**
    236. * @param exceptionsInInit List of {@link Exception}
    237. * @return String
    238. */
    239. private static String exceptionsToString(List<? extends Exception> exceptionsInInit) {
    240. StringBuilder builder = new StringBuilder();
    241. for (Exception exception : exceptionsInInit) {
    242. StringWriter stringWriter = new StringWriter();
    243. PrintWriter printWriter = new PrintWriter(stringWriter);
    244. exception.printStackTrace(printWriter); // NOSONAR
    245. builder.append(stringWriter.toString())
    246. .append("\r\n");
    247. }
    248. return builder.toString();
    249. }
    250. /*
    251. * Set logging related system properties.
    252. */
    253. private static void setLoggingProperties(String[] args) {
    254. String jmLogFile = getCommandLineArgument(args, 'j', "jmeterlogfile");// $NON-NLS-1$ $NON-NLS-2$
    255. if (jmLogFile != null && !jmLogFile.isEmpty()) {
    256. jmLogFile = replaceDateFormatInFileName(jmLogFile);
    257. System.setProperty(JMETER_LOGFILE_SYSTEM_PROPERTY, jmLogFile);// $NON-NLS-1$
    258. } else if (System.getProperty(JMETER_LOGFILE_SYSTEM_PROPERTY) == null) {// $NON-NLS-1$
    259. System.setProperty(JMETER_LOGFILE_SYSTEM_PROPERTY, "jmeter.log");// $NON-NLS-1$ $NON-NLS-2$
    260. }
    261. String jmLogConf = getCommandLineArgument(args, 'i', "jmeterlogconf");// $NON-NLS-1$ $NON-NLS-2$
    262. File logConfFile = null;
    263. if (jmLogConf != null && !jmLogConf.isEmpty()) {
    264. logConfFile = new File(jmLogConf);
    265. } else if (System.getProperty("log4j.configurationFile") == null) {// $NON-NLS-1$
    266. logConfFile = new File("log4j2.xml");// $NON-NLS-1$
    267. if (!logConfFile.isFile()) {
    268. logConfFile = new File(JMETER_INSTALLATION_DIRECTORY, "bin" + File.separator + "log4j2.xml");// $NON-NLS-1$ $NON-NLS-2$
    269. }
    270. }
    271. if (logConfFile != null) {
    272. System.setProperty("log4j.configurationFile", logConfFile.toURI().toString());// $NON-NLS-1$
    273. }
    274. }
    275. private static boolean shouldBeHeadless(String[] args) {
    276. for (String arg : args) {
    277. if("-n".equals(arg) || "-s".equals(arg) || "-g".equals(arg)) {
    278. return true;
    279. }
    280. }
    281. return false;
    282. }
    283. /*
    284. * Find command line argument option value by the id and name.
    285. */
    286. private static String getCommandLineArgument(String[] args, int id, String name) {
    287. final String shortArgName = "-" + ((char) id);// $NON-NLS-1$
    288. final String longArgName = "--" + name;// $NON-NLS-1$
    289. String value = null;
    290. for (int i = 0; i < args.length; i++) {
    291. if ((shortArgName.equals(args[i]) && i < args.length - 1)
    292. || longArgName.equals(args[i])) {
    293. if (!args[i + 1].startsWith("-")) {// $NON-NLS-1$
    294. value = args[i + 1];
    295. }
    296. break;
    297. } else if (!shortArgName.equals(args[i]) && args[i].startsWith(shortArgName)) {
    298. value = args[i].substring(shortArgName.length());
    299. break;
    300. }
    301. }
    302. return value;
    303. }
    304. /*
    305. * If the fileName contains at least one set of paired single-quotes, reformat using DateFormat
    306. */
    307. private static String replaceDateFormatInFileName(String fileName) {
    308. try {
    309. StringBuilder builder = new StringBuilder();
    310. final Instant date = Instant.now();
    311. int fromIndex = 0;
    312. int begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
    313. int end;
    314. String format;
    315. DateTimeFormatter dateFormat;
    316. while (begin != -1) {
    317. builder.append(fileName.substring(fromIndex, begin));
    318. fromIndex = begin + 1;
    319. end = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
    320. if (end == -1) {
    321. throw new IllegalArgumentException("Invalid pairs of single-quotes in the file name: " + fileName);// $NON-NLS-1$
    322. }
    323. format = fileName.substring(begin + 1, end);
    324. dateFormat = DateTimeFormatter.ofPattern(format).withZone(ZoneId.systemDefault());
    325. builder.append(dateFormat.format(date));
    326. fromIndex = end + 1;
    327. begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
    328. }
    329. if (fromIndex < fileName.length() - 1) {
    330. builder.append(fileName.substring(fromIndex));
    331. }
    332. return builder.toString();
    333. } catch (Exception ex) {
    334. System.err.println("Error replacing date format in file name:"+fileName+", error:"+ex.getMessage()); // NOSONAR
    335. }
    336. return fileName;
    337. }
    338. }

2. 业务逻辑类:JMeter

  • JMeter类由NewDriver入口类通过反射调用,是实际的业务逻辑类。
  • 它负责接收用户的启动参数并进行解析。
  • 启动BeanShell服务。
  • JMeter类的start方法是其重点部分,因为它负责解析传入的指令,并对后续应用模式进行逻辑判断。如果未配置远程参数,启动类StandardJMeterEngine的runTest(); 如果已配置远程参数,启动远程类DistributedRunner的start(),此处最终仍然调用 StandardJMeterEngine的runTest();
    1. /*
    2. * Licensed to the Apache Software Foundation (ASF) under one or more
    3. * contributor license agreements. See the NOTICE file distributed with
    4. * this work for additional information regarding copyright ownership.
    5. * The ASF licenses this file to you under the Apache License, Version 2.0
    6. * (the "License"); you may not use this file except in compliance with
    7. * the License. You may obtain a copy of the License at
    8. *
    9. * http://www.apache.org/licenses/LICENSE-2.0
    10. *
    11. * Unless required by applicable law or agreed to in writing, software
    12. * distributed under the License is distributed on an "AS IS" BASIS,
    13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. * See the License for the specific language governing permissions and
    15. * limitations under the License.
    16. */
    17. package org.apache.jmeter;
    18. import java.io.File;
    19. import java.io.FileInputStream;
    20. import java.io.FileNotFoundException;
    21. import java.io.IOException;
    22. import java.io.InputStream;
    23. import java.io.Reader;
    24. import java.net.Authenticator;
    25. import java.net.DatagramPacket;
    26. import java.net.DatagramSocket;
    27. import java.net.InetAddress;
    28. import java.net.MalformedURLException;
    29. import java.net.SocketException;
    30. import java.nio.charset.StandardCharsets;
    31. import java.nio.file.Files;
    32. import java.time.Instant;
    33. import java.time.ZoneId;
    34. import java.time.format.DateTimeFormatter;
    35. import java.time.format.FormatStyle;
    36. import java.util.ArrayList;
    37. import java.util.Collection;
    38. import java.util.Enumeration;
    39. import java.util.List;
    40. import java.util.Locale;
    41. import java.util.Map;
    42. import java.util.Properties;
    43. import java.util.StringTokenizer;
    44. import java.util.concurrent.ConcurrentLinkedQueue;
    45. import java.util.concurrent.TimeUnit;
    46. import java.util.concurrent.atomic.AtomicInteger;
    47. import java.util.stream.Collectors;
    48. import javax.script.Bindings;
    49. import javax.script.ScriptEngine;
    50. import javax.script.ScriptEngineFactory;
    51. import javax.script.ScriptEngineManager;
    52. import javax.script.ScriptException;
    53. import org.apache.commons.cli.avalon.CLArgsParser;
    54. import org.apache.commons.cli.avalon.CLOption;
    55. import org.apache.commons.cli.avalon.CLOptionDescriptor;
    56. import org.apache.commons.cli.avalon.CLUtil;
    57. import org.apache.commons.io.FilenameUtils;
    58. import org.apache.commons.io.IOUtils;
    59. import org.apache.commons.lang3.StringUtils;
    60. import org.apache.jmeter.control.ReplaceableController;
    61. import org.apache.jmeter.engine.ClientJMeterEngine;
    62. import org.apache.jmeter.engine.DistributedRunner;
    63. import org.apache.jmeter.engine.JMeterEngine;
    64. import org.apache.jmeter.engine.RemoteJMeterEngineImpl;
    65. import org.apache.jmeter.engine.StandardJMeterEngine;
    66. import org.apache.jmeter.engine.TreeCloner;
    67. import org.apache.jmeter.exceptions.IllegalUserActionException;
    68. import org.apache.jmeter.gui.action.LoadRecentProject;
    69. import org.apache.jmeter.gui.tree.JMeterTreeModel;
    70. import org.apache.jmeter.gui.tree.JMeterTreeNode;
    71. import org.apache.jmeter.plugin.JMeterPlugin;
    72. import org.apache.jmeter.plugin.PluginManager;
    73. import org.apache.jmeter.report.config.ConfigurationException;
    74. import org.apache.jmeter.report.dashboard.ReportGenerator;
    75. import org.apache.jmeter.reporters.ResultCollector;
    76. import org.apache.jmeter.reporters.Summariser;
    77. import org.apache.jmeter.rmi.RmiUtils;
    78. import org.apache.jmeter.samplers.Remoteable;
    79. import org.apache.jmeter.samplers.SampleEvent;
    80. import org.apache.jmeter.save.SaveService;
    81. import org.apache.jmeter.services.FileServer;
    82. import org.apache.jmeter.testelement.TestElement;
    83. import org.apache.jmeter.testelement.TestElementSchema;
    84. import org.apache.jmeter.testelement.TestStateListener;
    85. import org.apache.jmeter.threads.RemoteThreadsListenerTestElement;
    86. import org.apache.jmeter.util.BeanShellInterpreter;
    87. import org.apache.jmeter.util.BeanShellServer;
    88. import org.apache.jmeter.util.JMeterUtils;
    89. import org.apache.jmeter.util.SecurityProviderLoader;
    90. import org.apache.jmeter.util.ShutdownClient;
    91. import org.apache.jorphan.collections.HashTree;
    92. import org.apache.jorphan.collections.SearchByClass;
    93. import org.apache.jorphan.reflect.ClassTools;
    94. import org.apache.jorphan.util.HeapDumper;
    95. import org.apache.jorphan.util.JMeterException;
    96. import org.apache.jorphan.util.JOrphanUtils;
    97. import org.apache.jorphan.util.ThreadDumper;
    98. import org.apache.logging.log4j.Level;
    99. import org.apache.logging.log4j.core.config.Configurator;
    100. import org.slf4j.Logger;
    101. import org.slf4j.LoggerFactory;
    102. /**
    103. * Main JMeter class; processes options and starts the GUI, non-GUI or server as appropriate.
    104. */
    105. public class JMeter implements JMeterPlugin {
    106. private static final String JSR223_INIT_FILE = "jsr223.init.file";
    107. private static final Logger log = LoggerFactory.getLogger(JMeter.class);
    108. public static final int UDP_PORT_DEFAULT = ShutdownClient.UDP_PORT_DEFAULT;
    109. public static final String HTTP_PROXY_PASS = "http.proxyPass"; // $NON-NLS-1$
    110. public static final String HTTP_PROXY_USER = "http.proxyUser"; // $NON-NLS-1$
    111. public static final String JMETER_NON_GUI = "JMeter.NonGui"; // $NON-NLS-1$
    112. public static final String JMETER_REPORT_OUTPUT_DIR_PROPERTY =
    113. "jmeter.reportgenerator.outputdir"; //$NON-NLS-1$
    114. // Icons size in the JMeter tree
    115. public static final String TREE_ICON_SIZE = "jmeter.tree.icons.size"; //$NON-NLS-1$
    116. public static final String DEFAULT_TREE_ICON_SIZE = "19x19"; //$NON-NLS-1$
    117. protected static final String KEY_SIZE = "<SIZE>"; //$NON-NLS-1$
    118. // If the -t flag is to "LAST", then the last loaded file (if any) is used
    119. private static final String USE_LAST_JMX = "LAST";
    120. // If the -j or -l flag is set to LAST or LAST.log|LAST.jtl, then the last loaded file name is used to
    121. // generate the log file name by removing .JMX and replacing it with .log|.jtl
    122. private static final int PROXY_PASSWORD = 'a';// $NON-NLS-1$
    123. private static final int JMETER_HOME_OPT = 'd';// $NON-NLS-1$
    124. private static final int HELP_OPT = 'h';// $NON-NLS-1$
    125. private static final int OPTIONS_OPT = '?';// $NON-NLS-1$
    126. // logging configuration file
    127. private static final int JMLOGCONF_OPT = 'i';// $NON-NLS-1$
    128. // jmeter.log
    129. private static final int JMLOGFILE_OPT = 'j';// $NON-NLS-1$
    130. // sample result log file
    131. private static final int LOGFILE_OPT = 'l';// $NON-NLS-1$
    132. private static final int NONGUI_OPT = 'n';// $NON-NLS-1$
    133. private static final int PROPFILE_OPT = 'p';// $NON-NLS-1$
    134. private static final int PROPFILE2_OPT = 'q';// $NON-NLS-1$
    135. private static final int REMOTE_OPT = 'r';// $NON-NLS-1$
    136. private static final int SERVER_OPT = 's';// $NON-NLS-1$
    137. private static final int TESTFILE_OPT = 't';// $NON-NLS-1$
    138. private static final int PROXY_USERNAME = 'u';// $NON-NLS-1$
    139. private static final int VERSION_OPT = 'v';// $NON-NLS-1$
    140. private static final int REPORT_GENERATING_OPT = 'g';// $NON-NLS-1$
    141. private static final int REPORT_AT_END_OPT = 'e';// $NON-NLS-1$
    142. private static final int REPORT_OUTPUT_FOLDER_OPT = 'o';// $NON-NLS-1$
    143. private static final int FORCE_DELETE_RESULT_FILE = 'f';// $NON-NLS-1$
    144. private static final int SYSTEM_PROPERTY = 'D';// $NON-NLS-1$
    145. private static final int JMETER_GLOBAL_PROP = 'G';// $NON-NLS-1$
    146. private static final int PROXY_SCHEME = 'E';// $NON-NLS-1$
    147. private static final int PROXY_HOST = 'H';// $NON-NLS-1$
    148. private static final int JMETER_PROPERTY = 'J';// $NON-NLS-1$
    149. private static final int LOGLEVEL = 'L';// $NON-NLS-1$
    150. private static final int NONPROXY_HOSTS = 'N';// $NON-NLS-1$
    151. private static final int PROXY_PORT = 'P';// $NON-NLS-1$
    152. private static final int REMOTE_OPT_PARAM = 'R';// $NON-NLS-1$
    153. private static final int SYSTEM_PROPFILE = 'S';// $NON-NLS-1$
    154. private static final int REMOTE_STOP = 'X';// $NON-NLS-1$
    155. private static final String JMX_SUFFIX = ".JMX"; // $NON-NLS-1$
    156. private static final String PACKAGE_PREFIX = "org.apache."; //$NON_NLS-1$
    157. /**
    158. * Define the understood options. Each CLOptionDescriptor contains:
    159. * <ul>
    160. * <li>The "long" version of the option. Eg, "help" means that "--help"
    161. * will be recognised.</li>
    162. * <li>The option flags, governing the option's argument(s).</li>
    163. * <li>The "short" version of the option. Eg, 'h' means that "-h" will be
    164. * recognised.</li>
    165. * <li>A description of the option.</li>
    166. * </ul>
    167. */
    168. private static final CLOptionDescriptor D_OPTIONS_OPT =
    169. new CLOptionDescriptor("?", CLOptionDescriptor.ARGUMENT_DISALLOWED, OPTIONS_OPT,
    170. "print command line options and exit");
    171. private static final CLOptionDescriptor D_HELP_OPT =
    172. new CLOptionDescriptor("help", CLOptionDescriptor.ARGUMENT_DISALLOWED, HELP_OPT,
    173. "print usage information and exit");
    174. private static final CLOptionDescriptor D_VERSION_OPT =
    175. new CLOptionDescriptor("version", CLOptionDescriptor.ARGUMENT_DISALLOWED, VERSION_OPT,
    176. "print the version information and exit");
    177. private static final CLOptionDescriptor D_PROPFILE_OPT =
    178. new CLOptionDescriptor("propfile", CLOptionDescriptor.ARGUMENT_REQUIRED, PROPFILE_OPT,
    179. "the jmeter property file to use");
    180. private static final CLOptionDescriptor D_PROPFILE2_OPT =
    181. new CLOptionDescriptor("addprop", CLOptionDescriptor.ARGUMENT_REQUIRED
    182. | CLOptionDescriptor.DUPLICATES_ALLOWED, PROPFILE2_OPT,
    183. "additional JMeter property file(s)");
    184. private static final CLOptionDescriptor D_TESTFILE_OPT =
    185. new CLOptionDescriptor("testfile", CLOptionDescriptor.ARGUMENT_REQUIRED, TESTFILE_OPT,
    186. "the jmeter test(.jmx) file to run. \"-t LAST\" will load last used file");
    187. private static final CLOptionDescriptor D_LOGFILE_OPT =
    188. new CLOptionDescriptor("logfile", CLOptionDescriptor.ARGUMENT_REQUIRED, LOGFILE_OPT,
    189. "the file to log samples to");
    190. private static final CLOptionDescriptor D_JMLOGCONF_OPT =
    191. new CLOptionDescriptor("jmeterlogconf", CLOptionDescriptor.ARGUMENT_REQUIRED, JMLOGCONF_OPT,
    192. "jmeter logging configuration file (log4j2.xml)");
    193. private static final CLOptionDescriptor D_JMLOGFILE_OPT =
    194. new CLOptionDescriptor("jmeterlogfile", CLOptionDescriptor.ARGUMENT_REQUIRED, JMLOGFILE_OPT,
    195. "jmeter run log file (jmeter.log)");
    196. private static final CLOptionDescriptor D_NONGUI_OPT =
    197. new CLOptionDescriptor("nongui", CLOptionDescriptor.ARGUMENT_DISALLOWED, NONGUI_OPT,
    198. "run JMeter in nongui mode");
    199. private static final CLOptionDescriptor D_SERVER_OPT =
    200. new CLOptionDescriptor("server", CLOptionDescriptor.ARGUMENT_DISALLOWED, SERVER_OPT,
    201. "run the JMeter server");
    202. private static final CLOptionDescriptor D_PROXY_SCHEME =
    203. new CLOptionDescriptor("proxyScheme", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_SCHEME,
    204. "Set a proxy scheme to use for the proxy server");
    205. private static final CLOptionDescriptor D_PROXY_HOST =
    206. new CLOptionDescriptor("proxyHost", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_HOST,
    207. "Set a proxy server for JMeter to use");
    208. private static final CLOptionDescriptor D_PROXY_PORT =
    209. new CLOptionDescriptor("proxyPort", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PORT,
    210. "Set proxy server port for JMeter to use");
    211. private static final CLOptionDescriptor D_NONPROXY_HOSTS =
    212. new CLOptionDescriptor("nonProxyHosts", CLOptionDescriptor.ARGUMENT_REQUIRED, NONPROXY_HOSTS,
    213. "Set nonproxy host list (e.g. *.apache.org|localhost)");
    214. private static final CLOptionDescriptor D_PROXY_USERNAME =
    215. new CLOptionDescriptor("username", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_USERNAME,
    216. "Set username for proxy server that JMeter is to use");
    217. private static final CLOptionDescriptor D_PROXY_PASSWORD =
    218. new CLOptionDescriptor("password", CLOptionDescriptor.ARGUMENT_REQUIRED, PROXY_PASSWORD,
    219. "Set password for proxy server that JMeter is to use");
    220. private static final CLOptionDescriptor D_JMETER_PROPERTY =
    221. new CLOptionDescriptor("jmeterproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
    222. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_PROPERTY,
    223. "Define additional JMeter properties");
    224. private static final CLOptionDescriptor D_JMETER_GLOBAL_PROP =
    225. new CLOptionDescriptor("globalproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
    226. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, JMETER_GLOBAL_PROP,
    227. "Define Global properties (sent to servers)\n\t\te.g. -Gport=123 or -Gglobal.properties");
    228. private static final CLOptionDescriptor D_SYSTEM_PROPERTY =
    229. new CLOptionDescriptor("systemproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
    230. | CLOptionDescriptor.ARGUMENTS_REQUIRED_2, SYSTEM_PROPERTY,
    231. "Define add
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/648370
推荐阅读
相关标签
  

闽ICP备14008679号