From 0ed00218959e9185a392cfe7f3849960f1745d71 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 17 Apr 2020 18:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=93=8D=E5=BA=94=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/report/JtlResolver.java | 153 ++++-------------- .../report/components/TestOverview.vue | 38 +++-- 2 files changed, 60 insertions(+), 131 deletions(-) diff --git a/backend/src/main/java/io/metersphere/report/JtlResolver.java b/backend/src/main/java/io/metersphere/report/JtlResolver.java index 87082b87c5..b54741bee1 100644 --- a/backend/src/main/java/io/metersphere/report/JtlResolver.java +++ b/backend/src/main/java/io/metersphere/report/JtlResolver.java @@ -11,10 +11,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.report.core.Sample; import org.apache.jmeter.report.core.SampleMetadata; import org.apache.jmeter.report.dashboard.JsonizerVisitor; -import org.apache.jmeter.report.processor.ListResultData; -import org.apache.jmeter.report.processor.MapResultData; -import org.apache.jmeter.report.processor.ResultData; -import org.apache.jmeter.report.processor.SampleContext; +import org.apache.jmeter.report.processor.*; import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer; import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer; @@ -346,61 +343,6 @@ public class JtlResolver { return testOverview; } - -// public static List getLoadChartData(String jtlString) { -// List chartsDataList = new ArrayList<>(); -// List totalMetricList = JtlResolver.resolver(jtlString); -// -// if (totalMetricList != null) { -// for (Metric metric : totalMetricList) { -// metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp())); -// } -// } -// Map> collect = Objects.requireNonNull(totalMetricList).stream().collect(Collectors.groupingBy(Metric::getTimestamp)); -// List>> entries = new ArrayList<>(collect.entrySet()); -// -// for (Map.Entry> entry : entries) { -// int failSize = 0; -// List metrics = entry.getValue(); -// Map> metricsMap = metrics.stream().collect(Collectors.groupingBy(Metric::getThreadName)); -// int maxUsers = metricsMap.size(); -// for (Metric metric : metrics) { -// String isSuccess = metric.getSuccess(); -// if (!"true".equals(isSuccess)) { -// failSize++; -// } -// } -// -// String timeStamp = ""; -// try { -// timeStamp = formatDate(entry.getKey()); -// } catch (ParseException e) { -// e.printStackTrace(); -// } -// -// ChartsData chartsData = new ChartsData(); -// chartsData.setxAxis(timeStamp); -// chartsData.setGroupName("hits"); -// chartsData.setyAxis(new BigDecimal(metrics.size() * 1.0 / maxUsers)); -// chartsDataList.add(chartsData); -// -// chartsData = new ChartsData(); -// chartsData.setxAxis(timeStamp); -// chartsData.setGroupName("users"); -// chartsData.setyAxis(new BigDecimal(maxUsers)); -// chartsDataList.add(chartsData); -// -// chartsData = new ChartsData(); -// chartsData.setxAxis(timeStamp); -// chartsData.setGroupName("errors"); -// chartsData.setyAxis(new BigDecimal(failSize)); -// chartsDataList.add(chartsData); -// -// } -// -// return chartsDataList; -// } - public static List getLoadChartData(String jtlString) { Map activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer()); Map hitsMap = getResultDataMap(jtlString, new HitsPerSecondGraphConsumer()); @@ -412,45 +354,6 @@ public class JtlResolver { return activeThreadList; } - // public static List getResponseTimeChartData(String jtlString) { -// List chartsDataList = new ArrayList<>(); -// List totalMetricList = JtlResolver.resolver(jtlString); -// -// totalMetricList.forEach(metric -> { -// metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp())); -// }); -// -// Map> metricMap = totalMetricList.stream().collect(Collectors.groupingBy(Metric::getTimestamp)); -// List>> entries = new ArrayList<>(metricMap.entrySet()); -// -// for (Map.Entry> entry : entries) { -// List metricList = entry.getValue(); -// Map> metricsMap = metricList.stream().collect(Collectors.groupingBy(Metric::getThreadName)); -// int maxUsers = metricsMap.size(); -// int sumElapsedTime = metricList.stream().mapToInt(metric -> Integer.parseInt(metric.getElapsed())).sum(); -// String timeStamp = ""; -// try { -// timeStamp = formatDate(entry.getKey()); -// } catch (ParseException e) { -// e.printStackTrace(); -// } -// -// ChartsData chartsData = new ChartsData(); -// chartsData.setxAxis(timeStamp); -// chartsData.setGroupName("users"); -// chartsData.setyAxis(new BigDecimal(maxUsers)); -// chartsDataList.add(chartsData); -// -// ChartsData chartsData2 = new ChartsData(); -// chartsData2.setxAxis(timeStamp); -// chartsData2.setGroupName("responseTime"); -// chartsData2.setyAxis(new BigDecimal(sumElapsedTime * 1.0 / metricList.size())); -// chartsDataList.add(chartsData2); -// -// } -// -// return chartsDataList; -// } public static List getResponseTimeChartData(String jtlString) { Map activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer()); Map responseTimeMap = getResultDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer()); @@ -464,40 +367,52 @@ public class JtlResolver { } public static void mapResolver(Map map, List list, String seriesName) { + // ThreadGroup-1 for (String key : map.keySet()) { MapResultData mapResultData = (MapResultData) map.get(key); ResultData maxY = mapResultData.getResult("maxY"); ListResultData series = (ListResultData) mapResultData.getResult("series"); if (series.getSize() > 0) { - MapResultData resultData = (MapResultData) series.get(0); - ListResultData data = (ListResultData) resultData.getResult("data"); - if (data.getSize() > 0) { - for (int i = 0; i < data.getSize(); i++) { - ListResultData listResultData = (ListResultData) data.get(i); - String result = listResultData.accept(new JsonizerVisitor()); - result = result.substring(1, result.length() - 1); - String[] split = result.split(","); - ChartsData chartsData = new ChartsData(); - BigDecimal bigDecimal = new BigDecimal(split[0]); - String timeStamp = bigDecimal.toPlainString(); - String time = null; - try { - time = formatDate(stampToDate(DATE_TIME_PATTERN, timeStamp)); - } catch (ParseException e) { - e.printStackTrace(); + for (int j = 0; j < series.getSize(); j++) { + MapResultData resultData = (MapResultData) series.get(j); + // data, isOverall, label, isController + ListResultData data = (ListResultData) resultData.getResult("data"); + ValueResultData label = (ValueResultData) resultData.getResult("label"); + + if (data.getSize() > 0) { + for (int i = 0; i < data.getSize(); i++) { + ListResultData listResultData = (ListResultData) data.get(i); + String result = listResultData.accept(new JsonizerVisitor()); + result = result.substring(1, result.length() - 1); + String[] split = result.split(","); + ChartsData chartsData = new ChartsData(); + BigDecimal bigDecimal = new BigDecimal(split[0]); + String timeStamp = bigDecimal.toPlainString(); + String time = null; + try { + time = formatDate(stampToDate(DATE_TIME_PATTERN, timeStamp)); + } catch (ParseException e) { + e.printStackTrace(); + } + chartsData.setxAxis(time); + chartsData.setyAxis(new BigDecimal(split[1].trim())); + if (series.getSize() == 1) { + chartsData.setGroupName(seriesName); + } else { + chartsData.setGroupName((String) label.getValue()); + } + list.add(chartsData); } - chartsData.setxAxis(time); - chartsData.setyAxis(new BigDecimal(split[1].trim())); - chartsData.setGroupName(seriesName); - list.add(chartsData); } } + } } } public static Map getResultDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) { + int row = 0; AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer; abstractOverTimeGraphConsumer.setGranularity(60000); // 这个路径不存在 @@ -513,7 +428,7 @@ public class JtlResolver { while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); String[] data = line.split(",", -1); - Sample sample = new Sample(0, sampleMetaData, data); + Sample sample = new Sample(row++, sampleMetaData, data); abstractOverTimeGraphConsumer.consume(sample, 0); } abstractOverTimeGraphConsumer.stopConsuming(); diff --git a/frontend/src/business/components/performance/report/components/TestOverview.vue b/frontend/src/business/components/performance/report/components/TestOverview.vue index 13b87c1cfb..8a0654f6e7 100644 --- a/frontend/src/business/components/performance/report/components/TestOverview.vue +++ b/frontend/src/business/components/performance/report/components/TestOverview.vue @@ -157,7 +157,8 @@ this.$get("/performance/report/content/res_chart/" + this.id, res => { let data = res.data; let userList = data.filter(m => m.groupName === "users").map(m => m.yAxis); - let responseTimeList = data.filter(m => m.groupName === "responseTime").map(m => m.yAxis); + let responseTimeList = data.filter(m => m.groupName != "users").map(m => m.yAxis); + let responseGroupNameList = data.filter(m => m.groupName != "users").map(m => m.groupName); let userMax = this._getChartMax(userList); let resMax = this._getChartMax(responseTimeList); let resOption = { @@ -171,7 +172,24 @@ }, tooltip: { show: true, - trigger: 'axis' + trigger: 'axis', + extraCssText: 'z-index: 999;', + formatter: function (params, ticket, callback) { + let result = ""; + let name = params[0].name; + result += name + "
"; + for (let i = 0; i < params.length; i++) { + let seriesName = params[i].seriesName; + if (seriesName.length > 100) { + seriesName = seriesName.substring(0, 100); + } + let value = params[i].value; + let marker = params[i].marker; + result += marker + seriesName + ": " + value[1] + "
"; + } + + return result; + } }, legend: {}, xAxis: {}, @@ -197,14 +215,12 @@ { name: 'users', color: '#0CA74A', - }, - { - name: "responseTime", - yAxisIndex: '1', - color: '#99743C', } ] } + responseGroupNameList.forEach(item => { + setting["series"].splice(0, 0, {name: item, yAxisIndex: '1'}) + }) this.resOption = this.generateOption(resOption, data, setting); }) }, @@ -229,10 +245,11 @@ legend.push(name) series[name] = [] } - series[name].splice(xAxis.indexOf(item.xAxis), 0, [item.xAxis, Math.round(item.yAxis.toFixed(2))]); + series[name].splice(xAxis.indexOf(item.xAxis), 0, [item.xAxis, item.yAxis.toFixed(2)]); }) this.$set(option.legend, "data", legend); - this.$set(option.legend, "bottom", 10); + this.$set(option.legend, "type", "scroll"); + this.$set(option.legend, "bottom", "10px"); this.$set(option.xAxis, "data", xAxis); for (let name in series) { let d = series[name]; @@ -259,9 +276,6 @@ _getChartMax(arr) { const max = Math.max(...arr); return Math.ceil(max / 4.5) * 5; - }, - _arraySort(a, b) { - return a[0] > b[0]; } }, watch: {