Created
March 10, 2015 17:11
-
-
Save thvitt/9cc42fe8e0f88f156a66 to your computer and use it in GitHub Desktop.
Summarizes a profiling file as output by xmlcalabash to a sortable HTML table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:f="http://thorstenvitt.de/functions" | |
exclude-result-prefixes="xs" | |
xpath-default-namespace="http://xmlcalabash.com/ns/profile" | |
version="2.0"> | |
<xsl:output method="xhtml" include-content-type="yes"/> | |
<xsl:template match="/"> | |
<html> | |
<head> | |
<title>Calabash Profile Summary</title> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/sortable/0.6.0/js/sortable.min.js"/> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sortable/0.6.0/css/sortable-theme-bootstrap.css"/> | |
</head> | |
<body> | |
<table class="sortable-theme-bootstrap" data-sortable="data-sortable"> | |
<thead> | |
<tr> | |
<th>Type</th> | |
<th>Name</th> | |
<th>File</th> | |
<th>Line</th> | |
<th>Number of Calls</th> | |
<th>Total Step Time</th> | |
<th>Average Step Time</th> | |
</tr> | |
</thead> | |
<xsl:perform-sort> | |
<xsl:sort select="@data-step-time-sum" data-type="number" order="descending"/> | |
<xsl:for-each-group select="//profile" group-by="string-join((@href, @name, @line), ' ')"> | |
<xsl:variable name="step-time-sum" select="sum(current-group()/@step-time[matches(., '\d+')])"/> | |
<xsl:variable name="calls" select="count(current-group())"/> | |
<xsl:for-each select="current-group()[1]"> | |
<tr data-step-time-sum="{$step-time-sum}"> | |
<td title="{@type}"><xsl:value-of select="replace(@type, '\{.*\}', '')"/></td> | |
<td><xsl:value-of select="@name"/></td> | |
<td><a href="{@href}"><xsl:value-of select="replace(@href, '^.*/', '')"/></a></td> | |
<td><xsl:value-of select="@line"/></td> | |
<td><xsl:value-of select="$calls"/></td> | |
<td data-value="{$step-time-sum div 1000}"><xsl:value-of select="f:format-duration(f:fromms($step-time-sum))"/></td> | |
<td data-value="{$step-time-sum div $calls}"><xsl:value-of select="f:format-duration(f:fromms($step-time-sum div $calls))"/></td> | |
</tr> | |
</xsl:for-each> | |
</xsl:for-each-group> | |
</xsl:perform-sort> | |
</table> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:function name="f:fromms"> | |
<xsl:param name="ms"/> | |
<xsl:value-of select="xs:duration(concat('PT', format-number(number($ms) div 1000, '00.000'), 'S'))"/> | |
</xsl:function> | |
<xsl:function name="f:format-duration"> | |
<xsl:param name="duration"/> | |
<xsl:value-of select=" | |
replace(replace(replace(replace($duration, '^PT', ''), 'H', 'h '), 'M', 'min '), 'S', 's ')"/> | |
</xsl:function> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment