Java Code Examples for org.apache.jmeter.samplers.SampleResult#getTime()

The following examples show how to use org.apache.jmeter.samplers.SampleResult#getTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AggregatedTypeUpdater.java    From jmeter-prometheus-plugin with Apache License 2.0 6 votes vote down vote up
protected long measure(SampleEvent event) {
	SampleResult result = event.getResult();
	switch(this.config.getMeasuringAsEnum()) {
	case ResponseSize:
		return result.getBodySizeAsLong();
	case ResponseTime:
		return result.getTime();
	case Latency:
		return result.getLatency();
	case IdleTime:
		return result.getIdleTime();
	case ConnectTime:
		return result.getConnectTime();
	default:
		return 0;
	}
}
 
Example 2
Source File: ConsoleStatusLogger.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void sampleOccurred(SampleEvent se) {
    // TODO: make the interval configurable
    long sec = System.currentTimeMillis() / 1000;
    if (sec != cur && count > 0) {
        if (cur == 0) {
            begin = sec;
        }

        log.debug(cur + " " + begin);
        flush(sec - begin);
        cur = sec;
    }
    SampleResult res = se.getResult();

    count++;
    sumRTime += res.getTime();
    sumLatency += res.getLatency();
    errors += res.isSuccessful() ? 0 : 1;
    threads = res.getAllThreads();
}
 
Example 3
Source File: LoadosophiaClient.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
private JSONObject getAggregateSecond(Long sec, List<SampleResult> raw) {
    /*
     "rc": item.http_codes,
     "net": item.net_codes
     */
    JSONObject result = new JSONObject();
    Date ts = new Date(sec * 1000);
    log.debug("Aggregating " + sec);
    result.put("ts", format.format(ts));

    int avg_rt = 0;
    Long[] rtimes = new Long[raw.size()];
    String[] rcodes = new String[raw.size()];
    int cnt = 0;
    int failedCount = 0;
    long maxThreadCount = 0;
    for (SampleResult res : raw) {
        if (maxThreadCount < res.getAllThreads()) {
            maxThreadCount = res.getAllThreads();
        }

        avg_rt += res.getTime();
        rtimes[cnt] = res.getTime();
        rcodes[cnt] = res.getResponseCode();
        if (!res.isSuccessful()) {
            failedCount++;
        }
        cnt++;
    }

    result.put("rps", cnt);
    result.put("threads", maxThreadCount);
    result.put("avg_rt", avg_rt / cnt);
    result.put("quantiles", getQuantilesJSON(rtimes));
    result.put("net", getNetJSON(failedCount, cnt - failedCount));
    result.put("rc", getRCJSON(rcodes));
    result.put("planned_rps", 0); // JMeter has no such feature like Yandex.Tank
    return result;
}
 
Example 4
Source File: ThroughputVsThreadsGui.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void add(SampleResult res)
{
    if (!isSampleIncluded(res)) {
        return;
    }

    long time = res.getTime();
    if (time < 1)
    {
        return;
    }

    super.add(res);

    String label = res.getSampleLabel();
    String averageLabel = "Average " + res.getSampleLabel();
    GraphRowAverages row = (GraphRowAverages) model.get(label);
    GraphRowOverallAverages avgRow = (GraphRowOverallAverages) model.get(averageLabel);

    if(row == null || avgRow == null)
    {
        row = (GraphRowAverages) getNewRow(model, AbstractGraphRow.ROW_AVERAGES, label, AbstractGraphRow.MARKER_SIZE_SMALL , false, false, false, true, false);
        avgRow = (GraphRowOverallAverages) getNewRow(model, AbstractGraphRow.ROW_OVERALL_AVERAGES, averageLabel, AbstractGraphRow.MARKER_SIZE_BIG , false, true, false, false, row.getColor(), false);
    }

    int allThreads = getCurrentThreadCount(res);
    double throughput = (double) allThreads * 1000.0d / time;
    row.add(allThreads, throughput);
    avgRow.add(allThreads, throughput);
    graphPanel.getGraphObject().setCurrentX(allThreads);
    updateGui(null);
}
 
