|
2#
楼主 |
发表于 2018-2-8 13:34:57
|
只看该作者
- public static void createChart_Jmeter(int type, Map<Integer, List<SampleResult>> sampleResultsMap,String className) throws IOException {
- ArrayList<double[]> tpsSeries = new ArrayList<double[]>();
- ArrayList<double[]> averageSeries = new ArrayList<double[]>();
- ArrayList<double[]> minSeries = new ArrayList<double[]>();
- ArrayList<double[]> maxSeries = new ArrayList<double[]>();
- ArrayList<double[]> time60 = new ArrayList<double[]>();
- ArrayList<double[]> time90 = new ArrayList<double[]>();
- ArrayList<double[]> time95 = new ArrayList<double[]>();
- //用treeSet排序
- TreeSet<Integer> tree = new TreeSet<Integer>();
- for(int thread : sampleResultsMap.keySet()) {
- tree.add(thread);
- }
- // 遍历每一个threadgroup的结果集,算出tps,平均相应时间并画图
- for(int thread : tree) {
- AggregatedParser aggregated = new AggregatedParser(sampleResultsMap.get(thread));
- double tps = aggregated.getTps();
- double averageTime = aggregated.getAverageTime();
- long maxTime = aggregated.getMaxTime();
- long minTime = aggregated.getMinTime();
- long per60Time = aggregated.getPercentTime(0.6);
- long per90Time = aggregated.getPercentTime(0.9);
- long per95Time = aggregated.getPercentTime(0.95);
- double errorRate = aggregated.getErrorRate();
- tpsSeries.add(new double[]{thread, tps});
- averageSeries.add(new double[]{thread, averageTime});
- maxSeries.add(new double[]{thread, maxTime});
- minSeries.add(new double[]{thread, minTime});
- time60.add(new double[]{thread, per60Time});
- time90.add(new double[]{thread, per90Time});
- time95.add(new double[]{thread, per95Time});
- Logger.info("在"+thread+"并发下错误率:"+errorRate);
- }
- Map<String, ArrayList<double[]>> timeMap = new HashMap<String, ArrayList<double[]>>();
- timeMap.put("average time", averageSeries);
- timeMap.put("min time", minSeries);
- timeMap.put("max time", maxSeries);
- timeMap.put("60% time", time60);
- timeMap.put("90% time", time90);
- timeMap.put("95% time", time95);
- JfreeChart tpsChart = new JfreeChart("thread_tps", "thread", "tps");
- tpsChart.addXYSeries("thread_tps_report", tpsSeries);
- File folder = new File(Constant.imagePath()+className);
- folder.mkdirs();
- File imgTps = new File(Constant.imagePath()+className, "_tps.png");
- tpsChart.createJfreeChartImage(imgTps, 800, 600);
- //在html report中增加图片链接
- //Logger.html_img(Constant.imagePath()+className+"/_tps.png");
- //echarts_Qps(tpsSeries);
- JfreeChart avgTimeChart = new JfreeChart("avgTime", "thread", "avg_time");
- avgTimeChart.addXYSeries("thread_avgTime", averageSeries);
- File imgAvgTime = new File(Constant.imagePath()+className, "_avg.png");
- avgTimeChart.createJfreeChartImage(imgAvgTime, 800, 600);
- //在html report中增加图片链接
- //Logger.html_img(Constant.imagePath()+className+"/_avg.png");
- //使用echart在html页面中花出tps和平均响应时间的图
- Integer id = tempCount.getAndAdd(1);
- Logger.html("<div id=\"chart_qps"+id+"\" style=\"width:800px;height:600px;\"></div>");
- Logger.html("<div id=\"chart_time"+id+"\" style=\"width:800px;height:600px;\"></div>");
- Logger.html("<script>");
- echarts_Qps(tpsSeries,id);
- echarts_Time(timeMap,id);
- Logger.html("</script>");
复制代码 然后增加结果收集算法。并画出图来。我分别用jfreechart和echart画图。
然后我们一下case控制
- <suite name="rock" >
- <paras>
- <para host_ip="10.9.20.171"></para>
- </paras>
- <cases>
- <case name="performance.TestP" run="false">
- <perf begin_thread="100" end_thread="200" add_thread="20" loop="10"/>
- <para desc="根据订单ID查询订单"></para>
- </case>
- <case name="performance.TestP" run="false">
- <perf begin_thread="100" end_thread="200" add_thread="20" loop="10"/>
- <para desc="根据订单ID查询订单"></para>
- </case>
- </cases>
- </suite>
复制代码 case里有我们想要控制的信息,例如起始的并发数,每次递增的并发数。结束的并发数等等。
其中name就是我们的测试类的全路径(我这里都是我自己写的demo类)。
效果图
现在我们来看看效果图吧,就是我们最后的结果
以及
|
|