public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Maintain a local ProcessIdentifier indexed table of processes.
@ 2008-02-08 22:45 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-08 22:45 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  56a8ca502dd2862e7411cf97e2248fb719db5dac (commit)
      from  a92ed3564375cfa4673641a266c79d6c8e520b9f (commit)

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

- Log -----------------------------------------------------------------
commit 56a8ca502dd2862e7411cf97e2248fb719db5dac
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Feb 8 17:44:18 2008 -0500

    Maintain a local ProcessIdentifier indexed table of processes.
    
    frysk-core/frysk/proc/live/ChangeLog
    2008-02-08  Andrew Cagney  <cagney@redhat.com>
    
    	* LinuxPtraceHost.java (procs): New.
    	(getProc(ProcessIdentifier)): New.
    	(putProc(ProcessIdentifier,LinuxPtraceProc)): New.
    	(ProcChanges): Use.
    	* LinuxPtraceProc.java: Use.

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

Summary of changes:
 frysk-core/frysk/proc/live/ChangeLog            |    6 +++
 frysk-core/frysk/proc/live/LinuxPtraceHost.java |   49 +++++++++++++----------
 frysk-core/frysk/proc/live/LinuxPtraceProc.java |    3 +
 3 files changed, 37 insertions(+), 21 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/proc/live/ChangeLog b/frysk-core/frysk/proc/live/ChangeLog
index f2f0210..7cfa15a 100644
--- a/frysk-core/frysk/proc/live/ChangeLog
+++ b/frysk-core/frysk/proc/live/ChangeLog
@@ -1,5 +1,11 @@
 2008-02-08  Andrew Cagney  <cagney@redhat.com>
 
+	* LinuxPtraceHost.java (procs): New.
+	(getProc(ProcessIdentifier)): New.
+	(putProc(ProcessIdentifier,LinuxPtraceProc)): New.
+	(ProcChanges): Use.
+	* LinuxPtraceProc.java: Use.
+	
 	* LinuxPtraceHost.java: Update to match
 	ProcBuilder.build(ProcessIdentifier).
 	* LinuxPtraceProc.java: Ditto.
diff --git a/frysk-core/frysk/proc/live/LinuxPtraceHost.java b/frysk-core/frysk/proc/live/LinuxPtraceHost.java
index 09fe0a7..4aab80e 100644
--- a/frysk-core/frysk/proc/live/LinuxPtraceHost.java
+++ b/frysk-core/frysk/proc/live/LinuxPtraceHost.java
@@ -62,8 +62,6 @@ import frysk.sys.Pid;
 import frysk.event.Event;
 import frysk.proc.FindProc;
 import frysk.proc.HostRefreshBuilder;
-import java.util.Map;
-import java.util.WeakHashMap;
 import java.util.Collection;
 
 /**
@@ -83,7 +81,7 @@ public class LinuxPtraceHost extends LiveHost {
     /**
      * Maintain a cache of tasks indexed by ProcessIdentifier.
      */
-    private final Map tasks = new WeakHashMap();
+    private final HashMap tasks = new HashMap();
     LinuxPtraceTask getTask(ProcessIdentifier pid) {
 	return (LinuxPtraceTask) tasks.get(pid);
     }
@@ -92,6 +90,17 @@ public class LinuxPtraceHost extends LiveHost {
     }
 
     /**
+     * Maintain a cache of procs indexed by ProcessIdentifier.
+     */
+    private final HashMap procs = new HashMap();
+    LinuxPtraceProc getProc(ProcessIdentifier pid) {
+	return (LinuxPtraceProc) procs.get(pid);
+    }
+    void putProc(ProcessIdentifier pid, LinuxPtraceProc proc) {
+	procs.put(pid, proc);
+    }
+
+    /**
      * Either add or update a process, however, before doing that
      * determine the parent and ensure that it has been updated.
      */
