public static int classId=0; public static HashMap classMap = new HashMap(); public static int methodId=0; public static HashMap methMap = new HashMap(); public static HashMap classForMethod = new HashMap(); public static String className=null; public static int ticket=1; public static int stackdepth=0; public static boolean printHeader=true; public static String languageType="Web Service"; public static FileOutputStream outputStream; public static File file = new File("d:\\webService_"+DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(new Date()).replace(' ', '_').replace(':', '_').replace(',','_')+".trcxml"); if(meth.equals("getTransportForURL") && args[0] != null) { Object name = args[0]; className = name.toString(); if(classMap.get(className) != null) return; classMap.put(className, String.valueOf(classId)); if(printHeader) { String timeStamp = Long.toString(System.currentTimeMillis()); int splitPoint = timeStamp.length() - 3; String timeStr = timeStamp.substring(0, splitPoint) + "." + timeStamp.substring(splitPoint); printHeader = false; StringBuffer header = new StringBuffer(); header.append("<?xml version=\"1.0\"?>").append("\n") .append("<TRACE>").append("\n") .append("<node nodeId=\"Web Service\" hostname=\"localhost\" time=\"").append(timeStr).append("\"/>").append("\n") .append("<processCreate processId=\"webServices\" pid=\"1\" nodeIdRef=\"WebServices\" time=\"").append(timeStr).append("\"/>").append("\n") .append("<agentCreate agentId=\"1\" processIdRef=\"1\" agentName=\"WebServices Profiling Agent\" agentType=\"Profiler\" time=\"").append(timeStr).append("\"/>").append("\n") .append("<traceStart traceId=\"1\" agentIdRef=\"1\" time=\"").append(timeStr).append("\" language=\"").append(languageType).append("\" />").append("\n") .append("<threadStart threadId=\"1\" threadName=\"Execution\" time=\"").append(timeStr).append("\"/>"); if(file.exists()) file.delete(); try { file.createNewFile(); outputStream = new FileOutputStream(file); outputStream.write(header.toString().getBytes()); } catch(Exception exc) { exc.printStackTrace(); } } String timeStamp1 = Long.toString(System.currentTimeMillis()); int splitPoint1 = timeStamp1.length() - 3; String timeStr1 = timeStamp1.substring(0, splitPoint1) + "." + timeStamp1.substring(splitPoint1); String str = "<classDef threadIdRef=\"1\" name=\"" + args[0] + "\"" + " timestamp=\"" + timeStr1 + "\"" + " classId=\"" + classId + "\"" + " />\n"; try { outputStream.write(str.getBytes()); } catch(Exception exc) { exc.printStackTrace(); } classId++; return; } else if (meth.equals("setOperation")) { String methName = args[0].toString().trim(); methName = methName.substring(methName.indexOf("name:")+5).trim(); int idx=methName.indexOf("\n"); if(idx!=-1) methName=methName.substring(0, idx); if(methMap.get(methName) != null) return;//already declared Object clsId = classMap.get(className); methMap.put(methName, String.valueOf(methodId)); classForMethod.put(String.valueOf(methodId), String.valueOf(clsId)); String timeStamp1 = Long.toString(System.currentTimeMillis()); int splitPoint1 = timeStamp1.length() - 3; String timeStr1 = timeStamp1.substring(0, splitPoint1) + "." + timeStamp1.substring(splitPoint1); String str = "<methodDef name=\"" + methName + "\"" + " timestamp=\"" + timeStr1 + "\"" + " methodId=\"" + methodId + "\"" + " classIdRef=\"" + clsId + "\"" + " />\n"; try { outputStream.write(str.getBytes()); } catch(Exception exc) { exc.printStackTrace(); } methodId++; return; } if(!meth.equals("invoke")) return; if(args != null && args.length > 0l) { for(int idx=0; idx<args.length; idx++) { if(args[idx] == null || !(args[idx] instanceof String)) continue; String methName = args[idx].toString(); if(methName.startsWith("http:")) continue; Object methIdRef=methMap.get(methName); if(methIdRef != null) { Object clsId = classForMethod.get(methIdRef.toString()); if(clsId != null) { long sysTime = System.currentTimeMillis(); String timeStamp1 = Long.toString(sysTime); int splitPoint1 = timeStamp1.length() - 3; String timeStr1 = timeStamp1.substring(0, splitPoint1) + "." + timeStamp1.substring(splitPoint1); String str = "<methodEntry threadIdRef=\"" + 1 + "\" time=\"" + timeStr1 + "\" methodIdRef=\"" + methIdRef + "\" classIdRef=\"" + clsId + "\" ticket=\"" + (ticket++) + "\" stackDepth=\"" + (stackdepth++)+ "\" />\n"; try { outputStream.write(str.getBytes()); } catch(Exception exc) { exc.printStackTrace(); } } } } } if(!meth.equals("invoke")) return; if(args != null && args.length > 0l) { for(int idx=0; idx<args.length; idx++) { if(args[idx] == null || !(args[idx] instanceof String)) continue; String methName = args[idx].toString(); if(methName.startsWith("http:")) continue; Object methIdRef=methMap.get(methName); if(methIdRef != null) { Object clsId = classForMethod.get(methIdRef.toString()); if(clsId != null) { String timeStamp = Long.toString(System.currentTimeMillis()); int splitPoint = timeStamp.length() - 3; timeStamp = timeStamp.substring(0, splitPoint) + "." + timeStamp.substring(splitPoint); String str = "<methodExit threadIdRef=\"" + 1 + "\" time=\"" + timeStamp + "\" methodIdRef=\"" + methIdRef + "\" classIdRef=\"" + clsId + "\"/>\n"; try { outputStream.write(str.getBytes()); } catch(Exception exc) { exc.printStackTrace(); } stackdepth--; } } } }