From 3163cc1b14e3cc41c52cac13b55b99940fc8af99 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 13 Apr 2020 17:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E6=A6=82?= =?UTF-8?q?=E8=A7=88Max=20Users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/report/JtlResolver.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index 3f2490d9e0..ba423a1ac8 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -104,7 +104,7 @@ public class JtlResolver { String average = decimalFormat.format((float) oneLineElapsedTime / jtlSamplesSize); requestStatistics.setAverage(average); - /** + /* * TP90的计算 * 1,把一段时间内全部的请求的响应时间,从小到大排序,获得序列A * 2,总的请求数量,乘以90%,获得90%对应的请求个数C @@ -123,7 +123,7 @@ public class JtlResolver { requestStatistics.setMax(elapsedList.get(jtlSamplesSize - 1) + ""); requestStatistics.setErrors(decimalFormat.format(failSize * 100.0 / jtlSamplesSize) + "%"); requestStatistics.setKo(failSize); - /** + /* * 所有的相同请求的bytes总和 / 1024 / 请求持续运行的时间=sum(bytes)/1024/total time * total time = 最大时间戳 - 最小时间戳 + 最后请求的响应时间 */ @@ -268,20 +268,34 @@ public class JtlResolver { DecimalFormat decimalFormat = new DecimalFormat("0.00"); List totalLineList = JtlResolver.resolver(jtlString); + // todo + List totalLineList2 = JtlResolver.resolver(jtlString); + // 时间戳转时间 + for (Metric metric : totalLineList2) { + metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp())); + } + + Map> collect2 = Objects.requireNonNull(totalLineList2).stream().collect(Collectors.groupingBy(Metric::getTimestamp)); + List>> entries = new ArrayList<>(collect2.entrySet()); + int maxUsers = 0; + for (Map.Entry> entry : entries) { + List metrics = entry.getValue(); + Map> metricsMap = metrics.stream().collect(Collectors.groupingBy(Metric::getThreadName)); + if (metricsMap.size() > maxUsers) { + maxUsers = metricsMap.size(); + } + } + Map> collect = totalLineList.stream().collect(Collectors.groupingBy(Metric::getTimestamp)); Iterator>> iterator = collect.entrySet().iterator(); - int maxUsers = 0, totalElapsed = 0; + int totalElapsed = 0; float totalBytes = 0f; while (iterator.hasNext()) { Map.Entry> entry = iterator.next(); List metricList = entry.getValue(); - if (metricList.size() > maxUsers) { - maxUsers = metricList.size(); - } - for (Metric metric : metricList) { String elapsed = metric.getElapsed(); totalElapsed += Integer.parseInt(elapsed);