Jmeter Html 报告中添加90% line time

首先上效果图:

其次明白几个原理:

  1. 90% Line的意思是:一组数由小到大进行排列,找到它的第90%个数;
  2. Jmeter html报告生成是使用xxx.jtl文件通过xsl模板生成的,因此要在html报告中显示90% line,就需要修改xsl模板文件(jmeter-results-detail-report_21.xsl)

最后上步骤:
1、在jmeter-results-detail-report_21.xsl添加xsl template,可以放在max template模板下面,如下

<!-- 90% line time -->
<xsl:template name="lineTime">
        <xsl:param name="nodes" select="/.." />
	<xsl:choose>
		<xsl:when test="not($nodes)">NaN</xsl:when>
		<xsl:otherwise>
			<xsl:for-each select="$nodes">
				<xsl:sort data-type="number" />
				<!-- last() 返回当前上下文中的最后一个节点位置数 -->
				<!-- floor(number) 返回不大于number的最大整数 -->
				<!-- position() 返回当前节点位置的数字 -->
				<!-- number(object) 使对象转换成数字 -->
				<xsl:if test="position() = floor(last()*0.9)">
					<xsl:value-of select="number(.)" />
				</xsl:if>
			</xsl:for-each>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

2、在Summary中添加90% Line

<xsl:template name="summary">
	<h2>Summary</h2>
	<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
        <tr valign="top">
            <th># Samples</th>
            ...省略N行,添加总结框中的90% Line标题...
            <th>90% Line</th>
        </tr>
            ...省略N行,添加一个xsl变量...
	    <!-- New add 90% line -->
	    <xsl:variable name="allLineTime">
	        <xsl:call-template name="lineTime">
	            <xsl:with-param name="nodes" select="/testResults/*/@t" />
	        </xsl:call-template>
	    </xsl:variable>

            ...省略N行,在表格中显示数字...
            <td align="center">
                <xsl:call-template name="display-time">
                    <xsl:with-param name="value" select="$allLineTime" />
                </xsl:call-template>
            </td>

3、在pagelist中添加90% Line

<xsl:template name="pagelist">
	<h2>Pages</h2>
	<table align="center" class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
                <tr valign="top">
                    <th>URL</th>
	            ...省略N行,添加Pages中的90% Line标题...
                    <th>90% Line</th>
	            <th></th>
                ...省略N行,添加一个xsl变量...
                <!-- new add 90% line time -->
                <xsl:variable name="nintyTime">
                    <xsl:call-template name="lineTime">
                        <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@t" />
                    </xsl:call-template>
                </xsl:variable>
                ...在表格中显示数字...
                <td align="center">
                    <xsl:call-template name="display-time">
                        <xsl:with-param name="value" select="$nintyTime" />
                    </xsl:call-template>
                </td>
posted @ 2016-08-18 17:55  南风_real  阅读(1594)  评论(3编辑  收藏  举报