Search in sources :

Example 1 with Aggregator

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

the class AbstractGraphConsumer method aggregateValue.

/**
 * Aggregate a value to the aggregator defined by the specified parameters.
 */
private void aggregateValue(AggregatorFactory factory, SeriesData data, Double key, double value) {
    Map<Double, Aggregator> aggInfo = data.getAggregatorInfo();
    // Get or create aggregator
    Aggregator aggregator = aggInfo.get(key);
    if (aggregator == null) {
        aggregator = factory.createValueAggregator();
        aggInfo.put(key, aggregator);
    }
    // Add the value to the aggregator
    aggregator.addValue(value);
    // Increment the count of sample for this series
    data.incrementCount();
    // Aggregate keys if needed (if aggregated keys series is set)
    Aggregator keysAgg = data.getKeysAggregator();
    if (keysAgg != null) {
        keysAgg.addValue(key);
    }
    // Aggregate values if needed (if aggregated keys series is set)
    Aggregator valuesAgg = data.getValuesAggregator();
    if (valuesAgg != null) {
        valuesAgg.addValue(value);
    }
}
Also used : Aggregator(org.apache.jmeter.report.processor.Aggregator)

Example 2 with Aggregator

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

the class AbstractGraphConsumer method addKeyData.

/**
 * Adds a value map build from specified parameters to the result map.
 *
 * @param result     {@link MapResultData}
 * @param group
 * @param series
 * @param seriesData
 * @param aggregated
 */
private void addKeyData(MapResultData result, @SuppressWarnings("unused") String group, String series, SeriesData seriesData, boolean aggregated) {
    // Override series name when aggregated
    if (aggregated) {
        series = String.format(aggregatedKeysSeriesFormat, series);
    }
    // Add to the result map
    ListResultData seriesList = (ListResultData) result.getResult(RESULT_SERIES);
    // Looks for series result using its name
    MapResultData seriesResult = null;
    int index = 0;
    int size = seriesList.getSize();
    while (seriesResult == null && index < size) {
        MapResultData currSeries = (MapResultData) seriesList.get(index);
        String name = String.valueOf(((ValueResultData) currSeries.getResult(RESULT_SERIES_NAME)).getValue());
        if (Objects.equals(name, series)) {
            seriesResult = currSeries;
        }
        index++;
    }
    // Create series result if not found
    if (seriesResult == null) {
        seriesResult = createSerieResult(series, seriesData);
        seriesList.addResult(seriesResult);
    }
    ListResultData dataResult = (ListResultData) seriesResult.getResult(RESULT_SERIES_DATA);
    // Populate it with data from groupData
    Map<Double, Aggregator> aggInfo;
    if (aggregated) {
        aggInfo = new HashMap<>();
        aggInfo.put(seriesData.getKeysAggregator().getResult(), seriesData.getValuesAggregator());
    } else {
        aggInfo = seriesData.getAggregatorInfo();
    }
    if (!renderPercentiles) {
        for (Map.Entry<Double, Aggregator> entry : aggInfo.entrySet()) {
            // Init key and value depending on invertKeysAndValues property
            Double key = entry.getKey();
            Double value = entry.getValue().getResult();
            if (invertKeysAndValues) {
                key = entry.getValue().getResult();
                value = entry.getKey();
            }
            // Create result storage for coordinates
            ListResultData coordResult = new ListResultData();
            coordResult.addResult(new ValueResultData(key));
            coordResult.addResult(new ValueResultData(value));
            dataResult.addResult(coordResult);
            setMinResult(result, RESULT_MIN_X, key);
            setMaxResult(result, RESULT_MAX_X, key);
            setMinResult(result, RESULT_MIN_Y, value);
            setMaxResult(result, RESULT_MAX_Y, value);
        }
    } else {
        long count = seriesData.getCount();
        int rank = 0;
        double percent = 0;
        TreeMap<Double, Aggregator> sortedInfo = new TreeMap<>(aggInfo);
        if (!invertKeysAndValues) {
            for (Map.Entry<Double, Aggregator> entry : sortedInfo.entrySet()) {
                Double value = entry.getKey();
                percent += (double) 100 * entry.getValue().getCount() / count;
                double percentile = (double) rank / 10;
                while (percentile < percent) {
                    ListResultData coordResult = new ListResultData();
                    coordResult.addResult(new ValueResultData(percentile));
                    coordResult.addResult(new ValueResultData(value));
                    dataResult.addResult(coordResult);
                    percentile = (double) ++rank / 10;
                }
                setMinResult(result, RESULT_MIN_Y, value);
                setMaxResult(result, RESULT_MAX_Y, value);
            }
            setMinResult(result, RESULT_MIN_X, 0d);
            setMaxResult(result, RESULT_MAX_X, 100d);
        } else {
            for (Map.Entry<Double, Aggregator> entry : sortedInfo.entrySet()) {
                Double value = entry.getKey();
                percent += (double) 100 * entry.getValue().getCount() / count;
                double percentile = (double) rank / 10;
                while (percentile < percent) {
                    ListResultData coordResult = new ListResultData();
                    coordResult.addResult(new ValueResultData(value));
                    coordResult.addResult(new ValueResultData(percentile));
                    dataResult.addResult(coordResult);
                    percentile = (double) ++rank / 10;
                }
                setMinResult(result, RESULT_MIN_X, value);
                setMaxResult(result, RESULT_MAX_X, value);
            }
            setMinResult(result, RESULT_MIN_Y, 0d);
            setMaxResult(result, RESULT_MAX_Y, 100d);
        }
    }
}
Also used : Aggregator(org.apache.jmeter.report.processor.Aggregator) TreeMap(java.util.TreeMap) MapResultData(org.apache.jmeter.report.processor.MapResultData) ListResultData(org.apache.jmeter.report.processor.ListResultData) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) ValueResultData(org.apache.jmeter.report.processor.ValueResultData)

Aggregations

Aggregator (org.apache.jmeter.report.processor.Aggregator)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ListResultData (org.apache.jmeter.report.processor.ListResultData)1 MapResultData (org.apache.jmeter.report.processor.MapResultData)1 ValueResultData (org.apache.jmeter.report.processor.ValueResultData)1