1 package net.sf.saxon.trace; 2 import net.sf.saxon.expr.XPathContext; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.style.StandardNames; 5 6 9 10 public class TimedTraceListener implements TraceListener { 11 12 15 16 public void open() { 17 System.err.println("<trace time=\"" + System.currentTimeMillis() + "\">"); 18 } 19 20 23 24 public void close() { 25 System.err.println("<end time=\"" + System.currentTimeMillis() 26 + "\"/></trace>"); 27 } 28 29 32 33 public void enter(InstructionInfo instruction, XPathContext context) { 34 int loc = instruction.getConstructType(); 35 if (loc == StandardNames.XSL_FUNCTION || loc == StandardNames.XSL_TEMPLATE) { 36 String tag = "<"; 37 tag += (loc==StandardNames.XSL_FUNCTION ? "function" : "template"); 38 String name = null; 39 if (instruction.getObjectNameCode() != -1) { 40 name = context.getController().getNamePool().getDisplayName(instruction.getObjectNameCode()); 41 } else if (instruction.getProperty("name") != null) { 42 name = instruction.getProperty("name").toString(); 43 } 44 if (name != null) { 45 tag += " name=\"" + name + "\""; 46 } 47 if (instruction.getProperty("match") != null) { 48 tag += " match=\"" + instruction.getProperty("match") + "\""; 49 } 50 String file = instruction.getSystemId(); 51 if (file != null) { 52 if (file.length()>15) { 53 file="*" + file.substring(file.length()-14); 54 } 55 tag += " file=\"" + file + "\""; 56 } 57 tag += " line=\"" + instruction.getLineNumber() + "\""; 58 tag += " time=\"" + System.currentTimeMillis() + "\""; 59 tag += ">"; 60 System.err.println(tag); 61 } 62 } 63 64 67 68 public void leave(InstructionInfo instruction) { 69 int loc = instruction.getConstructType(); 70 if (loc == StandardNames.XSL_FUNCTION || loc == StandardNames.XSL_TEMPLATE) { 71 String tag = "<end time=\"" + System.currentTimeMillis() + "\"/></"; 72 tag += (loc==StandardNames.XSL_FUNCTION ? "function>" : "template>"); 73 System.err.println(tag); 74 } 75 } 76 77 80 81 public void startCurrentItem(Item item) {} 82 83 86 87 public void endCurrentItem(Item item) {} 88 89 } 90 91 92 | Popular Tags |