##
## Licensed to the Apache Software Foundation (ASF) under one
## or more contributor license agreements.  See the NOTICE file
## distributed with this work for additional information
## regarding copyright ownership.  The ASF licenses this file
## to you under the Apache License, Version 2.0 (the
## "License"); you may not use this file except in compliance
## with the License.  You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

## Common macros for avro trace

#macro( printNode $collection_id $stats $depth )
<tr>
<td>
#foreach ( $num in [0..$depth] )
  &nbsp;
#end
<a href="/collection/$collection_id/$stats.hashCode()">$stats.MessageName</a>
</td>
<td><strong>$stats.getAverageTime($stats.getTraceTimings())</strong></td>
<td>($stats.getMinTime($stats.getTraceTimings())</td>
<td>- $stats.getMaxTime($stats.getTraceTimings()))</td>
<td><strong>$stats.getAverageBytes($stats.getRequestPayloads())</strong></td>
<td>($stats.getMinBytes($stats.getRequestPayloads())</td>
<td>- $stats.getMaxBytes($stats.getRequestPayloads()))</td>
<td><strong>$stats.getAverageBytes($stats.getResponsePayloads())</strong></td>
<td>($stats.getMinBytes($stats.getResponsePayloads())</td>
<td>- $stats.getMaxBytes($stats.getResponsePayloads()))</td>
</tr>
#set( $depth = $depth + 1 )
#foreach ($child in $stats.Children)
  #printNode( $collection_id $child $depth )
#end
#set( $depth = $depth - 1 )
#end

#macro ( printCollectionSummary $collection )
<table>
  <tr>
    <td> Message </td>
    <td colspan=3>Latency</td>
    <td colspan=3>Request Payload</td>
    <td colspan=3>Response payload</td>
  </tr> 
  #printNode($collection.getExecutionPathHash() $collection.getRootNode() 0)
</table>
<br><br>
#end 

#macro ( printTraceStats $trace )
<table>
  <tr>
    <td> Message </td>
    <td> Client </td>
    <td> Server </td>
    <td> Latency </td>
    <td>Request payload</td>
    <td>Response payload</td>
  </tr> 
  #printTraceNode($trace.getRoot() 0)
</table>
<br><br>
#end 

#macro( printTraceNode $traceNode $depth )
<tr>
<td>
#foreach ( $num in [0..$depth] )
  &nbsp;
#end
$traceNode.getMessageName()
</td>
<td>$traceNode.getRequestorHostname()</td>
<td>$traceNode.getResponderHostname()</td>
<td>$traceNode.getLatencyTimeString()</td>
<td>$traceNode.getRequestPayloadSize()</td>
<td>$traceNode.getRequestPayloadSize()</td>
</tr>
#set( $depth = $depth + 1 )
#foreach ($child in $traceNode.Children)
  #printTraceNode( $child $depth )
#end
#set( $depth = $depth - 1 )
#end


#macro ( mediaIncludes )
<script type="text/javascript" src="/static/protovis-r3.2.js"></script>
<script type="text/javascript" src="/static/avrotrace.js"></script>
<script type="text/javascript" src="/static/tipsy.js"></script>
<script src="static/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="static/jquery.tipsy.js" type="text/javascript"></script>
<script src="static/tipsy.js" type="text/javascript"></script>
<link href="static/tipsy.css" type="text/css" rel="stylesheet"/>
<script src="static/avro.js" type="text/javascript"></script>
<link href="static/avro.css" type="text/css" rel="stylesheet"/>
#end
