@Override public void encode(MessageTree tree, ChannelBuffer buf) { Message message = tree.getMessage(); if (message instanceof Transaction) { int count = 0; int index = buf.writerIndex(); BufferHelper helper = m_bufferHelper; Transaction t = (Transaction) message; Locator locator = new Locator(); Ruler ruler = new Ruler((int) t.getDurationInMicros()); ruler.setWidth(1400); ruler.setHeight(18 * calculateLines(t) + 10); ruler.setOffsetX(200); ruler.setOffsetY(10); buf.writeInt(0); // place-holder count += helper.table1(buf); count += helper.crlf(buf); count += encodeHeader(tree, buf, ruler); count += encodeRuler(buf, locator, ruler); count += encodeTransaction(tree, t, buf, locator, ruler); count += encodeFooter(tree, buf); count += helper.table2(buf); buf.setInt(index, count); } }
protected int encodeTransactionLine( MessageTree tree, Transaction t, ChannelBuffer buf, Locator locator, Ruler ruler) { BufferHelper helper = m_bufferHelper; XmlBuilder b = new XmlBuilder(); int width = 6; int height = 18; int x = 0; int y = locator.getLine() * height + ruler.getOffsetY(); String tid = "t" + locator.getLine(); long t0 = tree.getMessage().getTimestamp(); long t1 = t.getTimestamp(); int rx = ruler.calcX((t1 - t0) * 1000); int rw = ruler.calcWidth(t.getDurationInMicros() * 1000); int[] segments = getTransactionDurationSegments(t); b.branch(locator, x, y, width, height); x += locator.getLevel() * width; if (t.getStatus().equals("0")) { b.tag1("text", "x", x, "y", y - 5, "font-weight", "bold", "stroke-width", "0"); } else { b.tag1("text", "x", x, "y", y - 5, "font-weight", "bold", "stroke-width", "0", "fill", "red"); } b.add(t.getType()).newLine(); b.tag( "set", "attributeName", "fill", "to", "red", "begin", tid + ".mouseover", "end", tid + ".mouseout"); b.tag2("text"); if (segments == null) { String durationInMillis = String.format("%.2f %s", t.getDurationInMicros() / 1000.0, t.getName()); b.tag( "rect", "x", rx + 1, "y", y - 15, "width", rw, "height", height - 2, "fill", "#0066ff", "opacity", "0.5"); b.tagWithText( "text", durationInMillis, "x", rx + 5, "y", y - 3, "font-size", "11", "stroke-width", "0"); } else { int index = 0; for (int segment : segments) { int w = ruler.calcWidth(segment); String durationInMillis = String.format("%.2f %s", segment / 1000.0 / 1000.0, index == 0 ? t.getName() : ""); String color = m_colors[index % m_colors.length]; b.tag( "rect", "x", rx + 1, "y", y - 15, "width", w, "height", height - 2, "fill", color, "opacity", "0.5"); b.tagWithText( "text", durationInMillis, "x", rx + 5, "y", y - 3, "font-size", "11", "stroke-width", "0"); index++; rx += w; } } b.tag( "rect", "id", tid, "x", ruler.getOffsetX() + 1, "y", y - 15, "width", ruler.getWidth(), "height", height, "fill", "#ffffff", "stroke-width", "0", "opacity", "0.01"); return helper.write(buf, b.getResult().toString()); }