• jmeter+maven+jenkins报告优化(一):添加90% line和QPS


    问题:默认jmeter-results-detail-report_21.xsl报告比较简陋,想要添加一些参数怎么办?

    • 添加90% Line模板

    • <xsl:template name="max">
          <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" 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)">NaN</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>
    • 在Sunmary中添加标题

    • <tr valign="top">
                  <th># Samples</th>
                  <th>Success</th>
                  <th>Failures</th>
                  <th>Success Rate</th>
                  <th>Average Time</th>
                  <th>Min Time</th>
                  <th>Max Time</th>
                  <th>90% Line</th>
                  <th>TPS</th>
      </tr>
    • 在Summary中添加allLineTime和qps变量

    • <xsl:variable name="allMaxTime">
                      <xsl:call-template name="max">
                          <xsl:with-param name="nodes" select="/testResults/*/@t" />
                      </xsl:call-template>
                  </xsl:variable>
                  <!-- 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>
                  <!-- 将毫秒转换成秒 -->
                  <xsl:variable name="qps" select="$allCount * 1000 div $allTotalTime"/>
    • Summary中调用allLineTime和qps变量

    • <td align="center">
                      <xsl:call-template name="display-time">
                          <xsl:with-param name="value" select="$allMaxTime" />
                      </xsl:call-template>
                  </td>
                  <td align="center">
                      <xsl:call-template name="display-time">
                          <xsl:with-param name="value" select="$allLineTime" />
                      </xsl:call-template>
                  </td>
                  <td align="center">
                      <xsl:call-template name="display-qps">
                          <xsl:with-param name="value" select="$qps" />
                      </xsl:call-template>
    • 在pagelist中添加标题

    • <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>
                  <th># Samples</th>
                  <th>Success</th>
                  <th>Failures</th>
                  <th>Success Rate</th>
                  <th>Average Time</th>
                  <th>Min Time</th>
                  <th>Max Time</th>
                  <th>90% Line</th>
                  <th>TPS</th>
                  <th></th>
              </tr>
    • 在pagelist中添加allLineTime和qps变量

    • <xsl:variable name="maxTime">
                      <xsl:call-template name="max">
                          <xsl:with-param name="nodes" select="../*[@lb = current()/@lb]/@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]/@t" />
                      </xsl:call-template>
                  </xsl:variable>
                  <xsl:variable name="qpsTime" select="$count * 1000 div $totalTime"/>
    • pagelist中调用allLineTime和qps变量

    • <td align="right">
                          <xsl:call-template name="display-time">
                              <xsl:with-param name="value" select="$maxTime" />
                          </xsl:call-template>
                      </td>
                      <!-- Page页面添加90% LineTime -->
                      <td align="center">
                          <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>

      最终效果:

    • 附模板下载

    • 链接:https://pan.baidu.com/s/1c3p2vvLxbDivAMxkek582g
      提取码:jqrt

  • 相关阅读:
    C语言 strcat
    C语言 strncpy
    C语言 strcpy
    C语言 main
    可显示Android设备选择列表,并进入指定Android设备Console的Shell脚本
    Android系统如何录制屏幕(录制成mp4格式)
    据说有99%的人都会做错的面试题
    一道淘汰85%面试者的百度开发者面试题
    用Android模拟器也可以开发和测试NFC应用
    一道腾讯面试题的思考:到底谁会赢?
  • 原文地址:https://www.cnblogs.com/greattao/p/12341393.html
Copyright © 2020-2023  润新知