zoukankan      html  css  js  c++  java
  • Jmeter与ant整合生成美观的测试报告

            一直觉得Jmeter生成的测试报告很难看,偶尔发现网上用jmeter-results-detail-report_30.xsl整全ant生成了美观的测试报告,参考https://blog.csdn.net/zouxiongqqq/article/details/71094245

            鉴于对美丽的追求,我决定去尝试一下。但一入坑,发现问题很多。经过不懈的努力,终于把坑都一一填平了,这里分享一下经验。

      整个测试报告的基本逻辑是;:

           录好或者自己编写jmeter脚本,添加聚合报告、服务器监控、及一些性能监控参数,生成相应的文件放在某个目录,用ant启动测试,jmeter数据生成完后,用bat文件将生成的jtl数据生成相应的图表,然后html把相应的图表渲染出来。当然可以考虑将生成图表的操作也写入ant中,同时将这些数据移到一定指 定的文件夹中,所有这些都可以交给ant来执行。

            先上几张最后的效果图:

    坑一:

    build.xml里面相应的参数应该修改,这里面需要相应的ant的相关知道,我这里附上我使用的脚本

    <?xml version="1.0" encoding="UTF-8"?>
     <project name="ant-jmeter-testing" default="run" basedir=".">  
         <property name="jmeter.home" value="F:devapache-jmeter-5.0" />
         <property name="report.title" value="Performance and interface testing" />
         <property name="jmeter.result.jtl.dir" value="${jmeter.home}
    esult" />
         <property name="jmeter.result.html.dir" value="${jmeter.home}
    esult" />
         <property name="ReportName" value="TestReport" />
         <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}${ReportName}.jtl" />
         <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}${ReportName}.html" />
    	 <!--设置jmeter生成结果服务器上ip地址 -->
    	 <property name="jmeter.request.url" value="http://192.168.8.34" />
    	 <!--设置失败率为xx时,html是否标颜色 -->
    	 <property name="failure.rate" value="0.6" />
    	 <!--设置服务器日志地址 -->
    	 <property name="Result.log" value="http://www.w3school.com.cn" />
    	 <!--是否显示服务器日志地址,0代表显示,1代表不显示 -->
    	 <property name="Is.show.Result.log" value="0" />
    	 <!--是否显示关键指标(APT、TPS、Throughput、Hit等)图片,0代表显示,1代表不显示 -->
    	 <property name="Is.Show.Key.index" value="0" />
    	 <!--是否显示资源(CPU、Memory、io、Network等)图片,0代表显示,1代表不显示 -->
    	 <property name="Is.Show.Resource" value="0" />
    
    	 
         <target name="run">
    	 	 <tstamp> <format property="start.report.datestamp" pattern="yyyyMMddHHmmSS" /></tstamp>
             <antcall target="run_TestCase" />
    		 <antcall target="build_report" />
         </target>
         <target name="run_TestCase">	 
             <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
             <jmeter jmeterhome="${jmeter.home}" runremote="false" resultlog="${jmeter.result.jtlName}">
                 <testplans dir="${jmeter.home}TestCase" includes="login.jmx" />            
                 <property name="jmeter.save.saveservice.output_format" value="xml"/>
    	     <property name="jmeter.save.saveservice.response_message" value="false" />
    	     <jvmarg value="-Xincgc"/>  
                 <jvmarg value="-Xms1024m"/>
                 <jvmarg value="-Xmx1024m"/>  
             </jmeter>
         </target>
    	 
    	 <path id="xslt.classpath">
             <fileset dir="${jmeter.home}lib" includes="xalan*.jar"/>
             <fileset dir="${jmeter.home}lib" includes="serializer*.jar"/>
         </path>
    
         <target name="build_report">
             <tstamp> <format property="end.report.datestamp" pattern="yyyyMMddHHmmSS" /></tstamp>
             <xslt 
                 classpathref="xslt.classpath"
                 force="true"
                 in="${jmeter.result.jtlName}"
                 out="${jmeter.result.htmlName}"
                 style="${jmeter.home}extrasjmeter-results-detail-report_30.xsl">
                 <param name="start_datetime" expression="${start.report.datestamp}"/>
    			 <param name="end_datetime" expression="${end.report.datestamp}"/>
    			 <param name="request_url" expression="${jmeter.request.url}"/>
    			 <param name="failure_rate" expression="${failure.rate}"/>
    			 <param name="Result_log" expression="${Result.log}"/>
    			 <param name="Is_show_Result_log" expression="${Is.show.Result.log}"/>
    			 <param name="Is_Show_Key_index" expression="${Is.Show.Key.index}"/>
    			 <param name="Is_Show_Resource" expression="${Is.Show.Resource}"/>
             </xslt>
     
             <copy todir="${jmeter.result.html.dir}">
                 <fileset dir="${jmeter.home}extras">
                     <include name="collapse.png" />
                     <include name="expand.png" />
                 </fileset>
             </copy>
         </target>
    	
           
     </project>

    必须看懂相应的属性和任务,创建相应的文件夹

    坑二:

    原帖作者linux上用的是linux系统,我用的是windows系统,里面的shell脚本需要转化为bat脚本

    echo jmeter_home is %JMETER_HOME%
    cd %JMETER_HOME%
    esult
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl CPU.jtl --plugin-type PerfMon --generate-png CPU.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl Memory.jtl --plugin-type PerfMon --generate-png Memory.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl IO.jtl --plugin-type PerfMon --generate-png IO.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl Network.jtl --plugin-type PerfMon --generate-png Network.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl Trans.jtl --plugin-type TransactionsPerSecond  --generate-png Trans.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl TimesVsThreads.jtl --plugin-type TimesVsThreads   --generate-png TimesVsThreads.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl ResponseTimesOverTime.jtl --plugin-type ResponseTimesOverTime  --generate-png ResponseTimesOverTime.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl ThroughputVsThreads.jtl --plugin-type ThroughputVsThreads  --generate-png ThroughputVsThreads.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl HitsPerSecond.jtl --plugin-type HitsPerSecond  --generate-png HitsPerSecond.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl BytesThroughputOverTime.jtl --plugin-type BytesThroughputOverTime  --generate-png BytesThroughputOverTime.png
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl HitsPerSecond.jtl --plugin-type HitsPerSecond  --generate-csv HitsPerSecond.csv
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl CPU.jtl --plugin-type PerfMon --generate-csv CPU.csv
    java -jar %JMETER_HOME%libcmdrunner-2.2.jar --tool Reporter --input-jtl Memory.jtl --plugin-type PerfMon --generate-csv Memory.csv
    

     坑三:

    我生成的测试报告在浏览器中打开js报错,我将jmeter-results-detail-report_30.xsl的js里面注掉一些后成功,在些附上该内容

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <!--
       Licensed to the Apache Software Foundation (ASF) under one or more
       contributor license agreements.  See the NOTICE file distributed with
       this work for additional information regarding copyright ownership.
       The ASF licenses this file to You under the Apache License, Version 2.0
       (the "License"); you may not use this file except in compliance with
       the License.  You may obtain a copy of the License at
     
           http://www.apache.org/licenses/LICENSE-2.0
     
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
    -->
    
    <!-- 
    	Stylesheet for processing 2.1 output format test result files 
    	To uses this directly in a browser, add the following to the JTL file as line 2:
    	<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_21.xsl"?>
    	and you can then view the JTL in a browser
    -->
    
    <!-- 
    	Stylesheet for processing 3.0 output format test result files 
    	To uses this directly in a browser, add the following to the JTL file as line 2:
    	<?xml-stylesheet type="text/xsl" href="../extras/jmeter-results-detail-report_30.xsl"?>
    	and you can then view the JTL in a browser.Edit by ZHC
    -->
    
    <xsl:output method="html" indent="yes" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
    
    <!-- Defined parameters (overrideable) -->
    <xsl:param    name="showData" select="'y'"/>
    <xsl:param    name="titleReport" select="'Performance_or_Interface Test Results'"/>
    <xsl:param    name="start_datetime" select="'date not defined'"/>
    <xsl:param    name="end_datetime" select="'date not defined'"/>
    <xsl:param    name="request_url" select="'date not defined'"/>
    <xsl:param    name="failure_rate" select="$failure_rate"/>
    <xsl:param    name="Result_log" select="'date not defined'"/>
    <xsl:param    name="Is_show_Result_log" select="'date not defined'"/>
    <xsl:param    name="Is_Show_Key_index" select="'date not defined'"/>
    <xsl:param    name="Is_Show_Resource" select="'date not defined'"/>
    
    <xsl:template match="testResults">
    	<html>
    	<link type='text/css' rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.css" />
    		<head>
    			<title><xsl:value-of select="$titleReport" /></title>
    			<style type="text/css">
    				body {
    					font:normal 68% verdana,arial,helvetica;
    					color:#000000;
    				}
    				table tr td, table tr th {
    					font-size: 68%;
    					padding:10px 0;
    				}
    				table.details tr th{
    				    color: #ffffff;
    					font-weight: bold;
    					text-align:center;
    					background:#2674a6;
    					white-space: nowrap;
    					padding:10px 0;
    				}
    				table.details tr td{
    					background:#eeeee0;
    					white-space: nowrap;
    					padding:10px 0;
    				}
    				
    				h1 {
    					margin: 0px 0px 5px;
    					font-size: 40px;
    					text-align:center;
    					text-decoration:underline;
    				}
    				h2 {
    					margin-top: 1em;
    					margin-bottom: 0.5em;
    					font: bold 125% verdana,arial,helvetica;
    				}
    				h3 {
    					margin-bottom: 0.5em;
    					font: bold 115% verdana,arial,helvetica;
    					align:center;
    					
    				}
    				ul{
    					margin:0px;
    					padding:0px;
    				}
    				li{
    					margin-bottom:20px;
    				}
    				hr{
    					border:1px dashed red;
    					height:1px;
    				}
    				.top .Failure {
    					font-weight:bold;
    					background:red;
    				}
    				.top .Time3s {
    					font-weight:bold;
    					background:yellow;
    				}
    				.top .Time5s{
    					font-weight:bold; 
    					background:orange;
    				}
    				.top .Time8s{
    					font-weight:bold; 
    					background:red;
    				}				
    				.top .NintyTime3s {
    					font-weight:bold; 
    					background:yellow;
    				}
    				.top .NintyTime5s {
    					font-weight:bold; 
    					background:orange;
    				}
    				.top .NintyTime8s {
    					font-weight:bold; 
    					background:red;
    				}
    											
    				img
    				{
    				  border- 0px;
    				}
    				
    				.expand_link
    				{
    				   position=absolute;
    				   right: 0px;
    				    27px;
    				   top: 1px;
    				   height: 27px;
    				}
    				
    				.page_details
    				{
    				   display: none;
    				}
                                    
                    .page_details_expanded
                    {
                        display: block;
                        display/* hide this definition from  IE5/6 */: table-row;
                    }
    
    				table.Failure_Detail_expanded th{
    				    color: #ffffff;
    					font-weight: bold;
    					background:#2674a6;
    					white-space: nowrap;
    					padding:10px;
    					 5%;
    				}
    				table.Failure_Detail_expanded td{
    					background:#eeeee0;
    					white-space: nowrap;
    					padding:10px;
    				}
    				
    				.Failure_Detail_collapse
    				{
    				   display: none;
    				}
                                    
                    .Failure_Detail_expanded
                    {
                        display: block;
                        display/* hide this definition from  IE5/6 */: table-row;
                    }
    				
    				
    				#RPSTime3s {
    					font-weight:bold;
    					background:yellow;
    				}
    				#RPSTime5s{
    					font-weight:bold; 
    					background:orange;
    				}
    				#RPSTime8s{
    					font-weight:bold; 
    					background:red;
    				}
    				#failures{
    					font-weight:bold; 
    					background:red;
    				}
    				#show{ display:inline-block; 60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
    				#show1{ display:inline-block; 60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
    				#yellow_1{ display:inline-block; 10px; height:10px; line-height:22px; background:yellow; text-align: center; border-radius: 3px; color:#FFF;}
    				#red_1{ display:inline-block; 10px; height:10px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
    				#orange_1{ display:inline-block; 10px; height:10px; line-height:22px; background:orange; text-align: center; border-radius: 3px; color:#FFF;}
    				#failed{ display:inline-block; 10px; height:10px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
    				ul,ol{list-style: none;}
    			</style>
    			<script language="JavaScript">
    				<![CDATA[
    	                function expand(details_id)
    				   	{
    				      
    				    	document.getElementById(details_id).className = "page_details_expanded";
    				   	}
    				   
    				   	function collapse(details_id)
    				   	{
    				      
    				      	document.getElementById(details_id).className = "page_details";
    				   	}
    				   
    				   	function change(details_id)
    				   	{
    						if($(("#"+details_id+"_image")).text() == "show"){
    				         	$(("#"+details_id+"_image")).text("hidden");							
    				         	expand(details_id);
    				      	}else{
    				        	$(("#"+details_id+"_image")).text("show");
    				         	collapse(details_id);
    				      	}
    					
    	                }
    				]]>
    			</script>
    			
    			<script language="JavaScript">
    				<![CDATA[
    	                function expand1(details_id)
    				   	{
    				    	document.getElementById(details_id).className = "Failure_Detail_expanded";
    						document.getElementById(details_id).style.display="block";
    				   	}
    				   
    				   	function collapse1(details_id)
    				   	{
    				      	document.getElementById(details_id).className = "Failure_Detail_collapse";
    						document.getElementById(details_id).style.display ="none";
    				   	}
    				   
    				   	function change1(details_id)
    				   	{
    						if($(("#"+details_id+"_image")).text() == "show"){
    				         	$(("#"+details_id+"_image")).text("hidden");							
    				         	expand1(details_id);
    				      	}else{
    				        	$(("#"+details_id+"_image")).text("show");
    				         	collapse1(details_id);
    				      	}
    					
    	                }
    				]]>
    			</script>
    
    			
    		</head>
    		<body>
    			<xsl:call-template name="pageHeader" />			
    			<xsl:call-template name="summary" />
    			<hr width="100%" />
    			<xsl:call-template name="pagelist"/>
    			<xsl:call-template name="detail" />	
    			<hr width="100%" />
    			<xsl:call-template name="Resource" />	
    
    		</body>
    	</html>
    	<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    	<script>
    		
    	            var IP=$(Request_url).text();
    				$("#show").on("click", function(){
    				if($(this).text() == "show"){
    					$(this).text("hidden")
    				}else{
    					$(this).text("show")
    					}
    				$("#img-box").toggle();
    				});
    				
    				$("#show1").on("click", function(){
    				if($(this).text() == "show"){
    					$(this).text("hidden")
    				}else{
    					$(this).text("show")
    					}					
    				$("#img-box1").toggle();
    				});
    			
    		
    				//<![CDATA[
    				function Clockon()
    				{
    					var now=new Date();
    					var year=now.getFullYear(); //getFullYear getYear
    					var month=now.getMonth();
    					var date=now.getDate();
    					var day=now.getDay();
    					var hour=now.getHours();
    					var minu=now.getMinutes();
    					var sec=now.getSeconds();
    					var week;
    					month=month+1;
    					if(month<10){month="0"+month;}
    					if(date<10){date="0"+date;}
    					if(hour<10){hour="0"+hour;}
    					if(minu<10){minu="0"+minu;}
    					if(sec<10){sec="0"+sec;}
    					var arr_week=new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    					week = arr_week[day];
    					//check_time=year+"/"+month+"/"+date+" "+hour+":"+minu;
    					check_time=year+""+month+""+date+""+hour+""+minu;
    					return {Check_times:check_time};
    					//var timer=setTimeout("clockon()", 200);
    				} 
    				//]]>
    
    				//回调jsonp结果,注jsonpCallback的命名要与txt和ajax请求中jsonp参数名称一致
    				//function jsonpCallback(data) {
    					//var oDiv = document.getElementById("date_check1");
    					//oDiv.innerHTML = data;
    					//var setTime=new Clockon();
    					//if($(date_check1).text()==setTime.Check_times){	
    					//		alert("我的小主,耐心点,数据分析需1~2分钟,请稍后查看!");
    					//		console.log("------------");
    					//		console.log(setTime.Check_times);
    							
    					//}else{	
    
    							//var change_time=$(date_check).text().replace('/','').replace('/','').replace(' ','').replace(':','');
    							//var change_time=change_times.substring(0,10);
    							var change_time=$(date_check1).text();
    							document.getElementById('results_path').innerText="/result/html/Report"+change_time+"/TestReport.html";
    							var cpu="CPU.png";
    							var Mem="Memory.png";
    							var io="IO.png";
    							var network="Network.png";
    							var RTO="ResponseTimesOverTime.png";
    							var TVT="TimesVsThreads.png";
    							var ThroughputVT="ThroughputVsThreads.png";
    							var tps="Trans.png";
    							var hps="HitsPerSecond.png";
    							var BTOT="BytesThroughputOverTime.png";					
    							$("#CPU").attr("src", cpu);
    							$("#Memory").attr("src", Mem);
    							$("#IO").attr("src", io);
    							$("#Network").attr("src", network);
    							$("#ResponseTimesOverTime").attr("src", RTO);
    							$("#TimesVsThreads").attr("src", TVT);
    							$("#ThroughputVsThreads").attr("src", ThroughputVT);
    							$("#TPS").attr("src", tps);
    							$("#HitsPerSecond").attr("src", hps);
    							$("#BytesThroughputOverTime").attr("src", BTOT);
    							console.log("+++++++++++");
    							console.log(change_time);
    						//}
    					//}
    					
    				//ajax跨域获取txt数据
    				//function Get_date() {
    				//		var url = '../../build_conf.txt';
    				//		$.ajax({
    				//			url: url,
    				//			async: false,
    				//			data: '',
    				//			dataType: 'jsonp',
    				//			jsonp: 'jsonpCallback',
    				//			success: function(data) {
    				//				console.log(data);
    				//			},
    				//			error: function(msg) {
    				//				console.log(msg);
    				//			}
    				//		});
    				//	};
    				//	
    				//var txt=new Get_date();	
    
    			//setTime();
    
    	</script>
    	<script language="JavaScript">
    		document.querySelector('#isshow_Key_index').style.display = document.querySelector('#isshow_Keyindex').innerText === '1' ? 'none' : 'block';
    		document.querySelector('#isshow_Key_index1').style.display = document.querySelector('#isshow_Keyindex').innerText === '1' ? 'none' : 'block';
    		document.querySelector('#isshow_Resource_usage').style.display = document.querySelector('#isshow_Resource').innerText === '1' ? 'none' : 'block';
    		document.querySelector('#isshow_Result_log').style.display = document.querySelector('#isshow_Resultlog').innerText === '1' ? 'none' : 'block';
    	</script>
    	
    </xsl:template>
    
    <xsl:template name="pageHeader">
    	<h1><xsl:value-of select="$titleReport" /></h1>
    	<table width="100%">
    		<tr>
    			<!-- 获取requestHeader数据 -->
    			<!-- xsl:variable name="URL" select="/testResults/httpSample/requestHeader" / -->
    			<!-- 从获取的URL中截取数据,第二代表起始位置,第三位代表长度 -->
    			<!-- xsl:variable name="newURL" select="substring($URL, 94, 30)" / --> 
    			<!-- 已换行符来截取,before代表换行符之前的数据 -->
    			<!-- xsl:variable name="remaining" select="substring-before($newURL, '
    ')" / --> 
    			<ul>
    				<li><b>Period:</b> <xsl:value-of select="$start_datetime" /> - <xsl:value-of select="$end_datetime" /></li>
    				<li><b>Results in Session:</b><span id="results_path" align="left"></span></li>
    				<li id="isshow_Result_log"><b>Server Result log:</b><a><xsl:attribute name="href"><xsl:value-of select="$Result_log" /></xsl:attribute><xsl:value-of select="$Result_log" /></a></li>
    			</ul>
    			<td id="date_check" align="left" style="display:none" ><xsl:value-of select="$end_datetime" /></td>
    			<td id="date_check1" align="left" style="display:none" ></td>
    			<!-- request_url表示build.xml中jmeter收集结果服务器请求地址 -->
    			<td id="Request_url" align="left" style="display:none" ><xsl:value-of select="$request_url" /></td>
    			<td style="display:none" align="left" id="isshow_Keyindex" ><xsl:value-of select="$Is_Show_Key_index" /></td> 
    			<td style="display:none" align="left" id="isshow_Resource" ><xsl:value-of select="$Is_Show_Resource" /></td>
    			<td style="display:none" align="left" id="isshow_Resultlog" ><xsl:value-of select="$Is_show_Result_log" /></td>
    			<!--td align="center">Host: <xsl:value-of select="$remaining" /></td>
    			<td align="right"><a href="./TestLog.html">测试日志</a></td -->
    		</tr>
    	</table>
    	<hr width="100%" />
    </xsl:template>
    
    <xsl:template name="Resource">
    	<h2 id="isshow_Resource_usage">Resource usage:<a href="javascript:void(0);" id="show1">show</a></h2> 
    	<div>
    		<div style="display:none" id="img-box1" class="container-fluid">
    			<div class="row">
    				<div class="col-md-6">
    					<ul>
    						<li><h2>CPU</h2></li>
    						<li><img id="CPU"/></li>
    						<li><h2>Memory</h2></li>
    						<li><img id="Memory"/></li>
    					</ul>
    				</div>
    				<div class="col-md-6">
    					<ul>
    						<li><h2>IO</h2></li>
    						<li><img id="IO" /></li>
    						<li><h2>Network</h2></li>
    						<li><img id="Network" /></li>
    					</ul>
    				</div>
    			</div>
    		</div>
    	</div>
    </xsl:template>
    
    
    <xsl:template name="summary">
    	<h2> Transaction Summary【Fail:<span id="failed"></span>】</h2>
    	<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
    		<tr valign="top">
    			<th>Total Transacthion</th>
    			<th>Total Pass</th>
    			<th>Total Fail</th>
    			<th>Passing rate</th>
    			<th>Failure rate</th>
    			<th id="isshow_Key_index">Dedail</th>
    		</tr>
    		<tr valign="top" class="top">
    			<xsl:variable name="allCount" select="count(/testResults/*)" />
    			<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
    			<xsl:variable name="allSuccessCount" select="count(/testResults/*[attribute::s='true'])" />
    			<xsl:variable name="allSuccessPercent" select="$allSuccessCount div $allCount" />
    			<xsl:variable name="allFailurePercent" select="$allFailureCount div $allCount" />
    			<!-- 			
    			<xsl:attribute name="class">
    				<xsl:choose>
    					<xsl:when test="$allFailureCount > 0">Failure</xsl:when>
    				</xsl:choose>
    			</xsl:attribute> 
    			-->
    			<td align="center">
    				<xsl:value-of select="$allCount" />
    			</td>
    			<td align="center">
    				<xsl:value-of select="$allSuccessCount" />
    			</td>
    			<xsl:choose>
    				<xsl:when test="$allFailureCount > 0">
    					<td align="center" style="font-weight:bold;background:red;">
    						<xsl:value-of select="$allFailureCount" />
    					</td>
    				</xsl:when>
    				<xsl:otherwise>
                		<td align="center">
    						<xsl:value-of select="$allFailureCount" />
    					</td>
              		</xsl:otherwise>
    			</xsl:choose>
    			
    			<td align="center">
    				<xsl:call-template name="display-percent">
    					<xsl:with-param name="value" select="$allSuccessPercent" />
    				</xsl:call-template>
    			</td>
    
    			<td align="center">
    				<xsl:choose>
    					<xsl:when test="$allFailurePercent >= $failure_rate ">
    						<xsl:attribute name="class">
    							<xsl:choose>
    								<xsl:when test="$allFailurePercent >= $failure_rate">Failure</xsl:when>
    							</xsl:choose>
    						</xsl:attribute>
    					</xsl:when>					
    				</xsl:choose>
    				<xsl:call-template name="display-percent">
    					<xsl:with-param name="value" select="$allFailurePercent" />
    				</xsl:call-template>			
    			</td>
    			
    			<td align="center" id="isshow_Key_index1">
    				<a href="javascript:void(0);" id="show">show</a>
    			</td>
    		</tr>
    	</table>
    	
    	<div>
    		<div style="display:none" id="img-box" class="container-fluid">
    				<div class="row">
    						<div class="col-md-6">
    						  <ul>
    								<li><h2>ResponseTimesOverTime</h2></li>
    								<li><img id="ResponseTimesOverTime" /></li>
    								<li><h2>TimesVsThreads</h2></li>
    								<li><img id="TimesVsThreads" /></li>
    						  </ul>
    						</div>
    
    					<div class="col-md-6">
    						<ul>
    							<li><h2>ThroughputVsThreads</h2></li>
    							<li><img id="ThroughputVsThreads" /></li>
    							<li><h2>BytesThroughputOverTime</h2></li>
    							<li><img id="BytesThroughputOverTime" /></li>
    						</ul>
    					</div>
    				</div>
    				<div class="row">
    					<div class="col-md-6">
    						<ul>
    							<li><h2>HitsPerSecond</h2></li>
    							<li><img id="HitsPerSecond" /></li>
    						</ul>
    					</div>
    					<div class="col-md-6">
    						<ul>
    							<li><h2>TPS</h2></li>
    							<li><img id="TPS" /></li>
    						</ul>
    					</div>
    				</div>
    		</div>
    	</div>
    </xsl:template>
    
    <xsl:template name="pagelist">
    	<h2> Transaction【Fail:<span id="failed"></span>,Avg:大于3s <span id="yellow_1"></span> 大于5s <span id="orange_1"></span>  大于8s <span id="red_1"></span>,90% line:大于3s <span id="yellow_1"></span>  大于5s <span id="orange_1"></span>  大于8s <span id="red_1"></span>】</h2>
    	<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
    		<tr valign="top">
    			<th>Transacthion Name</th>
    			<th>Transacthion</th>
    			<th>Pass</th>
    			<th>Fail</th>
    			<th>Passing Rate</th>
    			<th>Failure Rate</th>
    			<th>Average Time</th>
    			<th>Min Time</th>
    			<th>Max Time</th>
    			<th>90% Line</th>
    			<th>QPS</th>
    			<th>Dedail</th>
    		</tr>
    		<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]"	>
    			<!-- 按平均时间排序 -->
    			<xsl:sort select="sum(../*[@lb = current()/@lb]/@t) div count(../*[@lb = current()/@lb])" data-type="number" order="descending"/>
    			
    			<xsl:variable name="label" select="@lb" />
    					
    			<!-- 统计所有事务总数 -->			
    			<xsl:variable name="count" select="count(../*[@lb = current()/@lb])" />
    			<!-- 统计执行失败的事务总数 -->
    			<xsl:variable name="ffailureCount" select="../*[@lb = current()/@lb][attribute::s='false']"/>
    			<xsl:variable name="failureCount">	
    				<!--xsl:if test="sting-length(normalize-space($sChorus))=0"-->
    				<xsl:if test="not($ffailureCount)">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<!--xsl:if test="sting-length(normalize-space($sChorus))>0"-->
    				<xsl:if test="$ffailureCount">
    					<xsl:value-of select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
    				</xsl:if>
    			</xsl:variable>
    			<!-- 统计执行成功的事务总数 -->
    			<xsl:variable name="ssuccessCount" select="../*[@lb = current()/@lb][attribute::s='true']"/>
    			<xsl:variable name="successCount">	
    				<!--xsl:if test="sting-length(normalize-space($sChorus))=0"-->
    				<xsl:if test="not($ssuccessCount)">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<!--xsl:if test="sting-length(normalize-space($sChorus))>0"-->
    				<xsl:if test="$ssuccessCount">
    					<xsl:value-of select="count(../*[@lb = current()/@lb][attribute::s='true'])" />
    				</xsl:if>
    			</xsl:variable>
    			
    			<!--xsl:variable name="successPercent" select="$successCount div $count" / -->
    			<xsl:variable name="successPercent">			
    				<xsl:if test="$count = 0">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<xsl:if test="$count > 0">
    					<xsl:value-of select="$successCount div $count" />
    				</xsl:if>
    			</xsl:variable>
    						
    			<xsl:variable name="failurePercent">			
    				<xsl:if test="$count = 0">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<xsl:if test="$count > 0">
    					<xsl:value-of select="$failureCount div $count" />
    				</xsl:if>
    			</xsl:variable>
    			
    			<xsl:variable name="totalTime" select="sum(../*[@lb = current()/@lb][attribute::s='true']/@t)"/>
    			
    			<xsl:variable name="averageTime">			
    				<xsl:if test="$successCount = 0">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<xsl:if test="$successCount > 0">
    					<xsl:value-of select="$totalTime div $successCount" />
    				</xsl:if>
    			</xsl:variable>
    					
    			<xsl:variable name="minTime">
    				<xsl:call-template name="min">
    					<xsl:with-param name="nodes" select="../*[@lb = current()/@lb][attribute::s='true']/@t" />
    				</xsl:call-template>
    			</xsl:variable>
    			
    			<xsl:variable name="maxTime">
    				<xsl:call-template name="max">
    					<xsl:with-param name="nodes" select="../*[@lb = current()/@lb][attribute::s='true']/@t" />
    				</xsl:call-template>
    			</xsl:variable>
    			
    			<!-- new add 90% line time -->
    			<xsl:variable name="nintyTime">
    				<xsl:call-template name="lineTime">
    					<xsl:with-param name="nodes" select="../*[@lb = current()/@lb][attribute::s='true']/@t" />
    				</xsl:call-template>
    			</xsl:variable>
    			
    			<xsl:variable name="qpsTime">			
    				<xsl:if test="$totalTime = 0">
    					<xsl:value-of select="0" />
    				</xsl:if>
    				<xsl:if test="$totalTime > 0">
    					<xsl:value-of select="$successCount * 1000 div $totalTime" />
    				</xsl:if>
    			</xsl:variable>
    			
    			<tr valign="top" class="top">
    				<td align="center">
    					<xsl:if test="$failureCount > 0">
    						<a><xsl:attribute name="href">#<xsl:value-of select="$label" /></xsl:attribute>
    					  		<xsl:value-of select="$label" />
    					  	</a>
    					</xsl:if>
    					<xsl:if test="0 >= $failureCount">
    					  	<xsl:value-of select="$label" />
    					</xsl:if>
    				</td>
    				
    				<td align="center">
    					<xsl:value-of select="$count" />
    				</td>
    				
    				<td align="center">
    					<xsl:value-of select="$successCount" />
    				</td>
    				
    				<td align="center">
    					<xsl:choose>
    						<!-- 失败用例标红显示 -->
    						<xsl:when test="$failureCount > 0">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$failureCount > 0">Failure</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    					</xsl:choose>
    					<xsl:value-of select="$failureCount" />
    				</td>
    				
    				<td align="center">
    					<xsl:call-template name="display-percent">
    						<xsl:with-param name="value" select="$successPercent" />
    					</xsl:call-template>
    				</td>
    				
    				<td align="center">
    					<xsl:choose>
    						<xsl:when test="$failurePercent >= $failure_rate ">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$failurePercent >= $failure_rate">Failure</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>					
    					</xsl:choose>
    					<xsl:call-template name="display-percent">
    						<xsl:with-param name="value" select="$failurePercent" />
    					</xsl:call-template>
    				</td>
    								
    				<td align="center">
    					<xsl:choose>
    						<!-- 平均时间超过8s,显示红色 -->
    						<xsl:when test="$averageTime > 8000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$averageTime > 8000">Time8s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    
    						<!-- 平均时间超过5s,显示橙色 -->
    						<xsl:when test="$averageTime > 5000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$averageTime > 5000">Time5s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    						
    						<!-- 平均时间超过3s,显示黄色 -->
    						<xsl:when test="$averageTime > 3000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$averageTime > 3000">Time3s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    					</xsl:choose>
    					<xsl:call-template name="display-time">
    						<xsl:with-param name="value" select="$averageTime" />
    					</xsl:call-template>
    					
    				</td>
    				<td align="center">
    					<xsl:call-template name="display-time">
    						<xsl:with-param name="value" select="$minTime" />
    					</xsl:call-template>
    				</td>
    				<td align="center" >
    					<xsl:call-template name="display-time">
    						<xsl:with-param name="value" select="$maxTime" />
    					</xsl:call-template>
    				</td>
    				<!-- Page页面添加90% LineTime -->
    				<td align="center">
    					<xsl:choose>
    						<!-- 90%时间超过8s,显示红色 -->
    						<xsl:when test="$nintyTime > 8000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$nintyTime > 8000">NintyTime8s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    						
    						<!-- 90%时间超过5s,显示橙色 -->
    						<xsl:when test="$nintyTime > 5000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$nintyTime > 5000">NintyTime5s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    						
    						<!-- 90%时间超过3s,显示黄色 -->
    						<xsl:when test="$nintyTime > 3000">
    							<xsl:attribute name="class">
    								<xsl:choose>
    									<xsl:when test="$nintyTime > 3000">NintyTime3s</xsl:when>
    								</xsl:choose>
    							</xsl:attribute>
    						</xsl:when>
    					</xsl:choose>
    					
    					<xsl:call-template name="display-time">
    						<xsl:with-param name="value" select="$nintyTime" />
    					</xsl:call-template>
    				</td>
    				<td align="center">
    					<xsl:call-template name="display-qps">
    						<xsl:with-param name="value" select="$qpsTime" />
    					</xsl:call-template>
    				</td>
    				<td align="center">
    				   <a href="" id="" style="display:inline-block; 60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;" ><xsl:attribute name="href"><xsl:text/>javascript:change('page_details_<xsl:value-of select="position()" />')</xsl:attribute>
    				   <xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" />_image</xsl:attribute>show</a>
    				</td>
    			</tr>
    
    			
                <tr class="page_details">
                    <xsl:attribute name="id"><xsl:text/>page_details_<xsl:value-of select="position()" /></xsl:attribute>
                    <td colspan="8" bgcolor="#FF0000">
    	                <div align="center">
    				        <b>Details for Transaction "<xsl:value-of select="$label" />"</b>
    				        <table bordercolor="#000000" bgcolor="#2674A6" border="0"  cellpadding="1" cellspacing="1" width="95%">
    					        <tr>
    					            <th>Thread</th>
    					            <th>Iteration</th>
    					            <th>Time (milliseconds)</th>
    					            <th>Bytes</th>
    					            <th>Pass(true/false)</th>
    					        </tr>					         		         
    					        <xsl:for-each select="../*[@lb = $label and @tn != $label]">
    						    <xsl:variable name="responsetime" select="@t" />
    							<xsl:variable name="failuress" select="@s" />
    					            <tr>
    					               <td align="center"><xsl:value-of select="@tn" /></td>
    					               <td align="center"><xsl:value-of select="position()" /></td>
    					               <td align="center">
    										<xsl:choose>
    										<!-- 时间超过8s,显示红色 -->
    										<xsl:when test="$responsetime > 8000">
    											<xsl:attribute name="id">
    												<xsl:choose>
    													<xsl:when test="$responsetime > 8000">RPSTime8s</xsl:when>
    												</xsl:choose>
    											</xsl:attribute>
    										</xsl:when>
    											
    										<!-- 时间超过5s,显示橙色 -->
    										<xsl:when test="$responsetime > 5000">
    											<xsl:attribute name="id">
    												<xsl:choose>
    													<xsl:when test="$responsetime > 5000">RPSTime5s</xsl:when>
    												</xsl:choose>
    											</xsl:attribute>
    										</xsl:when>
    											
    										<!-- 时间超过3s,显示黄色 -->
    										<xsl:when test="$responsetime > 3000">
    											<xsl:attribute name="id">
    												<xsl:choose>
    													<xsl:when test="$responsetime > 3000">RPSTime</xsl:when>
    												</xsl:choose>
    											</xsl:attribute>
    										</xsl:when>
    											
    									</xsl:choose>
    										<xsl:value-of select="@t" />
    								   </td>
    					               <!--  TODO allow for missing bytes field -->
    					               <td align="center"><xsl:value-of select="@by" /></td>
    					               <td align="center">
    										<xsl:choose>
    											<!-- 失败用例标红显示 -->
    											<xsl:when test="$failuress='false'">
    												<xsl:attribute name="id">
    													<xsl:choose>
    														<xsl:when test="$failuress='false'">failures</xsl:when>
    													</xsl:choose>
    												</xsl:attribute>
    											</xsl:when>
    										</xsl:choose>
    										<xsl:value-of select="@s" />
    								   </td>
    					            </tr>
    					        </xsl:for-each>
    				        </table>
    				    </div>
                   	</td>
                </tr>
    		</xsl:for-each>
    	</table>
    </xsl:template>
    
    <xsl:template name="detail">
    	<xsl:variable name="allFailureCount" select="count(/testResults/*[attribute::s='false'])" />
    
    	<xsl:if test="$allFailureCount > 0">
    		<h2>Transaction Failure Detail:</h2>
    
    		    <xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
    			<xsl:variable name="failureCount" select="count(../*[@lb = current()/@lb][attribute::s='false'])" />
    			<xsl:if test="$failureCount > 0">
    			
    				<h3><xsl:value-of select="@lb" /><a><xsl:attribute name="name"><xsl:value-of select="@lb" /></xsl:attribute></a> :
    				   <a href="" id="" style="display:inline-block; 60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;" ><xsl:attribute name="href"><xsl:text/>javascript:change1('Failure_Detail_<xsl:value-of select="position()" />')</xsl:attribute>
    				   <xsl:attribute name="id"><xsl:text/>Failure_Detail_<xsl:value-of select="position()" />_image</xsl:attribute>show</a> </h3>
    				   
    					<table class="details" bordercolor="#000000" bgcolor="#2674A6" style="display:none;" border="0" cellpadding="1" cellspacing="1" width="95%" align="center" >
    						<xsl:attribute name="id"><xsl:text/>Failure_Detail_<xsl:value-of select="position()" /></xsl:attribute>
    
    						<tr valign="top">
    							<th align="center">Response</th>
    							<th align="center">Failure Message</th>
    							<xsl:if test="$showData = 'y'">
    								<th align="left">Response Data</th>
    							</xsl:if>
    						</tr>
    					
    						<xsl:for-each select="/testResults/*[@lb = current()/@lb][attribute::s='false']">
    							<tr>
    								<td align="center"><xsl:value-of select="@rc | @rs" /> - <xsl:value-of select="@rm" /></td>
    								<td><xsl:value-of select="assertionResult/failureMessage" /></td>
    								<xsl:if test="$showData = 'y'">
    									<td><xsl:value-of select="responseData" /></td>
    								</xsl:if>
    							</tr>
    						</xsl:for-each>	
    					</table>
    
    			</xsl:if>
    
    		</xsl:for-each>
    	</xsl:if>
    </xsl:template>
    
    
    
    <xsl:template name="min">
    	<xsl:param name="nodes" select="/.." />
    	<xsl:choose>
    		<xsl:when test="not($nodes)">0.00</xsl:when>
    		<xsl:otherwise>
    			<xsl:for-each select="$nodes">
    				<xsl:sort data-type="number" />
    				<xsl:if test="position() = 1">
    					<xsl:value-of select="number(.)" />
    				</xsl:if>
    			</xsl:for-each>
    		</xsl:otherwise>
    	</xsl:choose>
    </xsl:template>
    
    <xsl:template name="max">
    	<xsl:param name="nodes" select="/.." />
    	<xsl:choose>
    		<xsl:when test="not($nodes)">0.00</xsl:when>
    		<xsl:otherwise>
    			<xsl:for-each select="$nodes">
    				<xsl:sort data-type="number" order="descending" />
    				<xsl:if test="position() = 1">
    					<xsl:value-of select="number(.)" />
    				</xsl:if>
    			</xsl:for-each>
    		</xsl:otherwise>
    	</xsl:choose>
    </xsl:template>
    
    <!-- 90% line time -->
    <xsl:template name="lineTime">
    	<xsl:param name="nodes" select="/.." />
    	<xsl:choose>
    		<xsl:when test="not($nodes)">0.00</xsl:when>
    		<xsl:otherwise>
    			<xsl:for-each select="$nodes">
    				<xsl:sort data-type="number" />
    				<!-- last() 返回当前上下文中的最后一个节点位置数 -->
    				<!-- ceiling(number) 返回大于number的最小整数 -->
    				<!-- floor(number) 返回不大于number的最大整数 -->
    				<!-- position() 返回当前节点位置的数字 -->
    				<!-- number(object) 使对象转换成数字 -->
    				<xsl:choose>
                        <!-- 当只有一个节点时,向上取整 -->
                        <xsl:when test="last() = 1">
                           	<xsl:if test="position() = ceiling(last()*0.9)">
                                <xsl:value-of select="number(.)" />
                            </xsl:if>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:if test="position() = floor(last()*0.9)">
                                <xsl:value-of select="number(.)" />
                            </xsl:if>
                          </xsl:otherwise>
                    </xsl:choose>
    			</xsl:for-each>
    		</xsl:otherwise>
    	</xsl:choose>
    </xsl:template>
    
    <xsl:template name="display-percent">
    	<xsl:param name="value" />
    	<xsl:value-of select="format-number($value,'0.00%')" />
    </xsl:template>
    
    <xsl:template name="display-time">
    	<xsl:param name="value" />
    	<xsl:value-of select="format-number($value,'0.00 ms')" />
    </xsl:template>
    
    <xsl:template name="display-qps">
    	<xsl:param name="value" />
    	<xsl:value-of select="format-number($value,'0.000 /s')" />
    </xsl:template>
    
    </xsl:stylesheet>
    
  • 相关阅读:
    P1587 [NOI2016]循环之美 杜教筛
    【学习笔记】省选动态规划类型选讲
    【模板】结构体重载高精度
    SP1716 GSS3
    SP1043 GSS1
    P1890 gcd区间 线段树
    【模板】(最小费用)最大流
    【模板】矩阵乘法
    P1073 最优贸易 DFS
    【2019.8.14】2019QB学堂DP图论班第一次考试 Problem C
  • 原文地址:https://www.cnblogs.com/linwenbin/p/10985403.html
Copyright © 2011-2022 走看看