Example 5
Source File: JSONConverter.java    From jmeter-bzm-plugins with Apache License 2.0 4 votes vote down vote up
private static Map<String, Object> getMainMetrics(List<SampleResult> list) {
    long first = Long.MAX_VALUE;
    long last = 0;
    long failed = 0;
    long bytesCount = 0;
    long sumTime = 0;
    long sumLatency = 0;
    Long[] rtimes = new Long[list.size()];
    int counter = 0;

    for (SampleResult sample : list) {
        long endTime = sample.getEndTime();

        if (endTime < first) {
            first = endTime;
        }

        if (endTime > last) {
            last = endTime;
        }

        if (!sample.isSuccessful()) {
            failed++;
        }

        bytesCount += sample.getBytes();
        sumTime += sample.getTime();
        sumLatency += sample.getLatency();
        rtimes[counter] = sample.getTime();
        counter++;
    }

    final Map<String, Object> results = new HashMap<>();

    results.put("first", first);
    results.put("last", last);
    results.put("failed", failed);
    results.put("bytesCount", bytesCount);
    results.put("sumTime", sumTime);
    results.put("sumLatency", sumLatency);
    results.put("rtimes", rtimes);

    return results;
}
 
Example 6
Source File: HonoSender.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Publishes multiple messages to Hono.
 *
 * @param sampleResult The result object representing the combined outcome of the samples.
 * @param messageCount The number of messages to send
 * @param deviceId The identifier if the device to send a message for.
 * @param waitForDeliveryResult A flag indicating whether to wait for the result of the send operation.
 */
public void send(final SampleResult sampleResult, final int messageCount, final String deviceId,
                 final boolean waitForDeliveryResult) {
    final long sampleStart = System.currentTimeMillis();
    long addedSendDurations = 0;
    boolean isSuccessful = true;
    String firstResponseErrorMessage = "";
    String firstResponseErrorCode = "";
    long sentBytes = 0;
    int errorCount = 0;
    for (int i = 0; i < messageCount; i++) {
        final SampleResult subResult = new SampleResult();
        subResult.setDataType(SampleResult.TEXT);
        subResult.setResponseOK();
        subResult.setResponseCodeOK();
        subResult.setSampleLabel(sampleResult.getSampleLabel());
        // send the message
        send(subResult, deviceId, waitForDeliveryResult);
        // can't call sampleResult.addSubResult(subResult) here - this would prevent a later invocation of sampleResult.setStampAndTime()
        sampleResult.addRawSubResult(subResult);

        if (!subResult.isSuccessful()) {
            isSuccessful = false;
            errorCount++;
            if (firstResponseErrorMessage.isEmpty()) {
                firstResponseErrorMessage = subResult.getResponseMessage();
                firstResponseErrorCode = subResult.getResponseCode();
            }
        }
        sentBytes += subResult.getSentBytes();
        addedSendDurations += subResult.getTime();
    }
    sampleResult.setSuccessful(isSuccessful);
    final String responseMessage = MessageFormat.format("BatchResult {0}/{1}/{2}", sampler.getEndpoint(), sampler.getTenant(), deviceId);
    if (isSuccessful) {
        sampleResult.setResponseMessage(responseMessage);
    } else {
        sampleResult.setResponseMessage(responseMessage + ": " + errorCount + " errors - first: " + firstResponseErrorMessage);
        sampleResult.setResponseCode(firstResponseErrorCode);
    }
    sampleResult.setSentBytes(sentBytes);
    sampleResult.setSampleCount(messageCount);
    sampleResult.setErrorCount(errorCount); // NOTE: This method does nothing in JMeter 3.3/4.0
    final long averageElapsedTimePerMessage = addedSendDurations / messageCount;
    sampleResult.setStampAndTime(sampleStart, averageElapsedTimePerMessage);
}
 
Example 7
Source File: PerfMonSampleResult.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
public static double getValue(SampleResult res) {
    return ((double) res.getTime()) / 1000d;
}