jmeter3.x source code modification to realize jtl file only print failed requests

In the process of using jmeter for performance stress testing, we often encounter the problem of high tps and long stress testing time, which leads to the generation of jtl files that are too large. Although the "-l" parameter can not be added to prevent jmeter from generating jtl files, the drawbacks of doing so are also Obviously, if there is a failed request, there is no log to find the cause of the failure and then troubleshoot the problem, so let's modify the jmeter source code and add the "-F" parameter to make jmeter produce the effect of only recording the failed request in jtl. .

The first is the JMeter.java file, and the definition of '-F' is added here according to the gourd painting:

private static final int SYSTEM_PROPFILE    = 'S';// $NON-NLS-1$
private static final int REMOTE_STOP        = 'X';// $NON-NLS-1$
private static final int JTLFAILONLY_OPT    = 'F';

 There are also the following places to add code accordingly:

private static final CLOptionDescriptor D_REPORT_OUTPUT_FOLDER_OPT =
            new CLOptionDescriptor("reportoutputfolder",
                    CLOptionDescriptor.ARGUMENT_REQUIRED, REPORT_OUTPUT_FOLDER_OPT,
                    "output folder for report dashboard");
private static final CLOptionDescriptor D_JTLFAILONLY_OPT =
            new CLOptionDescriptor("jtlfailonly",
                    CLOptionDescriptor.ARGUMENT_DISALLOWED, JTLFAILONLY_OPT,
                    "only record the failed request log");

 

private static final CLOptionDescriptor[] options = new CLOptionDescriptor[] {
            D_OPTIONS_OPT,
            D_HELP_OPT,
            D_VERSION_OPT,
            D_PROPFILE_OPT,
            D_PROPFILE2_OPT,
            D_TESTFILE_OPT,
            D_LOGFILE_OPT,
            D_JTLFAILONLY_OPT,

 This place is to get whether our parameter is empty and pass the parameter to the startNonGui method.

CLOption jtlfailonly = parser.getArgumentById(JTLFAILONLY_OPT);
                    
startNonGui(testFile, jtlFile, rem, reportAtEndOpt != null, jtlfailonly!=null);
startOptionalServers ();

 Pass the parameters to the runNonGui method in the startNonGui method

driver.runNonGui(testFile, logFile, remoteStart != null, remoteHostsString, generateReportDashboard, jtlfailonly);

 Modify the runNonGui method as follows, according to whether there is a polymorphic method to call ResultCollector according to the jtlfailonly parameter

if (logFile != null) {
                ResultCollector logger=null;
                if(jtlfailonly){
                    logger = new ResultCollector(summer,jtlfailonly);
                }else {
                    logger = new ResultCollector(summer);
                }

 The ResultCollector method is in the ResultCollector class, modified as follows:



 After recompiling and running, the effect can be achieved.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326847756&siteId=291194637