@@ -107,14 +116,13 @@ public class LinuxPtraceHost extends LiveHost {
 	 * works backwards removing any that are processed, by the end
 	 * it contains processes that no longer exist.
 	 */
-	HashMap removed = (HashMap) ((HashMap) procPool).clone();
+	HashMap removed = (HashMap) procs.clone();
 
 	/**
 	 * Update PROCID, either adding it
 	 */
 	Proc update(ProcessIdentifier pid) {
-	    ProcId procId = new ProcId(pid.intValue());
-	    Proc proc = (Proc) procPool.get(procId);
+	    Proc proc = getProc(pid);
 	    if (proc == null) {
 		// New, unknown process. Try to find both the process
 		// and its parent. In the case of a daemon process, a
@@ -130,7 +138,7 @@ public class LinuxPtraceHost extends LiveHost {
 		    // Scan in the process's stat file. Of course, if
 		    // the stat file disappeared indicating that the
 		    // process exited, return NULL.
-		    if (! stat.refresh(procId.id))
+		    if (stat.scan(pid) == null)
 			return null;
 		    // Find the parent, every process, except process
 		    // 1, has a parent.
@@ -141,10 +149,10 @@ public class LinuxPtraceHost extends LiveHost {
 			break;
 		}
 		// .. and then add this process.
-		proc = new LinuxPtraceProc(LinuxPtraceHost.this, parent, procId, stat);
+		proc = new LinuxPtraceProc(LinuxPtraceHost.this, parent,
+					   new ProcId(pid.intValue()), stat);
 		added.add(proc);
-	    }
-	    else if (removed.get(procId) != null) {
+	    } else if (removed.containsKey(pid)) {
 		// Process 1 never gets a [new] parent.
 		if (pid.intValue() > 1) {
 		    Stat stat = ((LinuxPtraceProc) proc).getStat();
@@ -163,7 +171,7 @@ public class LinuxPtraceHost extends LiveHost {
 			newParent.add(proc);
 		    }
 		}
-		removed.remove(procId);
+		removed.remove(pid);
 	    }
 	    return proc;
 	}
@@ -215,21 +223,20 @@ public class LinuxPtraceHost extends LiveHost {
 
     public void requestProc(final int theProcId, final FindProc theFinder) {
 	Manager.eventLoop.add(new Event() {
-		private final int procId = theProcId;
+		private final ProcessIdentifier pid
+		    = ProcessIdentifierFactory.create(theProcId);
 		private final FindProc finder = theFinder;
 		public void execute() {
 		    // Iterate (build) the /proc tree starting with
 		    // the given procId.
-		    final ProcChanges procChanges = new ProcChanges();
-		    ProcBuilder pidBuilder = new ProcBuilder() {
-			    public void build(ProcessIdentifier pid) {
-				procChanges.update(pid);
-			    }
-			};
-		    pidBuilder.construct(procId);
-		    final Proc proc = Manager.host.getProc(new ProcId(procId));
+		    new ProcBuilder() {
+			public void build(ProcessIdentifier pid) {
+			    new ProcChanges().update(pid);
+			}
+		    }.construct(pid);
+		    Proc proc = getProc(pid);
 		    if (proc == null) {
-			finder.procNotFound(procId);
+			finder.procNotFound(pid.intValue());
 		    } else {
 			proc.sendRefresh();
 			finder.procFound(proc);
diff --git a/frysk-core/frysk/proc/live/LinuxPtraceProc.java b/frysk-core/frysk/proc/live/LinuxPtraceProc.java
index b805fba..1147982 100644
--- a/frysk-core/frysk/proc/live/LinuxPtraceProc.java
+++ b/frysk-core/frysk/proc/live/LinuxPtraceProc.java
@@ -53,6 +53,7 @@ import java.util.ArrayList;
 import frysk.sys.proc.CmdLineBuilder;
 import frysk.sys.proc.MapsBuilder;
 import frysk.sys.ProcessIdentifier;
+import frysk.sys.ProcessIdentifierFactory;
 import frysk.sys.proc.Status;
 import java.util.logging.Level;
 import frysk.sys.proc.ProcBuilder;
@@ -76,6 +77,7 @@ public class LinuxPtraceProc extends LiveProc {
      */
     public LinuxPtraceProc(Host host, Proc parent, ProcId pid, Stat stat) {
 	super(host, parent, pid);
+	((LinuxPtraceHost)host).putProc(ProcessIdentifierFactory.create(pid.hashCode()), this);
 	this.newState = LinuxPtraceProcState.initial(false);
 	this.stat = stat;
 	this.breakpoints = new BreakpointAddresses(this);
@@ -86,6 +88,7 @@ public class LinuxPtraceProc extends LiveProc {
      */
     public LinuxPtraceProc(Task task, ProcessIdentifier fork) {
 	super(task, new ProcId(fork.intValue()));
+	((LinuxPtraceHost)getHost()).putProc(fork, this);
 	this.newState = LinuxPtraceProcState.initial(true);
 	this.breakpoints = new BreakpointAddresses(this);
     }


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


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

only message in thread, other threads:[~2008-02-08 22:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-08 22:45 [SCM] master: Maintain a local ProcessIdentifier indexed table of processes cagney

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).