public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Get fstack to use ProcStopUtil.
@ 2008-03-13 18:54 tthomas
  0 siblings, 0 replies; only message in thread
From: tthomas @ 2008-03-13 18:54 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  b5dd83dda5cd506c65914247987c8fef06a6a2b2 (commit)
      from  fbd23dae64a0c33303d87610bb0c012e365b57cf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit b5dd83dda5cd506c65914247987c8fef06a6a2b2
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Thu Mar 13 14:44:09 2008 -0400

    Get fstack to use ProcStopUtil.
    
    frysk-core/frysk/bindir/ChangeLog:
    2008-03-13  Teresa Thomas  <tthomas@redhat.com>
    
    	* fstack.java: Refactor to use ProcStopUtil.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog   |    4 +
 frysk-core/frysk/bindir/fstack.java |  223 +++++++++++++++--------------------
 2 files changed, 101 insertions(+), 126 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 06636a1..bc181d9 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,7 @@
+2008-03-13  Teresa Thomas  <tthomas@redhat.com>
+
+	* fstack.java: Refactor to use ProcStopUtil.
+
 2008-03-13  Mark Wielaard  <mwielaard@redhat.com>
 
 	* fcatch.xml: Fixed URL.
diff --git a/frysk-core/frysk/bindir/fstack.java b/frysk-core/frysk/bindir/fstack.java
index bbf949e..9b57a78 100644
--- a/frysk-core/frysk/bindir/fstack.java
+++ b/frysk-core/frysk/bindir/fstack.java
@@ -40,141 +40,114 @@
 package frysk.bindir;
 
 import java.io.PrintWriter;
+import java.util.Iterator;
 import java.util.StringTokenizer;
+import java.util.TreeMap;
+
+import frysk.debuginfo.DebugInfoStackFactory;
 import frysk.debuginfo.PrintStackOptions;
 import frysk.event.Event;
-import frysk.event.RequestStopEvent;
-import frysk.proc.Manager;
+import frysk.event.ProcEvent;
 import frysk.proc.Proc;
