xml - Converting average response times to a summable node-set -
i've been running series of webservice tests in jmeter, , i'd take total sum of average response times returned each test. have way find average response times each test, no way add averages tests together. aware in order use xpath's sum() function values need part of node-set, understand once find average values out of xml no longer part of one. need use node-set() function, new xslt/xpath , unsure how things working.
any appreciated!
this sample xml jmeter running 2 iterations:
<?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> this exerpt in xslt averages each test found.
<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> how can enter these average times node-set , subsequently sum them?
here example of final reports interested
thanks in advance!
if can use xslt2.0, has built-in functionality handle node-sets, whereas in xslt1.0 have make use of extension function. means of node-set, can create variable, holds list of (newly created) nodes, , can iterate on them, or sum them, if source document itself.
another thing note before showing solution, example of grouping problem. have results multiple tests, , want group them name. method using not efficient. in xslt2.0 though there xsl:for-each-group function make things easier
<xsl:for-each-group select="httpsample" group-by="@lb"> what need do, created variable, , build new node set grouping test results, , adding 'average' node new list.
<xsl:variable name="results"> <xsl:for-each-group select="httpsample" group-by="@lb"> <xsl:variable name="count" select="count(current-group())"/> <xsl:variable name="totaltime" select="sum(current-group()/@t)"/> <test lb="{current-grouping-key()}" num="{$count}" tot="{$totaltime}" avg="{$totaltime div $count}"/> </xsl:for-each-group> </xsl:variable> thus, results variable here contain list of test elements, 1 each distinct test, newly appended node having average time. can iterate on these results , sum them.
here full xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="html" indent="yes"/> <xsl:template match="/testresults"> <xsl:variable name="results"> <xsl:for-each-group select="httpsample" group-by="@lb"> <xsl:variable name="count" select="count(current-group())"/> <xsl:variable name="totaltime" select="sum(current-group()/@t)"/> <test lb="{current-grouping-key()}" num="{$count}" tot="{$totaltime}" avg="{$totaltime div $count}"/> </xsl:for-each-group> </xsl:variable> <table> <tr> <th>test</th> <th>total test</th> <th>total time</th> <th>average time</th> </tr> <xsl:for-each select="$results/test"> <tr> <td> <xsl:value-of select="@lb"/> </td> <td> <xsl:value-of select="@num"/> </td> <td> <xsl:value-of select="@tot"/> </td> <td> <xsl:value-of select="@avg"/> </td> </tr> </xsl:for-each> <tr> <td>total</td> <td> <xsl:value-of select="sum($results/test/@num)"/> </td> <td> <xsl:value-of select="sum($results/test/@tot)"/> </td> <td> <xsl:value-of select="sum($results/test/@avg)"/> </td> </tr> </table> </xsl:template> </xsl:stylesheet> when applied xml sample, following output
<table> <tr> <th>test</th> <th>total test</th> <th>total time</th> <th>average time</th> </tr> <tr> <td>html</td> <td>2</td> <td>78</td> <td>39</td> </tr> <tr> <td>userroleretriever</td> <td>2</td> <td>47</td> <td>23.5</td> </tr> <tr> <td>useractivitywsdl</td> <td>2</td> <td>47</td> <td>23.5</td> </tr> <tr> <td>subscribermgmtwsdl</td> <td>2</td> <td>188</td> <td>94</td> </tr> <tr> <td>networkmgmtwsdl</td> <td>2</td> <td>62</td> <td>31</td> </tr> <tr> <td>alarmmgmtwsdl</td> <td>2</td> <td>31</td> <td>15.5</td> </tr> <tr> <td>getsubscribers</td> <td>2</td> <td>391</td> <td>195.5</td> </tr> <tr> <td>getmpegresultsbyid</td> <td>2</td> <td>15719</td> <td>7859.5</td> </tr> <tr> <td>getoverallsummary</td> <td>2</td> <td>30</td> <td>15</td> </tr> <tr> <td>total</td> <td>18</td> <td>16593</td> <td>8296.5</td> </tr> </table>
Comments
Post a Comment