我一直在 JMeter 中运行一系列的 web 服务测试,我想做的是取每个测试返回的平均响应时间的总和。我有办法找到每个测试的平均响应时间,但无法将测试的平均值加在一起。我知道,为了使用 XPath 的 sum() 函数,这些值需要成为节点集的一部分,但是据我所知,一旦我从 XML 中找到平均值,它们就不再是其中的一部分。所以我需要使用 node-set() 函数,但我对 XSLT/XPath 还很陌生,并且不确定如何让事情正常工作。
对此的任何帮助表示赞赏!
这是来自 JMeter 的示例 XML,运行两次迭代:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../style/jmeter-results-detail-report_21.xsl"?>
<testResults version="1.2">
<httpSample t="78" lt="78" ts="1338826079163" s="true" lb="html" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="4418" ng="1" na="1"/>
<httpSample t="31" lt="31" ts="1338826079241" s="true" lb="userRoleRetriever" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="758" ng="1" na="1"/>
<httpSample t="32" lt="32" ts="1338826079272" s="true" lb="UserActivityWSDL" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="2398" ng="1" na="1"/>
<httpSample t="156" lt="125" ts="1338826079304" s="true" lb="SubscriberMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="56434" ng="1" na="1"/>
<httpSample t="31" lt="16" ts="1338826079460" s="true" lb="NetworkMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="33020" ng="1" na="1"/>
<httpSample t="15" lt="15" ts="1338826079507" s="true" lb="AlarmMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="11594" ng="1" na="1"/>
<httpSample t="141" lt="141" ts="1338826079538" s="true" lb="getSubscribers" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="397" ng="1" na="1"/>
<httpSample t="265" lt="234" ts="1338826079679" s="true" lb="getMpegResultsById" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="832927" ng="1" na="1"/>
<httpSample t="15" lt="15" ts="1338826079976" s="true" lb="getOverallSummary" rc="200" rm="OK" tn="vuserver 1-1" dt="text" by="402" ng="1" na="1"/>
<httpSample t="0" lt="0" ts="1338826082663" s="true" lb="html" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="4418" ng="1" na="1"/>
<httpSample t="16" lt="16" ts="1338826082663" s="true" lb="userRoleRetriever" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="758" ng="1" na="1"/>
<httpSample t="15" lt="0" ts="1338826082679" s="true" lb="UserActivityWSDL" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="2398" ng="1" na="1"/>
<httpSample t="32" lt="0" ts="1338826082694" s="true" lb="SubscriberMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="56434" ng="1" na="1"/>
<httpSample t="31" lt="15" ts="1338826082726" s="true" lb="NetworkMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="33020" ng="1" na="1"/>
<httpSample t="16" lt="16" ts="1338826082757" s="true" lb="AlarmMgmtWSDL" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="11594" ng="1" na="1"/>
<httpSample t="250" lt="250" ts="1338826082788" s="true" lb="getSubscribers" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="10536" ng="1" na="1"/>
<httpSample t="15454" lt="15392" ts="1338826083038" s="true" lb="getMpegResultsById" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="2023426" ng="1" na="1"/>
<httpSample t="15" lt="15" ts="1338826098555" s="true" lb="getOverallSummary" rc="200" rm="OK" tn="vuserver 1-2" dt="text" by="402" ng="1" na="1"/>
</testResults>
这是我的 XSLT 中的一个摘录,其中找到了每个测试的平均值。
<xsl:for-each select="/testResults/*[not(@lb = preceding::*/@lb)]">
...
<xsl:variable name="count" select="count(../*[@lb = current()/@lb])" />
<xsl:variable name="totalTime" select="sum(../*[@lb = current()/@lb]/@t)" />
<xsl:variable name="averageTime" select="$totalTime div $count" />
...
</xsl:for-each>
如何将这些平均时间输入节点集中并随后求和?
提前致谢!