xref: /petsc/share/petsc/xml/performance_xml2html.xsl (revision 78945fcaee99765d2411105a1a2e44202294f02a)
1<?xml version="1.0" encoding="UTF-8"?>
2<!--**********************************************************************************
3 *    M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S     *
4 *************************************************************************************
5 *    authors: Koos Huijssen, Christiaan M. Klaij                                    *
6 *************************************************************************************
7 *    content: XML to HTML Transformation script for XML-formatted performance       *
8 *             reports with nested timers.                                           *
9 ***********************************************************************************-->
10<xsl:stylesheet id="rundata_xml2html"
11  version="1.0"
12  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
13  <xsl:output method="html"/>
14
15  <xsl:template match="root[1]">
16    <!-- base html document-->
17    <html>
18      <head>
19        <style type="text/css">
20          *, html { font-family: Verdana, Arial, Helvetica, sans-serif; }
21
22          table
23          {
24            table-layout:fixed;
25          }
26
27          th, td
28          {
29            white-space: nowrap;
30            border: 1px solid black;
31            padding-left: 10px;
32            padding-right: 10px;
33          }
34
35          td.timername, th.timername
36          {
37            white-space: nowrap;
38            overflow: hidden;
39            text-overflow: ellipsis;
40          }
41
42          td.numeric, font.numeric
43          {
44            font-family:Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,Courier New, monospace;
45          }
46
47          ol.tree {
48            padding-left: 15px;
49          }
50
51          ol.tree li {
52            list-style: none;          /* all list item li dots invisible */
53            position: relative;
54            margin-left: -20px;
55          }
56
57          label {
58            cursor: pointer;        /* cursor changes when you mouse over this class */
59          }
60
61          ol.tree td, ol.tree th {
62            border:none;
63            /*border: 1px solid black;*/
64            text-align: left;
65          }
66        </style>
67        <title>PETSc Performance Summary</title>
68        <meta charset="utf-8"/>
69        <script  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
70        <script>jQuery.fn.extend({
71            toggleTree: function (tr, isClicked, init){
72                var that = this;
73                var thattext = that.text();
74                if (!init) thattext = thattext.slice(2);
75                if (isClicked) { that.html("&#9698;&#160;"+thattext); tr.show(); isClicked = false; }
76                else {that.html("&#9655;&#160;"+thattext); tr.hide(); isClicked = true; }
77                this.unbind('click.expandtree');
78                this.bind('click.expandtree',function (){
79                    if (isClicked) { that.html("&#9698;&#160;"+thattext); tr.show(); isClicked = false; }
80                    else {that.html("&#9655;&#160;"+thattext); tr.hide(); isClicked = true; }
81                });
82                return this;
83            }
84        });</script>
85      </head>
86      <body>
87        <!--xsl:variable name="numsiblings">
88          <xsl:value-of select="count(preceding-sibling::root)+count(following-sibling::root)"/>
89        </xsl:variable>
90        <xsl:if test="$numsiblings>0">
91          <xsl:variable name="irank">
92            <xsl:value-of select="count(preceding-sibling::root)"/>
93          </xsl:variable>
94          <h1>Process rank <xsl:value-of select="$irank"/></h1>
95        </xsl:if-->
96        <xsl:apply-templates/>
97      </body>
98    </html>
99  </xsl:template>
100
101  <xsl:template match="root[position()>1]"/>
102
103  <xsl:template match="applicationroot">
104    <!-- application root -->
105    <h2><xsl:value-of select="@desc"/></h2>
106    <table>
107      <xsl:apply-templates/>
108    </table>
109  </xsl:template>
110
111  <xsl:template match="applicationroot/*">
112    <!-- application root elements -->
113    <tr><th align="left"><xsl:value-of select="@desc"/></th><td><xsl:apply-templates/></td></tr>
114  </xsl:template>
115
116  <xsl:template match="runspecification">
117    <!-- run specification -->
118    <h2><xsl:value-of select="@desc"/></h2>
119    <table width="800">
120      <xsl:apply-templates/>
121    </table>
122  </xsl:template>
123
124  <xsl:template match="runspecification/*">
125    <!-- run specification elements -->
126    <tr><th align="left" width="300"><xsl:value-of select="@desc"/></th><td><xsl:apply-templates/></td></tr>
127  </xsl:template>
128
129  <xsl:template match="globalperformance">
130    <!-- global performance -->
131    <h2><xsl:value-of select="@desc"/></h2>
132    <table width="800">
133      <tr><th width="240"></th><th>Max</th><th>Max/Min</th><th>Avg</th><th>Total</th></tr>
134      <xsl:apply-templates/>
135    </table>
136  </xsl:template>
137
138  <xsl:template match="globalperformance/*">
139    <!-- global performance elements -->
140    <tr><th align="left"><xsl:value-of select="@desc"/></th>
141      <td class="numeric"><xsl:value-of select="max"/></td>
142      <td class="numeric"><xsl:value-of select="ratio"/></td>
143      <td class="numeric"><xsl:value-of select="average"/></td>
144      <td class="numeric"><xsl:value-of select="total"/></td>
145    </tr>
146  </xsl:template>
147
148  <xsl:template match="timertree">
149    <!-- timer tree -->
150    <h2><xsl:value-of select="@desc"/>
151      <xsl:if test="totaltime">
152        (time in % of <xsl:value-of select="format-number(totaltime,'####0.##')"/> s, threshold = <xsl:value-of select="format-number(timethreshold,'##0.##')"/> %)
153      </xsl:if>
154    </h2>
155    <xsl:variable name="iroot">
156      <xsl:value-of select="count(preceding::root|ancestor::root)"/>
157    </xsl:variable>
158    <xsl:element name="button">
159      <xsl:attribute name="onclick">setAllExpand<xsl:value-of select="$iroot"/>(true)</xsl:attribute>
160      Expand all
161    </xsl:element>
162    <xsl:element name="button">
163      <xsl:attribute name="onclick">setAllExpand<xsl:value-of select="$iroot"/>(false)</xsl:attribute>
164      Collapse all
165    </xsl:element>
166    <ol class="tree">
167      <xsl:call-template name="treeheader"/>
168      <xsl:apply-templates select="event"/>
169    </ol>
170    <xsl:variable name="eventtreestart">
171      <xsl:value-of select="count(preceding::events|ancestor::events)"/>
172    </xsl:variable>
173    <xsl:variable name="neventtree">
174      <xsl:value-of select="count(descendant::events)"/>
175    </xsl:variable>
176    <script>
177      $(document).ready(function()
178      {
179      <xsl:call-template name="toggleTreeLoop">
180        <xsl:with-param name="i" select="$eventtreestart+1"/>
181        <xsl:with-param name="limit" select="$eventtreestart+$neventtree"/>
182        <xsl:with-param name="expandTree">false</xsl:with-param>
183        <xsl:with-param name="init">true</xsl:with-param>
184      </xsl:call-template>
185      });
186    </script>
187    <script>
188      function setAllExpand<xsl:value-of select="$iroot"/>(expandTree)
189      {
190      <xsl:call-template name="toggleTreeLoop">
191        <xsl:with-param name="i" select="$eventtreestart+1"/>
192        <xsl:with-param name="limit" select="$eventtreestart+$neventtree"/>
193        <xsl:with-param name="expandTree">expandTree</xsl:with-param>
194        <xsl:with-param name="init">false</xsl:with-param>
195      </xsl:call-template>
196      };
197    </script>
198  </xsl:template>
199
200  <xsl:template match="selftimertable">
201    <!-- Self timer table -->
202    <h2><xsl:value-of select="@desc"/>
203      <xsl:if test="totaltime">
204        (time in % of <xsl:value-of select="format-number(totaltime,'####0.00')"/> s)
205      </xsl:if>
206    </h2>
207    <ol class="tree">
208      <xsl:call-template name="selftreeheader"/>
209      <xsl:apply-templates select="event"/>
210    </ol>
211  </xsl:template>
212
213  <xsl:template match="event[events]">
214    <!--tree-->
215    <li>
216      <xsl:variable name="eventtreeid">
217        <xsl:value-of select="count(preceding::events|ancestor::events)+1"/>
218      </xsl:variable>
219      <table width="1130">
220        <tr>
221          <xsl:element name="td">
222            <xsl:attribute name="width">180</xsl:attribute>
223            <xsl:attribute name="class">timername</xsl:attribute>
224            <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
225            <xsl:element name="label">
226              <xsl:attribute name="class">h<xsl:value-of select="$eventtreeid"/></xsl:attribute>
227              <xsl:value-of select="name"/>
228            </xsl:element>
229          </xsl:element>
230          <xsl:call-template name="elemperfresults"/>
231        </tr>
232      </table>
233      <xsl:element name="ol">
234        <xsl:attribute name="class">t<xsl:value-of select="$eventtreeid"/></xsl:attribute>
235        <xsl:apply-templates select="events/event"/>
236      </xsl:element>
237    </li>
238  </xsl:template>
239
240  <xsl:template match="event[not(events)]">
241    <!--end-node-->
242    <xsl:variable name="tm">
243      <xsl:choose>
244        <xsl:when test="time/value">
245          <xsl:value-of select="time/value"/>
246        </xsl:when>
247        <xsl:otherwise>
248          <xsl:value-of select="time/maxvalue"/>
249        </xsl:otherwise>
250      </xsl:choose>
251    </xsl:variable>
252    <xsl:if test="$tm &gt; 0">
253      <li>
254        <table width="1250">
255          <tr>
256            <xsl:element name="td">
257              <xsl:attribute name="width">180</xsl:attribute>
258              <xsl:attribute name="class">timername</xsl:attribute>
259              <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
260              &#160;&#160;&#160;&#160;<xsl:value-of select="name"/>
261            </xsl:element>
262            <xsl:call-template name="elemperfresults"/>
263          </tr>
264        </table>
265      </li>
266     </xsl:if>
267  </xsl:template>
268
269  <xsl:template name="treeheader">
270    <li>
271      <table width="1250">
272        <tr>
273          <th width="210" class="timername">&#160;&#160;&#160;Name</th>
274          <th width="190">Time (%)</th>
275          <th width="220"><font color="red" face="TrueType">Calls/parent call</font></th>
276          <th width="220"><font color="blue" face="TrueType">Compute (Mflops)</font></th>
277          <th width="220"><font color="green" face="TrueType">Transfers (MiB/s)</font></th>
278          <th width="190"><font color="magenta" face="TrueType">Reductions/s</font></th>
279        </tr>
280      </table>
281    </li>
282  </xsl:template>
283
284  <xsl:template name="elemperfresults">
285    <td class="numeric" width="190">
286      <xsl:call-template name="printperfelem_prct">
287        <xsl:with-param name="varname" select="time"/>
288      </xsl:call-template>
289    </td>
290    <td width="220"><font color="red" class="numeric">
291      <xsl:call-template name="printperfelem_calls">
292        <xsl:with-param name="varname" select="ncalls"/>
293      </xsl:call-template>
294    </font></td>
295    <td width="220"><font color="blue" class="numeric">
296      <xsl:call-template name="printperfelem">
297        <xsl:with-param name="varname" select="mflops"/>
298      </xsl:call-template>
299    </font></td>
300    <td width="220"><font color="green" class="numeric">
301      <xsl:call-template name="printperfelem">
302        <xsl:with-param name="varname" select="mbps"/>
303      </xsl:call-template>
304    </font></td>
305    <td width="220"><font color="magenta" class="numeric">
306      <xsl:call-template name="printperfelem">
307        <xsl:with-param name="varname" select="nreductsps"/>
308      </xsl:call-template>
309    </font></td>
310  </xsl:template>
311
312  <xsl:template match="selftimertable/event">
313    <xsl:variable name="tm1">
314      <xsl:choose>
315        <xsl:when test="time/value">
316          <xsl:value-of select="time/value"/>
317        </xsl:when>
318        <xsl:otherwise>
319          <xsl:value-of select="time/maxvalue"/>
320        </xsl:otherwise>
321      </xsl:choose>
322    </xsl:variable>
323    <xsl:if test="$tm1 &gt; 0">
324      <li>
325        <table width="1030">
326          <tr>
327            <xsl:element name="td">
328              <xsl:attribute name="width">180</xsl:attribute>
329              <xsl:attribute name="class">timername</xsl:attribute>
330              <xsl:attribute name="title"><xsl:value-of select="name"/></xsl:attribute>
331              &#160;&#160;&#160;<xsl:value-of select="name"/>
332            </xsl:element>
333            <td class="numeric" width="190">
334              <xsl:call-template name="printperfelem_prct">
335                <xsl:with-param name="varname" select="time"/>
336              </xsl:call-template>
337            </td>
338            <td width="220"><font color="blue" class="numeric">
339              <xsl:call-template name="printperfelem">
340                <xsl:with-param name="varname" select="mflops"/>
341              </xsl:call-template>
342            </font></td>
343            <td width="220"><font color="green" class="numeric">
344              <xsl:call-template name="printperfelem">
345                <xsl:with-param name="varname" select="mbps"/>
346              </xsl:call-template>
347            </font></td>
348            <td width="220"><font color="magenta" class="numeric">
349              <xsl:call-template name="printperfelem">
350                <xsl:with-param name="varname" select="nreductsps"/>
351              </xsl:call-template>
352            </font></td>
353          </tr>
354        </table>
355      </li>
356    </xsl:if>
357  </xsl:template>
358
359  <xsl:template name="selftreeheader">
360    <li>
361      <table width="1030">
362        <tr>
363          <th width="210" class="timername">&#160;&#160;&#160;Name</th>
364          <th width="190">Time (%)</th>
365          <th width="220"><font color="blue" face="TrueType">Compute (Mflops)</font></th>
366          <th width="220"><font color="green" face="TrueType">Transfers (MiB/s)</font></th>
367          <th width="190"><font color="magenta" face="TrueType">Reductions/s</font></th>
368        </tr>
369      </table>
370    </li>
371  </xsl:template>
372
373  <xsl:template name="append-pad">
374    <xsl:param name="string"/>
375    <xsl:param name="appendchar"/>
376    <xsl:param name="length"/>
377    <xsl:choose>
378      <xsl:when test="string-length($string) &lt; $length">
379        <xsl:call-template name="append-pad">
380          <xsl:with-param name="string" select="concat($appendchar,$string)"/>
381          <xsl:with-param name="appendchar" select="$appendchar"/>
382          <xsl:with-param name="length" select="$length"/>
383        </xsl:call-template>
384      </xsl:when>
385      <xsl:otherwise>
386        <xsl:value-of select="substring($string,1,$length)"/>
387      </xsl:otherwise>
388      </xsl:choose>
389  </xsl:template>
390
391  <xsl:template name="printperfelem_prct">
392    <xsl:param name="varname"/>
393    <xsl:if test="$varname">
394      <xsl:choose>
395        <xsl:when test="$varname/value">
396          &#160;&#160;&#160;&#160;
397          <xsl:call-template name="append-pad">
398            <xsl:with-param name="string" select="format-number($varname/value,'##0')"/>
399            <xsl:with-param name="appendchar" select="'&#160;'"/>
400            <xsl:with-param name="length" select="2"/>
401          </xsl:call-template>
402        </xsl:when>
403        <xsl:when test="$varname/minvalue">
404          <xsl:call-template name="append-pad">
405            <xsl:with-param name="string" select="format-number($varname/minvalue,'##0')"/>
406            <xsl:with-param name="appendchar" select="'&#160;'"/>
407            <xsl:with-param name="length" select="2"/>
408          </xsl:call-template>
409          -
410          <xsl:if test="$varname/avgvalue">
411            <xsl:call-template name="append-pad">
412              <xsl:with-param name="string" select="format-number($varname/avgvalue,'##0')"/>
413              <xsl:with-param name="appendchar" select="'&#160;'"/>
414              <xsl:with-param name="length" select="2"/>
415            </xsl:call-template>
416            -
417          </xsl:if>
418          <xsl:call-template name="append-pad">
419            <xsl:with-param name="string" select="format-number($varname/maxvalue,'##0')"/>
420            <xsl:with-param name="appendchar" select="'&#160;'"/>
421            <xsl:with-param name="length" select="2"/>
422          </xsl:call-template>
423        </xsl:when>
424      </xsl:choose>
425    </xsl:if>
426  </xsl:template>
427
428  <xsl:template name="printperfelem">
429    <xsl:param name="varname"/>
430    <xsl:if test="$varname">
431      <xsl:choose>
432        <xsl:when test="$varname/value">
433          &#160;&#160;&#160;&#160;&#160;&#160;
434          <xsl:call-template name="append-pad">
435            <xsl:with-param name="string" select="format-number($varname/value,'####0')"/>
436            <xsl:with-param name="appendchar" select="'&#160;'"/>
437            <xsl:with-param name="length" select="4"/>
438          </xsl:call-template>
439        </xsl:when>
440        <xsl:when test="$varname/minvalue">
441          <xsl:call-template name="append-pad">
442            <xsl:with-param name="string" select="format-number($varname/minvalue,'####0')"/>
443            <xsl:with-param name="appendchar" select="'&#160;'"/>
444            <xsl:with-param name="length" select="4"/>
445          </xsl:call-template>
446          -
447          <xsl:if test="$varname/avgvalue">
448            <xsl:call-template name="append-pad">
449              <xsl:with-param name="string" select="format-number($varname/avgvalue,'####0')"/>
450            <xsl:with-param name="appendchar" select="'&#160;'"/>
451              <xsl:with-param name="length" select="4"/>
452            </xsl:call-template>
453            -
454          </xsl:if>
455          <xsl:call-template name="append-pad">
456            <xsl:with-param name="string" select="format-number($varname/maxvalue,'####0')"/>
457            <xsl:with-param name="appendchar" select="'&#160;'"/>
458            <xsl:with-param name="length" select="4"/>
459          </xsl:call-template>
460        </xsl:when>
461      </xsl:choose>
462    </xsl:if>
463  </xsl:template>
464
465  <xsl:template name="printperfelem_calls">
466    <xsl:param name="varname"/>
467    <xsl:if test="$varname">
468      <xsl:choose>
469        <xsl:when test="$varname/value">
470          &#160;&#160;&#160;&#160;&#160;&#160;
471          <xsl:call-template name="append-pad">
472            <xsl:with-param name="string" select="format-number($varname/value,'####0.00')"/>
473            <xsl:with-param name="appendchar" select="'&#160;'"/>
474            <xsl:with-param name="length" select="4"/>
475          </xsl:call-template>
476        </xsl:when>
477        <xsl:when test="$varname/minvalue">
478          <xsl:call-template name="append-pad">
479            <xsl:with-param name="string" select="format-number($varname/minvalue,'####0.00')"/>
480            <xsl:with-param name="appendchar" select="'&#160;'"/>
481            <xsl:with-param name="length" select="4"/>
482          </xsl:call-template>
483          -
484          <xsl:if test="$varname/avgvalue">
485            <xsl:call-template name="append-pad">
486              <xsl:with-param name="string" select="format-number($varname/avgvalue,'####0.00')"/>
487            <xsl:with-param name="appendchar" select="'&#160;'"/>
488              <xsl:with-param name="length" select="4"/>
489            </xsl:call-template>
490            -
491          </xsl:if>
492          <xsl:call-template name="append-pad">
493            <xsl:with-param name="string" select="format-number($varname/maxvalue,'####0.00')"/>
494            <xsl:with-param name="appendchar" select="'&#160;'"/>
495            <xsl:with-param name="length" select="4"/>
496          </xsl:call-template>
497        </xsl:when>
498      </xsl:choose>
499    </xsl:if>
500  </xsl:template>
501
502  <xsl:template name="toggleTreeLoop">
503    <xsl:param name="i"/>
504    <xsl:param name="limit"/>
505    <xsl:param name="expandTree"/>
506    <xsl:param name="init"/>
507    <xsl:if test="$i &lt;= $limit">
508      $(".h<xsl:value-of select="$i"/>").toggleTree($(".t<xsl:value-of select="$i"/>"),<xsl:value-of select="$expandTree"/>,<xsl:value-of select="$init"/>)
509      <xsl:call-template name="toggleTreeLoop">
510        <xsl:with-param name="i" select="$i+1"/>
511        <xsl:with-param name="limit" select="$limit"/>
512        <xsl:with-param name="expandTree" select="$expandTree"/>
513        <xsl:with-param name="init" select="$init"/>
514      </xsl:call-template>
515    </xsl:if>
516  </xsl:template>
517
518</xsl:stylesheet>
519