Jmeter與ant整合生成美觀的測試報告

        一直以爲Jmeter生成的測試報告很難看,偶爾發現網上用jmeter-results-detail-report_30.xsl整全ant生成了美觀的測試報告,參考https://blog.csdn.net/zouxiongqqq/article/details/71094245javascript

        鑑於對美麗的追求,我決定去嘗試一下。但一入坑,發現問題不少。通過不懈的努力,終於把坑都一一填平了,這裏分享一下經驗。css

  整個測試報告的基本邏輯是;:html

       錄好或者本身編寫jmeter腳本,添加聚合報告、服務器監控、及一些性能監控參數,生成相應的文件放在某個目錄,用ant啓動測試,jmeter數據生成完後,用bat文件將生成的jtl數據生成相應的圖表,而後html把相應的圖表渲染出來。固然能夠考慮將生成圖表的操做也寫入ant中,同時將這些數據移到必定指 定的文件夾中,全部這些均可以交給ant來執行。java

        先上幾張最後的效果圖:node

 

坑一:jquery

build.xml裏面相應的參數應該修改,這裏面須要相應的ant的相關知道,我這裏附上我使用的腳本linux

<?xml version="1.0" encoding="UTF-8"?>
 <project name="ant-jmeter-testing" default="run" basedir=".">  
     <property name="jmeter.home" value="F:\dev\apache-jmeter-5.0" />
     <property name="report.title" value="Performance and interface testing" />
     <property name="jmeter.result.jtl.dir" value="${jmeter.home}\result" />
     <property name="jmeter.result.html.dir" value="${jmeter.home}\result" />
     <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}\extras\jmeter-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>

必須看懂相應的屬性和任務,建立相應的文件夾ajax

 

坑二:shell

原帖做者linux上用的是linux系統,我用的是windows系統,裏面的shell腳本須要轉化爲bat腳本express

echo jmeter_home is %JMETER_HOME%
cd %JMETER_HOME%\result
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl CPU.jtl --plugin-type PerfMon --generate-png CPU.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl Memory.jtl --plugin-type PerfMon --generate-png Memory.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl IO.jtl --plugin-type PerfMon --generate-png IO.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl Network.jtl --plugin-type PerfMon --generate-png Network.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl Trans.jtl --plugin-type TransactionsPerSecond  --generate-png Trans.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl TimesVsThreads.jtl --plugin-type TimesVsThreads   --generate-png TimesVsThreads.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl ResponseTimesOverTime.jtl --plugin-type ResponseTimesOverTime  --generate-png ResponseTimesOverTime.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl ThroughputVsThreads.jtl --plugin-type ThroughputVsThreads  --generate-png ThroughputVsThreads.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl HitsPerSecond.jtl --plugin-type HitsPerSecond  --generate-png HitsPerSecond.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl BytesThroughputOverTime.jtl --plugin-type BytesThroughputOverTime  --generate-png BytesThroughputOverTime.png
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl HitsPerSecond.jtl --plugin-type HitsPerSecond  --generate-csv HitsPerSecond.csv
java -jar %JMETER_HOME%\lib\cmdrunner-2.2.jar --tool Reporter --input-jtl CPU.jtl --plugin-type PerfMon --generate-csv CPU.csv
java -jar %JMETER_HOME%\lib\cmdrunner-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-width: 0px;
				}
				
				.expand_link
				{
				   position=absolute;
				   right: 0px;
				   width: 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;
					width: 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; width:60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
				#show1{ display:inline-block; width:60px; height:22px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
				#yellow_1{ display:inline-block; width:10px; height:10px; line-height:22px; background:yellow; text-align: center; border-radius: 3px; color:#FFF;}
				#red_1{ display:inline-block; width:10px; height:10px; line-height:22px; background:red; text-align: center; border-radius: 3px; color:#FFF;}
				#orange_1{ display:inline-block; width:10px; height:10px; line-height:22px; background:orange; text-align: center; border-radius: 3px; color:#FFF;}
				#failed{ display:inline-block; width: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; width: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; width: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>
相關文章
相關標籤/搜索