-import frysk.proc.ProcBlockAction;
-import frysk.proc.ProcCoreAction;
-import frysk.util.CommandlineParser;
-import frysk.util.StacktraceAction;
+import frysk.proc.Task;
+import frysk.rsl.Log;
+import frysk.stack.StackFactory;
+import frysk.util.ProcStopUtil;
 import gnu.classpath.tools.getopt.Option;
 import gnu.classpath.tools.getopt.OptionException;
 
 public final class fstack {
 
-  private static StacktraceAction stacker;
-
-  private static CommandlineParser parser;
-
-  private static PrintWriter printWriter = new PrintWriter(System.out);
-  
+  private static PrintWriter printWriter = new PrintWriter(System.out);  
   static PrintStackOptions options = new PrintStackOptions();
+  private static final Log fine = Log.fine(fstack.class);
   
-  private static class Stacker extends StacktraceAction
+  public static void main (String[] args)
   {
+      ProcStopUtil fstack = new ProcStopUtil("fstack", args, 
+                                              new StackerEvent());
+      fstack.setUsage("Usage: fstack <PID> || fstack <COREFILE> [<EXEFILE>]");   
+      addOptions (fstack);
+      fstack.execute();
+  }
+  
+  /**
+   * Implements a ProcEvent for core file creation.
+   */
+  private static class StackerEvent implements ProcEvent {
+      public void executeLive(Proc proc) {
+          fine.log(this, "printTasks");
+          printTasks(proc);
+          proc.requestAbandonAndRunEvent(new Event()
+          {
+              public void execute ()
+              {   
+                  printWriter.flush();
+              }
+          });
+      }
 
-    Proc proc;
-    public Stacker (PrintWriter printWriter, Proc theProc, Event theEvent,PrintStackOptions options)
-    {
-      super(printWriter, theProc, theEvent, options);
-      this.proc = theProc;
-    }
-
-    //@Override
-    public void addFailed (Object observable, Throwable w)
-    {
-      w.printStackTrace();
-      proc.requestAbandonAndRunEvent(new RequestStopEvent(Manager.eventLoop));
-
-      try
-        {
-          // Wait for eventLoop to finish.
-          Manager.eventLoop.join();
-        }
-      catch (InterruptedException e)
-        {
-          e.printStackTrace();
-        }
-      System.exit(1);
-    } 
+      public void executeDead(Proc proc) {
+          fine.log(this, "printTasks");
+          printTasks(proc);
+          printWriter.flush();
+      }     
   }
   
-  private static class AbandonPrintEvent implements Event
-  {
-    private Proc proc;
-    
-    AbandonPrintEvent(Proc proc)
-    {
-      this.proc = proc;
-    }
-    public void execute ()
-    {
-      proc.requestAbandonAndRunEvent(new Event()
-    {
+  private static void printTasks(Proc proc) {
+      
+      Task[] tasks = (Task[]) proc.getTasks().toArray
+      (new Task[proc.getTasks().size()]);
 
-      public void execute ()
+      TreeMap sortedTasks = new TreeMap();
+      for (int i=0; i<tasks.length; i++)
+          sortedTasks.put(new Integer(tasks[i].getTid()), tasks[i]);
+
+      Iterator iter = sortedTasks.values().iterator();
+      while (iter.hasNext())
       {
-	  Manager.eventLoop.requestStop();
-	  stacker.flush();
+          Task task =  (Task) iter.next();
+
+          if(options.elfOnly()){
+              StackFactory.printTaskStackTrace(printWriter,task,options);
+          }else{
+              if(options.printVirtualFrames()){
+                  DebugInfoStackFactory.printVirtualTaskStackTrace(printWriter,task,options);
+              }else{
+                  DebugInfoStackFactory.printTaskStackTrace(printWriter,task,options);
+              }
+          }
+          printWriter.println();
       }
-    });
-    }
-    
-  }
-  
-  private static class PrintEvent implements Event
-  {
-    public void execute()
-    {
-      Manager.eventLoop.requestStop();
-      stacker.flush();
-    }
   }
   
-    private static void stackCore(Proc proc) {
-	stacker = new Stacker(printWriter, proc, new PrintEvent(), options);
-	new ProcCoreAction(proc, stacker);
-	Manager.eventLoop.run();
-    }
-  
-    private static void stackPid(Proc proc) {
-	stacker = new Stacker(printWriter, proc, new AbandonPrintEvent(proc), options);
-	new ProcBlockAction(proc, stacker);
-	Manager.eventLoop.run();
-    }
-  
-  public static void main (String[] args)
-  {
-
-      parser = new CommandlineParser("fstack") {
-	      //@Override
-	      public void parseCores(Proc[] cores) {
-		  for (int i = 0; i < cores.length; i++)
-		      stackCore(cores[i]);
-	      }
-	      //@Override
-	      public void parsePids(Proc[] procs) {
-		  for (int i = 0; i < procs.length; i++)
-		      stackPid(procs[i]);
-	      }
-	  };
-
-      parser.add(new Option("number-of-frames", 'n', "number of frames to print. Use -n 0 or" +
-      		" -n all to print all frames.", "<number of frames>") {
-	  public void parsed(String arg) throws OptionException {
-	      if(arg.equals("all")){
-		  options.setNumberOfFrames(0);
-	      }else{
-		  options.setNumberOfFrames(Integer.parseInt(arg));
-		  return;
-	      }
-	  }
+  /**
+   * Add options to fstack.
+   */
+  private static void addOptions (ProcStopUtil fstack) {
+      fstack.addOption(new Option("number-of-frames", 'n', "number of frames to print. Use -n 0 or" +
+                                  " -n all to print all frames.", "<number of frames>") {
+          public void parsed(String arg) throws OptionException {
+              if(arg.equals("all")){
+                  options.setNumberOfFrames(0);
+              }else{
+                  options.setNumberOfFrames(Integer.parseInt(arg));
+                  return;
+              }
+          }
       });
  
-      parser.add(new Option("fullpath", 'f', "print full path." +
-  		"-f prints full path") {
-	  public void parsed(String arg) throws OptionException {
-	        options.setPrintFullpath(true);
-	  }
+      fstack.addOption(new Option("fullpath", 'f', "print full path." +
+                                  "-f prints full path") {
+          public void parsed(String arg) throws OptionException {
+                options.setPrintFullpath(true);
+          }
       });
 
 
-    parser.add(new Option("all", 'a', "print all information that can currently be retrieved" +
-                          "about the stack\n" +
-                          "this is equivalent to -p functions,params,scopes,fullpath"){
+      fstack.addOption(new Option("all", 'a', "print all information that can currently be retrieved" +
+                                  "about the stack\n" +
+                                  "this is equivalent to -p functions,params,scopes,fullpath"){
 
                 public void parsed (String argument) throws OptionException
                 {
@@ -185,21 +158,21 @@ public final class fstack {
                 }
               });
     
-    parser.add(new Option(
-			"virtual",
-			'v',
-			"Includes virtual frames in the stack trace.\n" +
-			"Virtual frames are artificial frames corresponding" +
-			" to calls to inlined functions") {
+      fstack.addOption(new Option(
+                        "virtual",
+                        'v',
+                        "Includes virtual frames in the stack trace.\n" +
+                        "Virtual frames are artificial frames corresponding" +
+                        " to calls to inlined functions") {
 
-		    public void parsed(String argument) throws OptionException {
-			options.setPrintVirtualFrames(true);
-			options.setElfOnly(false);
-		    }
-		});
+                    public void parsed(String argument) throws OptionException {
+                        options.setPrintVirtualFrames(true);
+                        options.setElfOnly(false);
+                    }
+                });
 
 
-    parser.add(new Option("common", 'c', "print commonly used debug information:" +
+      fstack.addOption(new Option("common", 'c', "print commonly used debug information:" +
                           "this is equivalent to fstack -v -p functions,params,fullpath"){
 
                 public void parsed (String argument) throws OptionException
@@ -212,7 +185,7 @@ public final class fstack {
                 }
     });
               
-    parser.add(new Option("print", 'p', "itmes to print. Possible items:\n" +
+      fstack.addOption(new Option("print", 'p', "itmes to print. Possible items:\n" +
                 "functions : print function names using debug information\n" +
                 "scopes : print variables declared in each scope within the " +
                 "function.\n" +
@@ -249,10 +222,8 @@ public final class fstack {
               options.setElfOnly(false);
               options.setPrintFullpath(true);
             }
-            
           }
       }
-    });
-    parser.parse(args);    
+      }); 
   }
 }


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-13 18:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-13 18:54 [SCM] master: Get fstack to use ProcStopUtil tthomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).