Feature adds to webinterface:
authorsivaji <sivaji>
Fri, 8 Jun 2007 01:07:42 +0000 (01:07 +0000)
committersivaji <sivaji>
Fri, 8 Jun 2007 01:07:42 +0000 (01:07 +0000)
*Double lined nodes(allocated nodes) are linked to a 'allocating tasks' page.
*Each edge(task) in the FS graph is linked to its correnponding task page.
*Each task in the Task graph is linked to its corresponding task page.

Major mods:
Modified GraphNode.java : added getName();

Robust/src/Analysis/TaskStateAnalysis/Allocations.java
Robust/src/Analysis/TaskStateAnalysis/FlagState.java
Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java
Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java
Robust/src/Analysis/TaskStateAnalysis/TaskNode.java
Robust/src/Benchmarks/TTTTag/TTTServer.java
Robust/src/Benchmarks/TTTTag/TTTServerSocket.java
Robust/src/Interface/WebInterface.java
Robust/src/Main/Main.java
Robust/src/Util/GraphNode.java

index 760a7a6b67cd862895fdba5be01d41a89b456ad5..0146dafc1ee70ed85c3a744f1769b353af89d945 100644 (file)
@@ -11,7 +11,7 @@ public class Allocations extends Namer {
     public String nodeOption(GraphNode gn) {
        FlagState fs=(FlagState)gn;
        if (fs.isSourceNode())
-           return "peripheries=2";
+           return "peripheries=2, URL=\"" + fs.getClassDescriptor().toString() + "_" + fs.getLabel() + ".html\"";
        else
            return "";
     }
index 3c862ce5b73b7c5add1da7ea88f4d6c25fa30f00..bd211e8ceadb34f2f67baf56e22c8654a531647f 100644 (file)
@@ -22,6 +22,8 @@ public class FlagState extends GraphNode {
     private final ClassDescriptor cd;
     private final Hashtable<TagDescriptor,Integer> tags;
     private boolean issourcenode;
+    private Vector tasks;
+    
 
     /** Class constructor
      *  Creates a new flagstate with all flags set to false.
@@ -70,8 +72,17 @@ public class FlagState extends GraphNode {
      */
        public void setAsSourceNode(){
                issourcenode=true;
+               this.tasks=new Vector();
+       }
+       
+       public void addAllocatingTask(TaskDescriptor task){
+               tasks.addElement(task);
        }
 
+       public Vector getAllocatingTasks(){
+               return tasks;
+       }
+               
     
     public String toString() {
        return cd.toString()+getTextLabel();
@@ -216,6 +227,9 @@ public class FlagState extends GraphNode {
     public String getLabel() {
        return "N"+uid;
     }
+    
+    
+       
 
     public String getTextLabel() {
        String label=null;
index b723e1b8a7b6de4c3e315efef1c931faab8f8e2f..45cf7bea582779bedf93eb081cd3fa28ff68c48a 100644 (file)
@@ -14,6 +14,7 @@ public class TaskAnalysis {
     Hashtable extern_flags;
     Queue<FlagState> toprocess;
     TagAnalysis taganalysis;
+    Hashtable cdtorootnodes;
 
     TypeUtil typeutil;
 
@@ -28,7 +29,7 @@ public class TaskAnalysis {
        this.state=state;
        this.typeutil=new TypeUtil(state);
        this.taganalysis=taganalysis;
-       
+               
     }
     
     /** Builds a table of flags for each class in the Bristlecone program.  
@@ -94,7 +95,7 @@ public class TaskAnalysis {
     public void taskAnalysis() throws java.io.IOException {
        flagstates=new Hashtable();
        Hashtable<FlagState,FlagState> sourcenodes;
-       
+       cdtorootnodes=new Hashtable();
        
        getFlagsfromClasses();
        
@@ -113,6 +114,7 @@ public class TaskAnalysis {
            //Debug block
            
            flagstates.put(cd,new Hashtable<FlagState,FlagState>());
+           cdtorootnodes.put(cd,new Vector());
        }       
        
        
@@ -126,6 +128,7 @@ public class TaskAnalysis {
        
        fsstartup=fsstartup.setFlag(fd[0],true);
        fsstartup.setAsSourceNode();
+       ((Vector)cdtorootnodes.get(startupobject)).add(fsstartup);
 
        sourcenodes.put(fsstartup,fsstartup);
        toprocess.add(fsstartup);
@@ -207,6 +210,8 @@ private void analyseTasks(FlagState fs) {
        for(Iterator fsit=newstates.iterator();fsit.hasNext();) {
            FlagState fsnew=(FlagState) fsit.next();
            fsnew.setAsSourceNode();
+           fsnew.addAllocatingTask(td);
+           ((Vector)cdtorootnodes.get(cd)).add(fsnew);
            
            if (! ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) {
                ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew);
@@ -474,6 +479,9 @@ private FlagState evalNewObjNode(FlatNode nn){
     }
        }
        
+       public Vector getRootNodes(ClassDescriptor cd){
+               return (Vector)cdtorootnodes.get(cd);
+       }
 
        
 } 
index 00b31dc07259319366acba057e43b53fa44b8f49..f92df9cbd793853f24cb1e246ee7332ee78f0061 100644 (file)
@@ -11,6 +11,7 @@ public class TaskGraph {
     TaskAnalysis taskanalysis;
     State state;
     Hashtable cdtonodes;
+    Hashtable nodes;
 
     public TaskGraph(State state, TaskAnalysis taskanalysis) {
        this.state=state;
@@ -91,6 +92,25 @@ public class TaskGraph {
        }
     }
     
+  /*   private void mergeAllNodes(){
+               Hashtable alltasks=new Hashtable();
+               for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) {
+               ClassDescriptor cd=(ClassDescriptor) classit.next();
+                       Set tnodes=((Hashtable)cdtonodes.get(cd)).keyset();
+                       while (it_tnodes=tnodes.iterator();it_nodes.hasNext()){
+                               TaskNode tn=it_nodes.next();
+                               if (alltasks.containsKey(tn)){
+                                       while(tn.
+                               }
+                       }
+                       
+           
+           
+           
+    }
+    
+        */   
+    
     private void addEdges(FlagState fs, TaskNode tn){
            
            Hashtable<TaskNode,TaskNode> tasknodes=(Hashtable<TaskNode,TaskNode>)cdtonodes.get(fs.getClassDescriptor());
@@ -105,4 +125,6 @@ public class TaskGraph {
            }
 
        }
+       
+       
 }
index e2dbd34e5b2e4eb96c92cd48ef3b5773d21f1742..64c14a01df8aed7902c75cbd78d8deaf23e35283 100644 (file)
@@ -33,6 +33,9 @@ public class TaskNode extends GraphNode {
        return "N"+uid;
     }
 
+    public String getName(){
+           return name;
+    }
        
        /**toString method.
         * @return  string representation of the tasknode (e.g "Task foo")
index ab3169f45683b65451b1c8d54d248a6daec4e2f4..e7288a0dc69a1038da760fcc17fcd143e8a5bcdc 100644 (file)
@@ -14,21 +14,21 @@ task Startup(StartupObject s {initialstate}) {
 task AcceptConnection(ServerSocket ss{SocketPending}) {
        System.printString("Waiting for connection...\n");
        tag t=new tag(connect);
-       TTTServerSocket ttts = new TTTServerSocket() {TTTSInitialize}{t};
+       TTTServerSocket ttts = new TTTServerSocket() {ReceiveRequest}{t};
        System.printString("Calling accept...\n");
        ss.accept(t);
        System.printString("Connected...\n");
 }
 
 // Process incoming requests
-task ProcessRequest(TTTServerSocket ttts{TTTSInitialize}{connect l}, Socket s{IOPending}{connect l}) {
+task ProcessRequest(TTTServerSocket ttts{ReceiveRequest}{connect l}, Socket s{IOPending}{connect l}) {
        System.printString("Request received...");
        int action = ttts.receive(s);
        if (action == 1) { // Make move
-               taskexit(ttts {MakeMove});
+               taskexit(ttts {!ReceiveRequest,MakeMove});
        }
        else { // Send Error
-               taskexit(ttts {SendError});
+               taskexit(ttts {!ReceiveRequest,SendError});
        }
 }
 
@@ -48,12 +48,19 @@ task ProcessMove(TTTServerSocket ttts{MakeMove}, Board tttBoard{init}) {
 
 task SendBoardDisplay(TTTServerSocket ttts{SendBoard}{connect l}, Board tttBoard{init}, Socket s{}{connect l}) {
        ttts.sendBoardDisplay(tttBoard, s);
+       taskexit(ttts {/*!SendBoard,*/ ReceiveRequest});
+       
 }
 
 task GameOver(TTTServerSocket ttts{SendDone}{connect l}, Board tttBoard{init}, Socket s{}{connect l}) {
        ttts.sendDone(tttBoard.winner(), s);
+//     taskexit(ttts {!SendDone},tttBoard{!init});
+
 }
 
 task SendErrorMessage(TTTServerSocket ttts{SendError}{connect l}, Board tttBoard{init}, Socket s{}{connect l}) {
+       //System.printString("Error\n");
        ttts.sendError(s);
+       taskexit(ttts {/*!SendError,*/ ReceiveRequest});
+
 }
index 4d6b885272a5eb7312c099c5f34e161e56df584b..d0bc5bd9b85024bc92e2689f42909a10b802f692 100644 (file)
@@ -1,6 +1,6 @@
 public class TTTServerSocket {
        // TTTServerSocket flags
-       flag TTTSInitialize;
+       flag ReceiveRequest;
 
        flag MakeMove;
        flag SendError;
@@ -23,21 +23,27 @@ public class TTTServerSocket {
                System.printString("request: ");
                System.printString(request);
                if (parseTransaction() == 1) {
+                       System.printString(request);
                        return 1;
                }
+               System.printString("Error receiving...\n");
                return 0;
        }
 
        // Parse request
        public int parseTransaction(){
                int start = request.indexOf('_');
+               //System.printString("start parse");
                String s = request.subString(start+1);
+               //System.printString("before checking the string");
 //_move:3:3
                if (s.startsWith("move")==true){
                        //Get row
                        int i1 = s.indexOf(':');
                        String rowStr = new String(s.subString(i1+1, i1+2));
                        row = Integer.parseInt(rowStr);
+                       
+                       //System.printString("row");
 
                        //Get col
                        String s2 = new String(s.subString(i1+2));
@@ -46,6 +52,8 @@ public class TTTServerSocket {
                        col = Integer.parseInt(colStr);
                        return 1;
                        
+                       
+                       
                }
                // Error transaction
                return -1;
@@ -78,7 +86,7 @@ public class TTTServerSocket {
        }
        
        public void sendDone(int winner, Socket s) {
-               StringBuffer line1 = new String ("done_");
+               StringBuffer line1 = new StringBuffer ("done_");
                if (winner == 0)
                        line1.append("tie");
                else if (winner == 1)
@@ -92,7 +100,7 @@ public class TTTServerSocket {
        }
        
        public void sendError(Socket s) {
-               StringBuffer line1 = new String ("error_wrongmove");
+               StringBuffer line1 = new StringBuffer ("error_wrongmove");
                        
                String towrite = new String(line1);
                s.write(towrite.getBytes());
index eb88d969b33208f146ab1603bd7bd32e25e45601..2a75467a217466d57f2d01dddc06d4bd4b8d250f 100644 (file)
@@ -9,8 +9,10 @@ public class WebInterface {
     TaskAnalysis taskanalysis;
     TaskGraph taskgraph;
     State state;
-    Hashtable taskmap;
+    Hashtable flagstatemap;
     Hashtable taskgraphmap;
+    Hashtable sourcenodemap; //to hold the filenames for each of the pages linked to the source nodes.
+    Hashtable taskmap;  // to hold the filenames for each of the pages linked to tasks in the program.
     GarbageAnalysis garbageanalysis;
 
     public WebInterface(State state, TaskAnalysis taskanalysis, TaskGraph taskgraph, GarbageAnalysis garbageanalysis) {
@@ -19,52 +21,135 @@ public class WebInterface {
        this.taskgraph=taskgraph;
        this.garbageanalysis=garbageanalysis;
 
-       taskmap=new Hashtable();
+       flagstatemap=new Hashtable();
        taskgraphmap=new Hashtable();
+       taskmap = new Hashtable();
+       sourcenodemap=new Hashtable();
+       for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();){
+               TaskDescriptor td=(TaskDescriptor)it_tasks.next();
+               taskmap.put("/"+td.getSymbol()+".html",td);
+       } 
+       for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
+           ClassDescriptor cd=(ClassDescriptor) it_classes.next();
+           Vector rootnodes=taskanalysis.getRootNodes(cd);
+           if(rootnodes!=null)
+           for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){
+               FlagState root=(FlagState)it_rootnodes.next();
+               Vector cd_nodeid=new Vector();
+               cd_nodeid.addElement(cd);
+               cd_nodeid.addElement(root.getLabel());
+               sourcenodemap.put("/"+cd.getSymbol()+"_"+root.getLabel()+".html",cd_nodeid);
+           }
+       }
     }
     
     public boolean specialRequest(String filename) {
        System.out.println(filename);
        if (filename.equals("/index.html"))
            return true;
-       if (taskmap.containsKey(filename))
+       if (flagstatemap.containsKey(filename))
            return true;
        if (taskgraphmap.containsKey(filename))
            return true;
+       if (taskmap.containsKey(filename))
+               return true;
+       if (sourcenodemap.containsKey(filename))
+               return true;
        return false;
     }
 
     public String handleresponse(String filename, OutputStream out, HTTPResponse resp) {
        if (filename.equals("/index.html"))
            return indexpage(out, resp);
-       if (taskmap.containsKey(filename))
-           return flagstate((ClassDescriptor) taskmap.get(filename), out, resp);
+       if (flagstatemap.containsKey(filename))
+           return flagstate((ClassDescriptor) flagstatemap.get(filename), out, resp);
        if (taskgraphmap.containsKey(filename))
            return taskstate((ClassDescriptor) taskgraphmap.get(filename), out, resp);
+       if (taskmap.containsKey(filename))
+           return task((TaskDescriptor)taskmap.get(filename),out,resp);
+       if (sourcenodemap.containsKey(filename))
+           return sourcenode((Vector) sourcenodemap.get(filename), out, resp);
        return "NORESP";
     }
 
+    private String task(TaskDescriptor td, OutputStream out, HTTPResponse resp){
+       try{
+       PrintWriter pw=new PrintWriter(out);
+       pw.println("<br><br><h3>Task:&nbsp;&nbsp;&nbsp;"+td.toString()+"</h3><br>");
+       printTask(td,pw);
+       pw.flush();
+       } catch (Exception e) {e.printStackTrace();System.exit(-1);}
+       return null;
+    }
+
+    private String printTask(TaskDescriptor td, PrintWriter pw){
+       try{
+
+               for(int i=0; i < td.numParameters();i++){
+                       pw.println("FlagState Graph:&nbsp;&nbsp;<a href=\"/"+td.getParamType(i)+".html\">"+td.getParamType(i)+"</a><br>");
+                       pw.println("Task Graph:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"/"+td.getParamType(i)+"-t.html\">"
+                               +td.getParamType(i)+"</a><br>");
+               }                       
+               pw.flush();
+       }catch(Exception e) {e.printStackTrace();System.exit(-1);}
+       return null;
+   }
+
+    private String sourcenode(Vector cd_nodeid,OutputStream out, HTTPResponse resp){
+       Vector rootnodes=taskanalysis.getRootNodes((ClassDescriptor)cd_nodeid.elementAt(0));
+       for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){
+               FlagState root=(FlagState)it_rootnodes.next();
+               if (root.getLabel().equals((String)cd_nodeid.elementAt(1))){
+               try{
+                       PrintWriter pw=new PrintWriter(out);
+                       pw.println("<br><br><h3>Allocating tasks for "+root.getTextLabel()+":</h3><br>");
+                       Vector tasks=root.getAllocatingTasks();
+                       for(Iterator it_tasks=tasks.iterator();it_tasks.hasNext();){
+                               TaskDescriptor td=(TaskDescriptor)it_tasks.next();
+                               pw.println("<br><strong>Task:&nbsp;&nbsp;&nbsp;"+td.toString()+"</strong><br>");
+                               printTask(td,pw);
+                       }
+               
+               } catch (Exception e) {e.printStackTrace();System.exit(-1);}
+               break;
+               }
+               
+       }
+       return null;
+   }
+
     private String flagstate(ClassDescriptor cd, OutputStream out, HTTPResponse resp) {
        Set objects=taskanalysis.getFlagStates(cd);
        File file=new File(cd.getSymbol()+".dot");
+       File mapfile;
+       String str;
        Vector namers=new Vector();
        namers.add(new Namer());
        namers.add(garbageanalysis);
        namers.add(new Allocations());
+       namers.add(new TaskEdges());
        try {
            //Generate jpg
            Runtime r=Runtime.getRuntime();
+
            FileOutputStream dotstream=new FileOutputStream(file,false);
            FlagState.DOTVisitor.visit(dotstream, objects, namers);
            dotstream.close();
-           Process p=r.exec("dot -Tjpg "+cd.getSymbol()+".dot -o"+cd.getSymbol()+".jpg");
+           Process p=r.exec("dot -Tcmapx -o"+cd.getSymbol()+".map -Tjpg -o"+cd.getSymbol()+".jpg "+cd.getSymbol()+".dot");
            p.waitFor();
            p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+".ps");
            p.waitFor();
 
+           mapfile=new File(cd.getSymbol()+".map");
+           BufferedReader mapbr=new BufferedReader(new FileReader(mapfile));
            PrintWriter pw=new PrintWriter(out);
            pw.println("<a href=\"/"+ cd.getSymbol()+".ps\">ps</a><br>");
-           pw.println("<img src=\"/"+ cd.getSymbol()+".jpg\">");
+           //pw.println("<a href=\"/"+ cd.getSymbol()+".map\"><img src=\"/"+ cd.getSymbol()+".gif\" ismap=\"ismap\"></A>");
+           pw.println("<img src=\""+cd.getSymbol()+".jpg\" usemap=\"#dotvisitor\" />");
+           while((str=mapbr.readLine())!=null){
+               pw.println(str);
+           }
+           
            pw.flush();
        } catch (Exception e) {e.printStackTrace();System.exit(-1);}
        return null;
@@ -73,34 +158,51 @@ public class WebInterface {
     private String taskstate(ClassDescriptor cd, OutputStream out, HTTPResponse resp) {
        Set objects=taskgraph.getTaskNodes(cd);
        File file=new File(cd.getSymbol()+"-t.dot");
+       File mapfile;
+       String str;
+       Vector namers=new Vector();
+       namers.add(new Namer());
+       namers.add(new TaskNodeNamer());
+
        try {
            //Generate jpg
            Runtime r=Runtime.getRuntime();
            FileOutputStream dotstream=new FileOutputStream(file,false);
-           FlagState.DOTVisitor.visit(dotstream, objects);
+           FlagState.DOTVisitor.visit(dotstream, objects,namers);
            dotstream.close();
-           Process p=r.exec("dot -Tjpg "+cd.getSymbol()+"-t.dot -o"+cd.getSymbol()+"-t.jpg");
+           Process p=r.exec("dot -Tcmapx -o"+cd.getSymbol()+"-t.map -Tjpg -o"+cd.getSymbol()+"-t.jpg "+cd.getSymbol()+"-t.dot");
            p.waitFor();
            p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+"-t.ps");
+           
            p.waitFor();
 
+           mapfile=new File(cd.getSymbol()+"-t.map");
+           BufferedReader mapbr=new BufferedReader(new FileReader(mapfile));
            PrintWriter pw=new PrintWriter(out);
            pw.println("<a href=\"/"+ cd.getSymbol()+"-t.ps\">ps</a><br>");
-           pw.println("<img src=\"/"+ cd.getSymbol()+"-t.jpg\">");
+          // pw.println("<a href=\"/"+ cd.getSymbol()+"-t.map\"><img src=\"/"+ cd.getSymbol()+"-t.gif\" ismap=\"ismap\"></A>");
+           pw.println("<img src=\""+cd.getSymbol()+"-t.jpg\" usemap=\"#dotvisitor\" />");
+
+           while((str=mapbr.readLine())!=null){
+               pw.println(str);
+           }
            pw.flush();
        } catch (Exception e) {e.printStackTrace();System.exit(-1);}
        return null;
     }
-
+    
+   /* public void taskgraph(
+*/
 
     private String indexpage(OutputStream out, HTTPResponse resp) {
+
        PrintWriter pw=new PrintWriter(out);
        for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
            ClassDescriptor cd=(ClassDescriptor) it_classes.next();
            if (taskanalysis.getFlagStates(cd)!=null) {
                pw.println("<a href=\""+cd.getSymbol()+".html\">"+ cd.getSymbol() +"</a>");
                pw.println("<br>");
-               taskmap.put("/"+cd.getSymbol()+".html", cd);
+               flagstatemap.put("/"+cd.getSymbol()+".html", cd);
            }
            if (taskgraph.getTaskNodes(cd)!=null) {
                pw.println("<a href=\""+cd.getSymbol()+"-t.html\">Task Graph "+ cd.getSymbol() +"</a>");
index e880f0f65ebc5880f288832a64ab25d880f75598..775891c634d390133301faa57a4193a254bfddde 100644 (file)
@@ -112,6 +112,7 @@ public class Main {
       BuildFlat bf=new BuildFlat(state,tu);
       bf.buildFlat();
 
+
       if (state.TASKSTATE) {
          CallGraph callgraph=new CallGraph(state);
          TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
@@ -131,6 +132,7 @@ public class Main {
 
       
       
+
       BuildCode bc=new BuildCode(state, bf.getMap(), tu);
       bc.buildCode();
       System.exit(0);
index cbe96016d860db9de7fc46ac2dea65a989419b01..c4c7ba24dae146e4ddf7096b0a1439a20c04dabe 100755 (executable)
@@ -98,6 +98,10 @@ public class GraphNode {
     public String getTextLabel() {
        return "";
     }
+    
+       public String getName(){
+               return "";
+       }
 
     public NodeStatus getStatus() {
         return this.status;