1 6 7 package analyzer.listeners; 8 9 import java.util.Hashtable ; 10 import java.util.Enumeration ; 11 import java.util.TreeSet ; 12 import java.util.Iterator ; 13 import java.lang.StringBuffer ; 14 15 19 public class TCRAnalyzer extends TCRParser{ 20 21 boolean editorInUse; 22 long editorTime; 23 int tabSwitch, fields, constructors, methods, beanPatterns,tabCounter, maxEditorTabs; 24 Hashtable extensions; 25 public Hashtable windows,editorWindows; 26 public TreeSet sortedWindows; 27 WindowData previousWindow,lastB4OutWindow; 28 public long trashThis; 29 private final String EDITOR_ID="*EDITOR*",OUT="*OUT OF NB*"; 30 WindowData editorSum; 31 32 33 public TCRAnalyzer(String pathAndTS) { 34 super(pathAndTS); 35 } 36 37 protected void init(){ 38 System.out.println("\nAnalyze of the TopComponent.Registry listener output..."); 39 editorInUse = false; 40 windows = new Hashtable (); 41 editorWindows = new Hashtable (); 42 extensions = new Hashtable (); 43 maxEditorTabs=fields=constructors=methods=beanPatterns=tabCounter=tabSwitch=0; 44 45 editorSum=new WindowData(false,EDITOR_ID); 46 windows.put(EDITOR_ID, editorSum); 47 editorSum.chartColor=java.awt.Color.RED; 48 49 WindowData outNB=new WindowData(false,OUT); 50 windows.put(OUT, outNB); 51 outNB.chartColor=java.awt.Color.RED; 52 } 53 54 protected void analyzeNode(String parent, String node){ 55 matchFieldName(parent); 56 matchFieldName(node); 57 } 58 59 protected void analyzeOpen(String windowId, boolean editor){ 60 trashThis=startTime; 61 WindowData w; 62 if(windows.containsKey((Object )windowId)){ 63 w=(WindowData)windows.get((Object )windowId); 64 } else{ 65 w = new WindowData(editor,windowId); 66 windows.put((Object )windowId,w); 67 if(editor){ 68 editorWindows.put((Object )windowId,w); 69 w.chartColor=java.awt.Color.BLUE; 70 tabCounter++; 71 if(tabCounter>maxEditorTabs)maxEditorTabs=tabCounter; 72 extension(windowId); 73 } 74 } 75 w.open(timestamp); 76 } 77 78 protected void analyzeGAINED(){ 79 if(lastB4OutWindow!=null) analyzeActivated(lastB4OutWindow.id,lastB4OutWindow.editor); 80 else if(previousWindow!=null)analyzeActivated(previousWindow.id,previousWindow.editor); 81 } 82 83 protected void analyzeLOST(){ 84 lastB4OutWindow=previousWindow; 85 analyzeActivated(OUT,false); 86 } 87 88 protected void analyzeClose(String windowId, boolean editor){ 89 WindowData w; 90 if(editor)tabCounter--; 91 if(windows.containsKey((Object )windowId)){ 92 w=(WindowData)windows.get((Object )windowId); 93 w.close(timestamp); 94 } else { 95 myError("close without open:"+windowId); 96 } 97 } 98 99 protected void analyzeActivated(String windowId, boolean editor){ 100 WindowData currentWindow; 101 if(previousWindow!=null){ 102 previousWindow.deactivated(timestamp); 103 editorSum.deactivated(timestamp); 104 } 105 if(!windows.containsKey((Object )windowId))analyzeOpen(windowId,editor); 106 currentWindow=(WindowData)windows.get((Object )windowId); 107 currentWindow.activated(timestamp); 108 previousWindow=currentWindow; 109 if(editorInUse&&editor)tabSwitch++; 110 if(editor)editorSum.activated(timestamp); 111 editorInUse=editor; 112 } 113 114 115 protected void eof(){ 116 Enumeration e=windows.elements(); 117 WindowData w; 118 while(e.hasMoreElements()){ 119 w=(WindowData)e.nextElement(); 120 w.end(timestamp); 121 } 123 print(); 124 } 125 126 private void printWindows(){ 127 pln("Windows"); 128 sortedWindows=new TreeSet (); 129 Enumeration e=windows.elements(); 130 while(e.hasMoreElements())sortedWindows.add((WindowData)e.nextElement()); 131 Iterator it=sortedWindows.iterator(); 132 WindowData w; 133 boolean test=true; 134 while(it.hasNext()){ 135 w=(WindowData)it.next(); 136 pln(" + "+w.id+"\topen: "+prettyTime(w.open)+"\tactivated: "+prettyTime(w.activated)); 137 } 138 } 139 140 private void printEditor(){ 141 WindowData w; 142 long editorTime=0; 143 Enumeration e=editorWindows.elements(); 144 while(e.hasMoreElements()){ 145 w=(WindowData)e.nextElement(); 146 editorTime+=w.activated; 147 } 148 pln("editor time:"+prettyTime(editorTime)); 149 pln("max editor tabs simultaneously: "+maxEditorTabs); 150 pln("tab switches: "+tabSwitch); 151 if(tabSwitch>0){ 152 double time = new Long (editorTime).doubleValue(); 153 pln("tab frequency: "+prettyTime(new Double (time/tabSwitch).longValue())); 154 } 155 } 156 157 private void printExtension(){ 158 Enumeration e=extensions.keys(); 159 String ext, count; 160 while(e.hasMoreElements()){ 161 ext=(String )e.nextElement(); 162 count=((Integer )extensions.get((Object )ext)).toString(); 163 pln("extension type: "+ext+"\tcount:"+count); 164 } 165 } 166 167 168 private void printGal(){ 169 long duration=timestamp-startTime; 170 pln("Duration of session:"+prettyTime(duration)); 171 } 172 173 private void printFields(){ 174 pln("fields:"+fields+" constructors:"+constructors+" methods:"+methods+" beans:"+beanPatterns); 175 } 176 177 private void print(){ 178 pln("***TCR"); 179 printGal(); 180 printWindows(); 181 printEditor(); 182 printExtension(); 183 printFields(); 184 pln("***"); 185 } 186 187 private void pln(String s){ 188 System.out.println(s); 189 } 190 191 protected void myError(String msg){ 192 error("ANALYZER:"+msg); 193 } 194 195 private void matchFieldName(String s){ 196 if(s==null) return; 197 if(s.equalsIgnoreCase("Fields")) { 198 fields++; 199 return; 200 } 201 if(s.equalsIgnoreCase("Constructors")) { 202 constructors++; 203 return; 204 } 205 if(s.equalsIgnoreCase("Methods")) { 206 methods++; 207 return; 208 } 209 if(s.equalsIgnoreCase("BeanPatterns")) { 210 beanPatterns++; 211 return; 212 } 213 } 214 215 private void extension(String s){ 216 int index=s.lastIndexOf('.'); 217 if(index>0){ 218 Object ext; 219 ext=(Object )s.substring(index); 220 int i=1; 221 if(extensions.containsKey(ext)){ 222 i=((Integer )extensions.get(ext)).intValue(); 223 i++; 224 } 225 extensions.put(ext,(Object )new Integer (i)); 226 } 227 } 228 229 } 230 | Popular Tags |