Last active
August 29, 2015 14:14
-
-
Save josteinaj/2c43cc3ae43e30c1e791 to your computer and use it in GitHub Desktop.
This file contains 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" exclude-result-prefixes="#all" version="2.0" xmlns="http://www.w3.org/1999/xhtml" | |
xpath-default-namespace="http://xmlcalabash.com/ns/profile" xmlns:profile="http://xmlcalabash.com/ns/profile" xmlns:f="#"> | |
<xsl:output indent="yes"/> | |
<!-- input: calabash profiling xml output --> | |
<!-- output: html view which highlights steps that spends much time --> | |
<!-- change this URI to point to whatever XProc script you want to compare the profiling output against --> | |
<xsl:param name="xpl" select="'file:/home/jostein/nordic-epub3-dtbook-migrator/src/main/resources/xml/xproc/step/epub3-to-html.convert.xpl'"/> | |
<xsl:template match="/*"> | |
<xsl:variable name="profile" select="/*"/> | |
<xsl:variable name="xpl-filename" select="replace($xpl,'.*/','')"/> | |
<xsl:variable name="xpl-profile" select="//*[ends-with(@xpl-href,$xpl-filename)]"/> | |
<xsl:variable name="xpl-total-time" select="max($xpl-profile/xs:integer(@total-time))"/> | |
<xsl:variable name="lines" select="tokenize(unparsed-text($xpl),'\n')"/> | |
<html> | |
<head> | |
<title> | |
<xsl:value-of select="replace($xpl,'.*/','')"/> | |
</title> | |
</head> | |
<body> | |
<h1> | |
<xsl:value-of select="replace($xpl,'.*/','')"/> | |
</h1> | |
<table> | |
<thead> | |
<tr> | |
<th>Time spent</th> | |
<th>Invocations</th> | |
<th>Line</th> | |
<th>Code</th> | |
</tr> | |
</thead> | |
<tbody> | |
<xsl:for-each select="$lines"> | |
<xsl:variable name="line-number" select="position()"/> | |
<xsl:variable name="line" select="."/> | |
<xsl:variable name="total-time" select="sum(for $p in $xpl-profile[@xpl-line = $line-number] return $p/xs:integer((@total-time, @step-time)[1]))"/> | |
<xsl:variable name="intensity" select="f:time-intensity($total-time, $xpl-total-time)"/> | |
<tr style="background-color: rgb(255,{$intensity},{$intensity});"> | |
<td> | |
<xsl:value-of select="$total-time"/> | |
</td> | |
<td> | |
<xsl:value-of select="count($xpl-profile[@xpl-line = $line-number])"/> | |
</td> | |
<td> | |
<xsl:value-of select="$line-number"/> | |
</td> | |
<td> | |
<pre xml:space="preserve"><code><xsl:value-of select="$line"/></code></pre> | |
</td> | |
</tr> | |
</xsl:for-each> | |
</tbody> | |
</table> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:function name="f:time-intensity" as="xs:integer"> | |
<xsl:param name="total-time" as="xs:integer"/> | |
<xsl:param name="xpl-total-time" as="xs:integer"/> | |
<xsl:choose> | |
<xsl:when test="max(($total-time, $xpl-total-time)) = 0"> | |
<xsl:value-of select="255"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="255 - xs:integer(($total-time div max(($total-time, $xpl-total-time))) * 255)"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:function> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment