Search in sources :

Example 1 with FilterConsumer

use of org.apache.jmeter.report.processor.FilterConsumer in project jmeter by apache.

the class ReportGenerator method createNameFilter.

/**
 * @return a {@link FilterConsumer} that filters samplers based on their name
 */
private FilterConsumer createNameFilter() {
    FilterConsumer nameFilter = new FilterConsumer();
    nameFilter.setName(NAME_FILTER_CONSUMER_NAME);
    nameFilter.setSamplePredicate(sample -> {
        // Get filtered samples from configuration
        Pattern filteredSamplesPattern = configuration.getFilteredSamplesPattern();
        // or if its name matches the filter pattern
        return filteredSamplesPattern == null || filteredSamplesPattern.matcher(sample.getName()).matches();
    });
    nameFilter.addSampleConsumer(createApdexSummaryConsumer());
    nameFilter.addSampleConsumer(createRequestsSummaryConsumer());
    nameFilter.addSampleConsumer(createStatisticsSummaryConsumer());
    nameFilter.addSampleConsumer(createTop5ErrorsConsumer(configuration));
    return nameFilter;
}
Also used : Pattern(java.util.regex.Pattern) FilterConsumer(org.apache.jmeter.report.processor.FilterConsumer)

Example 2 with FilterConsumer

use of org.apache.jmeter.report.processor.FilterConsumer in project jmeter by apache.

the class ReportGenerator method generate.

/**
 * Generate dashboard reports using the data from the specified CSV File.
 *
 * @throws GenerationException when the generation failed
 */
public void generate() throws GenerationException {
    if (resultCollector != null) {
        log.info("Flushing result collector before report Generation");
        resultCollector.flushFile();
    }
    log.debug("Start report generation");
    File tmpDir = configuration.getTempDirectory();
    boolean tmpDirCreated = createTempDir(tmpDir);
    // Build consumers chain
    SampleContext sampleContext = new SampleContext();
    sampleContext.setWorkingDirectory(tmpDir);
    SampleSource source = new CsvFileSampleSource(testFile, CSV_DEFAULT_SEPARATOR);
    source.setSampleContext(sampleContext);
    NormalizerSampleConsumer normalizer = new NormalizerSampleConsumer();
    normalizer.setName(NORMALIZER_CONSUMER_NAME);
    FilterConsumer dateRangeConsumer = createFilterByDateRange();
    dateRangeConsumer.addSampleConsumer(createBeginDateConsumer());
    dateRangeConsumer.addSampleConsumer(createEndDateConsumer());
    FilterConsumer nameFilter = createNameFilter();
    FilterConsumer excludeControllerFilter = createExcludeControllerFilter();
    nameFilter.addSampleConsumer(excludeControllerFilter);
    dateRangeConsumer.addSampleConsumer(nameFilter);
    normalizer.addSampleConsumer(dateRangeConsumer);
    source.addSampleConsumer(normalizer);
    // Get graph configurations
    Map<String, GraphConfiguration> graphConfigurations = configuration.getGraphConfigurations();
    // Process configuration to build graph consumers
    for (Map.Entry<String, GraphConfiguration> entryGraphCfg : graphConfigurations.entrySet()) {
        addGraphConsumer(nameFilter, excludeControllerFilter, entryGraphCfg);
    }
    // Generate data
    log.debug("Start samples processing");
    try {
        // NOSONAR
        source.run();
    } catch (SampleException ex) {
        throw new GenerationException("Error while processing samples: " + ex.getMessage(), ex);
    }
    log.debug("End of samples processing");
    log.debug("Start data exporting");
    // Process configuration to build data exporters
    String key;
    ExporterConfiguration value;
    for (Map.Entry<String, ExporterConfiguration> entry : configuration.getExportConfigurations().entrySet()) {
        key = entry.getKey();
        value = entry.getValue();
        if (log.isInfoEnabled()) {
            log.info("Exporting data using exporter:'{}' of className:'{}'", key, value.getClassName());
        }
        exportData(sampleContext, key, value);
    }
    log.debug("End of data exporting");
    removeTempDir(tmpDir, tmpDirCreated);
    log.debug("End of report generation");
}
Also used : NormalizerSampleConsumer(org.apache.jmeter.report.processor.NormalizerSampleConsumer) SampleException(org.apache.jmeter.report.core.SampleException) GraphConfiguration(org.apache.jmeter.report.config.GraphConfiguration) FilterConsumer(org.apache.jmeter.report.processor.FilterConsumer) ExporterConfiguration(org.apache.jmeter.report.config.ExporterConfiguration) SampleContext(org.apache.jmeter.report.processor.SampleContext) CsvFileSampleSource(org.apache.jmeter.report.processor.CsvFileSampleSource) CsvFileSampleSource(org.apache.jmeter.report.processor.CsvFileSampleSource) SampleSource(org.apache.jmeter.report.processor.SampleSource) File(java.io.File) Map(java.util.Map)

