报告-测试概览
This commit is contained in:
parent
653460fd8e
commit
be78fc5939
|
@ -5,7 +5,6 @@ import com.opencsv.bean.CsvToBeanBuilder;
|
||||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||||
import io.metersphere.report.base.*;
|
import io.metersphere.report.base.*;
|
||||||
import io.metersphere.report.parse.ResultDataParse;
|
import io.metersphere.report.parse.ResultDataParse;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.jmeter.report.processor.ErrorsSummaryConsumer;
|
import org.apache.jmeter.report.processor.ErrorsSummaryConsumer;
|
||||||
import org.apache.jmeter.report.processor.StatisticsSummaryConsumer;
|
import org.apache.jmeter.report.processor.StatisticsSummaryConsumer;
|
||||||
import org.apache.jmeter.report.processor.Top5ErrorsBySamplerConsumer;
|
import org.apache.jmeter.report.processor.Top5ErrorsBySamplerConsumer;
|
||||||
|
@ -14,6 +13,7 @@ import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer;
|
||||||
import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer;
|
import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
@ -21,12 +21,9 @@ import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class GenerateReport {
|
public class GenerateReport {
|
||||||
|
|
||||||
private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss";
|
|
||||||
|
|
||||||
private static List<Metric> resolver(String jtlString) {
|
private static List<Metric> resolver(String jtlString) {
|
||||||
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
|
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
|
||||||
ms.setType(Metric.class);
|
ms.setType(Metric.class);
|
||||||
|
@ -60,71 +57,38 @@ public class GenerateReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TestOverview getTestOverview(String jtlString) {
|
public static TestOverview getTestOverview(String jtlString) {
|
||||||
TestOverview testOverview = new TestOverview();
|
|
||||||
DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
||||||
|
|
||||||
List<Metric> totalLineList = GenerateReport.resolver(jtlString);
|
Map<String, Object> activeDataMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||||
// todo 修改测试概览的数值
|
List<ChartsData> usersList = ResultDataParse.graphMapParsing(activeDataMap, "users");
|
||||||
List<Metric> totalLineList2 = GenerateReport.resolver(jtlString);
|
Optional<ChartsData> max = usersList.stream().max(Comparator.comparing(ChartsData::getyAxis));
|
||||||
// 时间戳转时间
|
int maxUser = max.get().getyAxis().setScale(0, BigDecimal.ROUND_UP).intValue();
|
||||||
for (Metric metric : totalLineList2) {
|
|
||||||
metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<Metric>> collect2 = Objects.requireNonNull(totalLineList2).stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
Map<String, Object> hitsDataMap = ResultDataParse.getGraphDataMap(jtlString, new HitsPerSecondGraphConsumer());
|
||||||
List<Map.Entry<String, List<Metric>>> entries = new ArrayList<>(collect2.entrySet());
|
List<ChartsData> hitsList = ResultDataParse.graphMapParsing(hitsDataMap, "hits");
|
||||||
int maxUsers = 0;
|
double hits = hitsList.stream().map(ChartsData::getyAxis)
|
||||||
for (Map.Entry<String, List<Metric>> entry : entries) {
|
.mapToDouble(BigDecimal::doubleValue)
|
||||||
List<Metric> metrics = entry.getValue();
|
.average().orElse(0);
|
||||||
Map<String, List<Metric>> metricsMap = metrics.stream().collect(Collectors.groupingBy(Metric::getThreadName));
|
|
||||||
if (metricsMap.size() > maxUsers) {
|
|
||||||
maxUsers = metricsMap.size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, List<Metric>> collect = totalLineList.stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
Map<String, Object> errorDataMap = ResultDataParse.getSummryDataMap(jtlString, new StatisticsSummaryConsumer());
|
||||||
Iterator<Map.Entry<String, List<Metric>>> iterator = collect.entrySet().iterator();
|
List<Statistics> statisticsList = ResultDataParse.summaryMapParsing(errorDataMap, Statistics.class);
|
||||||
|
Optional<Double> error = statisticsList.stream().map(item -> Double.parseDouble(item.getError())).reduce(Double::sum);
|
||||||
|
|
||||||
int totalElapsed = 0;
|
Map<String, Object> responseDataMap = ResultDataParse.getGraphDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer());
|
||||||
float totalBytes = 0f;
|
List<ChartsData> responseDataList = ResultDataParse.graphMapParsing(responseDataMap, "response");
|
||||||
|
double responseTime = responseDataList.stream().map(ChartsData::getyAxis)
|
||||||
|
.mapToDouble(BigDecimal::doubleValue)
|
||||||
|
.average().orElse(0);
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
TestOverview testOverview = new TestOverview();
|
||||||
Map.Entry<String, List<Metric>> entry = iterator.next();
|
testOverview.setMaxUsers(String.valueOf(maxUser));
|
||||||
List<Metric> metricList = entry.getValue();
|
testOverview.setAvgThroughput(decimalFormat.format(hits));
|
||||||
|
testOverview.setErrors(decimalFormat.format(error.get()));
|
||||||
for (Metric metric : metricList) {
|
testOverview.setAvgResponseTime(decimalFormat.format(responseTime / 1000));
|
||||||
String elapsed = metric.getElapsed();
|
|
||||||
totalElapsed += Integer.parseInt(elapsed);
|
|
||||||
String bytes = metric.getBytes();
|
|
||||||
totalBytes += Float.parseFloat(bytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
totalLineList.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp())));
|
|
||||||
|
|
||||||
testOverview.setMaxUsers(String.valueOf(maxUsers));
|
|
||||||
|
|
||||||
List<Metric> list90 = totalLineList.subList(0, totalLineList.size() * 9 / 10);
|
|
||||||
long sum = list90.stream().mapToLong(metric -> Long.parseLong(metric.getElapsed())).sum();
|
|
||||||
double avg90 = (double) sum / 1000 / list90.size();
|
|
||||||
testOverview.setResponseTime90(decimalFormat.format(avg90));
|
|
||||||
|
|
||||||
long timesStampStart = Long.parseLong(totalLineList.get(0).getTimestamp());
|
|
||||||
long timesStampEnd = Long.parseLong(totalLineList.get(totalLineList.size() - 1).getTimestamp());
|
|
||||||
long time = timesStampEnd - timesStampStart + Long.parseLong(totalLineList.get(totalLineList.size() - 1).getElapsed());
|
|
||||||
double avgThroughput = (double) totalLineList.size() / (time * 1.0 / 1000);
|
|
||||||
testOverview.setAvgThroughput(decimalFormat.format(avgThroughput));
|
|
||||||
|
|
||||||
List<Metric> falseList = totalLineList.stream().filter(metric -> StringUtils.equals("false", metric.getSuccess())).collect(Collectors.toList());
|
|
||||||
double errors = falseList.size() * 1.0 / totalLineList.size() * 100;
|
|
||||||
testOverview.setErrors(decimalFormat.format(errors));
|
|
||||||
|
|
||||||
double avg = totalElapsed * 1.0 / totalLineList.size() / 1000;
|
|
||||||
testOverview.setAvgResponseTime(decimalFormat.format(avg));
|
|
||||||
|
|
||||||
double bandwidth = totalBytes * 1.0 / time;
|
|
||||||
testOverview.setAvgBandwidth(decimalFormat.format(bandwidth));
|
|
||||||
|
|
||||||
|
// todo
|
||||||
|
testOverview.setResponseTime90("0");
|
||||||
|
testOverview.setAvgBandwidth("0");
|
||||||
return testOverview;
|
return testOverview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,10 +132,4 @@ public class GenerateReport {
|
||||||
return reportTimeInfo;
|
return reportTimeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String stampToDate(String pattern, String timeStamp) {
|
|
||||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
|
||||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(timeStamp)), ZoneId.systemDefault());
|
|
||||||
return localDateTime.format(dateTimeFormatter);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue