VisClient/org/hfbk/vis/visnode/VisFilesys.java

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import java.awt.event.MouseEvent;
00004 import java.io.File;
00005 
00006 import org.dronus.gl.GLBoxRenderer;
00007 import org.dronus.gl.GLFont;
00008 import org.dronus.gl.GLTextPanel;
00009 import org.dronus.gl.GLUtil;
00010 import org.dronus.graph.Edge;
00011 import org.dronus.graph.Graph;
00012 import org.dronus.graph.Node;
00013 import org.hfbk.util.Counter;
00014 import org.hfbk.util.Sleeper;
00015 import org.hfbk.vis.Prefs;
00016 import org.lwjgl.opengl.GL11;
00017 import org.lwjgl.util.vector.Vector3f;
00018 
00031 public class VisFilesys extends VisSet {
00032         
00034         final int DELAY=1000;  
00035         
00037         Graph profile=new Graph();
00038         
00039         
00040 
00042         Counter<Integer> callCounter=new Counter<Integer>();
00043         
00044         Counter<String> sizeAdder=new Counter<String>();
00045         
00046         //if something was sampled but not yet visualised.
00047         boolean dirty=true;
00048 
00049         /*private long getDirSize(File path) {
00050                 Iterator path_iterator;
00051                 File current_file ;
00052                 long size;
00053 
00054                 path_iterator =(Arrays.asList(path.listFiles())).iterator();
00055 
00056                 size=0;
00057 
00058                 while (path_iterator.hasNext()) {
00059                 current_file=(File) path_iterator.next();
00060                 if (current_file.isFile()) {
00061                 size+=current_file.length();
00062                 }
00063                 else {
00064                 size+=getDirSize(current_file);
00065                 }
00066                 }
00067 
00068                 return size;
00069                 }       
00070 */
00072         class VisCallBall extends VisNodeDraggable {
00073                         int dl;
00074                 GLTextPanel helpText;           
00075                 Node node;
00076                 boolean isTriggered=true; 
00077                 
00078                 VisCallBall(Node n, Vector3f position) {
00079                         super(n, position);
00080                         
00081                         this.node=n;
00082                         w=h=radius=1.6f;
00083                         String[] b = n.text.split("#");
00084                         n.text=b[0];
00085 float f=1.6f;
00086                         if (b.length>1) {
00087                                 f = Float.valueOf( b[1] ).floatValue();
00088                                 w=h=radius=f/10000;
00089                                 w=h=radius=((float)Math.pow(f,(double)( 1.0/3))/10f);
00090                                 }
00091                         
00092                         int cutoff=n.text.lastIndexOf("/");
00093                         String caption=n.text;
00094                         if (cutoff>0)caption=n.text.substring(n.text.lastIndexOf("/")+1);
00095                         
00096                         helpText=new GLTextPanel(caption,0,0);
00097                 }
00098                 
00099                 String cleanPath(String path){
00100                         path=path.replace('\\', '/');
00101                         path=path.replace("file://", "");
00102                         if (path.matches("file:/.*?\\:.*?")){//correct bad windows path in uri:  
00103                                 path=path.replace("file:/", "");//a driver letter is not root enough
00104                                                                                         //so it gets prefixed by / which we 
00105                                                                                         //remove here again.
00106                         }
00107                         
00108                         return path.trim();             
00109                 }
00110 
00111                 void handleEvent(VisMouseEvent evt) {
00112                         super.handleEvent(evt);
00113 
00114                         VisRoot root=getRoot();
00115                         
00116                         
00117                         if (evt.getID()==MouseEvent.MOUSE_CLICKED)
00118                         
00119                         {
00120                                 
00121 //                                      System.out.println(node.text+": "+sizeAdder.get(node.text));
00122 
00123 
00124                                 //is it an image/video?
00125                                 if (node.text.toLowerCase().matches(".*?\\.("+Prefs.current.suffixesImage+"|"+Prefs.current.suffixesVideo+")(.|\\s)*"))
00126                                 {
00127                                         
00128                                         System.out.println(cleanPath(node.text));
00129                                         
00130 
00131 //                                      root.add(new VisImage(new Node(cleanPath(node.text)),new Vector3f(root.client.mouseViewpoint)));
00132                                         
00133                                         
00134                                         Vector3f posi=position;
00135                                         posi.y+=1;
00136                                         add(new VisImage(new Node(cleanPath(node.text)),new Vector3f(0,1,0)));
00137                                         
00138                                         
00139                                         
00140 //                                      root.client.setViewpoint((Vector3f)root.client.mouseViewpoint,1);
00141                                                                         
00142                                         
00143                                 }
00144                                 else if (node.text.toLowerCase().matches(".*?\\.(obj)(.|\\s)*"))
00145                                 {
00146                                         System.out.println(cleanPath(node.text));
00147                                                 
00148                                         
00149                                         
00150 //                                              root.add(new VisObj(new Node(cleanPath(node.text)),new Vector3f(root.client.mouseViewpoint)));
00151 
00152                                                 root.client.root.create("obj", cleanPath(node.text));
00153                                                 
00154                                 }
00155 
00156                         }                                               
00157                 }       
00158                 
00159                 
00160                 void renderSelf() {
00161                         boolean isOur=false;
00162                         Integer count=callCounter.get(node.id);
00163                         if (count!=null){
00164 //                              radius=.6f+10*(float)Math.sqrt(count/(float)callCounter.total);
00165 //                              w=h=2*radius;
00166                         }
00167                         if (isHoovered || isTriggered)                          
00168                                 GL11.glColor3f(1,1,1);
00169                         else if (node.type.equals("File"))
00170                         {
00171                                 if (node.text.toLowerCase().matches(".*?\\.("+Prefs.current.suffixesImage+"|"+Prefs.current.suffixesVideo+")(.|\\s)*")){                                                                                                                        
00172                                         GL11.glColor4f(1f,1f,.1f,.5f);                  
00173                                 }
00174                                 else if (node.text.toLowerCase().matches(".*?\\.(java)(.|\\s)*")){
00175                                         GL11.glColor3f(0f,.8f,1f);                      
00176                                         
00177                                         //is it some subtitles file?
00178                                 }else if (node.text.toLowerCase().matches(".*?\\.(obj|srt|coord|coords)(.|\\s)*")){
00179                                         GL11.glColor3f(.1f,1f,.1f);                     
00180                                         
00181                                 }
00182                                 else GL11.glColor3f(.8f,.5f,.01f);
00183                         }
00184                         else if (node.type.equals("Dir")){
00185                          isOur=true;                    //node.text.startsWith("org.dronus")||node.text.startsWith("org.hfbk");
00186                                 GL11.glColor4f(1,0,0,(isOur ? 1 : .5f ));
00187                         }
00188 
00189                                 
00190 //                      GLSphereRenderer.renderSphere(radius);
00191 
00192                         GL11.glDisable(GL11.GL_TEXTURE_2D);
00193 
00194                         GLBoxRenderer.renderBox(radius,radius,radius);
00195                         
00196                         
00197 //                      if (isHoovered || radius>=1.6f) { //describe "fat" calls unhoovered also                
00198                         if (isHoovered || isOur) {
00199                                 GL11.glTranslatef(radius,radius,0);
00200                                 GLUtil.billboardCylinder();
00201                                 GL11.glScalef(1,2,1);
00202                                 GLFont.getDefault().render();                           
00203                                 helpText.render();
00204                                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00205                         }
00206                         
00207                         isTriggered=false;
00208                 }
00209         }
00210         
00212         VisNode create(Node node, Vector3f pos) {
00213                 return new VisCallBall(node, pos);
00214         }
00215         
00217         public VisFilesys(Node n, Vector3f position) {  
00218                 super(null, position);
00219                 if (n.text.length()==0) n.text=".";
00220                                 
00221                 final String start=n.text;
00222                                 
00223                 
00224                 profile.addNode(new Node("0","Vis/Client","Set"));
00225                 
00226         
00227                 
00228                 
00229         Thread scanner=new Thread(){                    
00230 
00231                 public void run() {
00232                                 setName("VisProfiler");
00233                                 while(true){
00234                                         synchronized(VisFilesys.this){  scandir(start,null);    };
00235                                         Sleeper.sleep(DELAY);
00236                                 }
00237                         }
00238                 };                              
00239                 scanner.start();
00240         
00241         }
00242         
00247         void scandir(String startatdir, Node parentnode){
00248                 Node rootset=profile.getRoot();
00249                 if (startatdir.equals("")) {startatdir=".";parentnode=rootset;}
00250 
00251                 if (parentnode==null)parentnode=rootset;
00252                 
00253                 File f = null;
00254 
00255                 f = new File(startatdir);
00256 
00257 //              System.out.println(getDirSize(f));
00258 
00259                 String path=f.getAbsolutePath();
00260                 
00261                 for (File f2 : f.listFiles()) {
00262                         String fn1=f2.getName();
00263 int size=(int)f2.length();
00264                         
00265                         boolean isdir=f2.isDirectory();
00266                         char c=fn1.charAt(0);
00267                         if ((c!='.')&&(!fn1.endsWith("~"))&&(!fn1.endsWith("strip")&&(!fn1.endsWith(".class"))))
00268                         {
00269                                 int fileId=fn1.hashCode();
00270 
00271                                 callCounter.add(fileId); //count method sample
00272                                 sizeAdder.add(startatdir,size); //add filesize sample
00273 
00274                                 Node fileNode=profile.findNode(fileId);
00275                                 if(fileNode==null) {
00276                                         if (isdir)
00277                                         {
00278                                                 
00279                                                 fileNode=new Node(fileId, fn1, "Dir");
00280         //                                      System.out.println(fn1+": dir added "+fileNode);
00281 
00282                                         }
00283                                         else
00284                                                 {
00285                                                 
00286                                                 fileNode=new Node(fileId, path+"/"+fn1+"#"+size, "File");
00287         //                                      System.out.println(fn1+": file added "+fileNode);
00288                                                 }
00289 
00290                                 
00291                                         profile.addNode(fileNode);
00292                                         dirty=true;
00293         //                              System.out.println("edge from "+fileNode+" to "+parentnode);
00294                                         
00295                                         profile.addEdge(new Edge(fileNode,rootset, null, "in",1f));             
00296 
00297                                         profile.addEdge(new Edge(fileNode,parentnode, null, "",.05f));          
00298 
00299                                         if (isdir){
00300                                                 scandir(startatdir+"/"+fn1,fileNode);
00301                                         }
00302                                         
00303                                 }
00304                         }
00305 
00306                                 }               
00307                 
00308                 
00309                 
00310                 //for all existing threads...
00311 /*              for(Map.Entry<Thread,StackTraceElement[]> trace : Thread.getAllStackTraces().entrySet())
00312                 {
00313                         
00314                         String threadName=trace.getKey().getName();
00315                         int threadId=threadName.hashCode();
00316                         Node threadNode=profile.findNode(threadId);
00317                         if(threadNode==null) {
00318                                 threadNode=new Node(threadId, threadName, "Thread");
00319                                 profile.addNode(threadNode);
00320                                 profile.addEdge(new Edge(threadNode,rootset, null, "in"));                                      
00321                         }
00322                         StackTraceElement[] stes=trace.getValue();
00323                         
00324                         //reverse stack trace
00325                         for (int i=0; i<stes.length/2; i++){
00326                                 StackTraceElement tmp=stes[i];
00327                                 stes[i]=stes[stes.length-i-1];
00328                                 stes[stes.length-i-1]=tmp;
00329                         }
00330                         
00331                         //for all elements of current thread's call stack...
00332                         Node last=null;
00333                         for (StackTraceElement ste: stes){
00334                                 //id by thread too to show threads independently
00335                                 int id=threadId^ste.getClassName().hashCode()^ste.getMethodName().hashCode();
00336                                 
00337                                 callCounter.add(id); //count method sample
00338                                 
00339                                 Node n=profile.findNode(id); //know this method already?
00340                                 
00341                                 if (n==null){
00342                                         n=new Node(id, ste.getClassName()+"."+ste.getMethodName(),"Call");
00343                                         profile.addNode(n);                                     
00344                                         dirty=true; //mark for update
00345                                 }       
00346                                 profile.addEdge(new Edge(n,rootset, null, "in"));
00347                                 
00348                                 if (last!=null) //link to caller method 
00349                                         profile.addEdge(new Edge(last,n, null, ""));
00350                                 else
00351                                         profile.addEdge(new Edge(n,threadNode, null, "in"));
00352                                 last=n;
00353                         }       
00354                         
00355                         // flash active node
00356                         VisNode vn=nodes.get(last);
00357                         if (vn instanceof VisCallBall)
00358                                 ((VisCallBall)vn).isTriggered=true;
00359                 }
00360                 */
00361         }
00362         
00363         void renderSelf() {
00364                 super.renderSelf();
00365                 //everytime the profiler added something to
00366                 //profile graph, we update the visualisation.
00367                 if (dirty) synchronized(this){
00368                         Node root=profile.getRoot();
00369                         update(root);
00370                         
00371                         dirty=false;
00372                 }
00373         }
00374 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1