Example 3 with FilterConsumer

use of org.apache.jmeter.report.processor.FilterConsumer in project jmeter by apache.

the class ReportGenerator method createExcludeControllerFilter.

private FilterConsumer createExcludeControllerFilter() {
    FilterConsumer excludeControllerFilter = new FilterConsumer();
    excludeControllerFilter.setName(START_INTERVAL_CONTROLLER_FILTER_CONSUMER_NAME);
    excludeControllerFilter.setSamplePredicate(new ControllerSamplePredicate());
    excludeControllerFilter.setReverseFilter(true);
    excludeControllerFilter.addSampleConsumer(createErrorsSummaryConsumer());
    return excludeControllerFilter;
}
Also used : ControllerSamplePredicate(org.apache.jmeter.report.core.ControllerSamplePredicate) FilterConsumer(org.apache.jmeter.report.processor.FilterConsumer)

Example 4 with FilterConsumer

use of org.apache.jmeter.report.processor.FilterConsumer in project jmeter by apache.

the class ReportGenerator method createFilterByDateRange.

/**
 * @return {@link FilterConsumer} that filter data based on date range
 */
@SuppressWarnings("JdkObsolete")
private FilterConsumer createFilterByDateRange() {
    FilterConsumer dateRangeFilter = new FilterConsumer();
    dateRangeFilter.setName(DATE_RANGE_FILTER_CONSUMER_NAME);
    dateRangeFilter.setSamplePredicate(sample -> {
        long sampleStartTime = sample.getStartTime();
        if (configuration.getStartDate() != null) {
            if (sampleStartTime >= configuration.getStartDate().getTime()) {
                if (configuration.getEndDate() != null) {
                    return sampleStartTime <= configuration.getEndDate().getTime();
                } else {
                    return true;
                }
            }
            return false;
        } else {
            if (configuration.getEndDate() != null) {
                return sampleStartTime <= configuration.getEndDate().getTime();
            } else {
                return true;
            }
        }
    });
    return dateRangeFilter;
}
Also used : FilterConsumer(org.apache.jmeter.report.processor.FilterConsumer)

Aggregations

FilterConsumer (org.apache.jmeter.report.processor.FilterConsumer)4 File (java.io.File)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 ExporterConfiguration (org.apache.jmeter.report.config.ExporterConfiguration)1 GraphConfiguration (org.apache.jmeter.report.config.GraphConfiguration)1 ControllerSamplePredicate (org.apache.jmeter.report.core.ControllerSamplePredicate)1 SampleException (org.apache.jmeter.report.core.SampleException)1 CsvFileSampleSource (org.apache.jmeter.report.processor.CsvFileSampleSource)1 NormalizerSampleConsumer (org.apache.jmeter.report.processor.NormalizerSampleConsumer)1 SampleContext (org.apache.jmeter.report.processor.SampleContext)1 SampleSource (org.apache.jmeter.report.processor.SampleSource)1