public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Split local classes in frysk.bindir.ftrace into frysk.ftrace.
@ 2008-02-29 20:31 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-02-29 20:31 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  148d1359cf791171d7f346d4fca35c1fc36aca8c (commit)
      from  b69a9d32535ea10a98fb4f67ef0778073654ea58 (commit)

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

- Log -----------------------------------------------------------------
commit 148d1359cf791171d7f346d4fca35c1fc36aca8c
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Feb 29 15:29:23 2008 -0500

    Split local classes in frysk.bindir.ftrace into frysk.ftrace.
    
    frysk-core/frysk/bindir/ChangeLog
    2008-02-29  Andrew Cagney  <cagney@redhat.com>
    
    	* ftrace.java: Move Rule, SymbolRule and MyFtraceController to
    	separate frysk.ftrace classes.
    
    frysk-core/frysk/ftrace/ChangeLog
    2008-02-29  Andrew Cagney  <cagney@redhat.com>
    
    	* FtraceController.java: Extract from frysk.bindir.ftrace.
    	* Rule.java: Extract from frysk.bindir.ftrace.
    	* SymbolRule.java: Extract from frysk.bindir.ftrace.

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog                  |    5 +
 frysk-core/frysk/bindir/ftrace.java                |  361 ++------------------
 frysk-core/frysk/ftrace/ChangeLog                  |    6 +
 frysk-core/frysk/ftrace/FtraceController.java      |  233 +++++++++++++
 .../TaskObserverBase.java => ftrace/Rule.java}     |   93 +++---
 .../{proc/TaskId.java => ftrace/SymbolRule.java}   |  117 ++++---
 6 files changed, 381 insertions(+), 434 deletions(-)
 create mode 100644 frysk-core/frysk/ftrace/FtraceController.java
 copy frysk-core/frysk/{testbed/TaskObserverBase.java => ftrace/Rule.java} (58%)
 copy frysk-core/frysk/{proc/TaskId.java => ftrace/SymbolRule.java} (51%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 51931f1..4f2f4dd 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-29  Andrew Cagney  <cagney@redhat.com>
+
+	* ftrace.java: Move Rule, SymbolRule and MyFtraceController to
+	separate frysk.ftrace classes.
+
 2008-02-29  Petr Machata  <pmachata@redhat.com>
 
 	* ftrace.java (parseSigSysRules): Produce case insensitive rules,
diff --git a/frysk-core/frysk/bindir/ftrace.java b/frysk-core/frysk/bindir/ftrace.java
index f886410..5545d14 100644
--- a/frysk-core/frysk/bindir/ftrace.java
+++ b/frysk-core/frysk/bindir/ftrace.java
@@ -43,365 +43,46 @@ import inua.util.PrintWriter;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.*;
 import java.util.regex.Pattern;
-
 import frysk.ftrace.Ftrace;
-import frysk.ftrace.ObjectFile;
-import frysk.ftrace.Symbol;
-import frysk.ftrace.TracePoint;
-import frysk.ftrace.TracePointOrigin;
 import frysk.isa.signals.Signal;
-import frysk.isa.signals.SignalTable;
 import frysk.isa.syscalls.Syscall;
-import frysk.isa.syscalls.SyscallTable;
 import frysk.proc.Proc;
-import frysk.proc.Task;
 import frysk.util.CommandlineParser;
 import frysk.util.Glob;
 import frysk.util.Util;
 import gnu.classpath.tools.getopt.Option;
 import gnu.classpath.tools.getopt.OptionException;
-import lib.dwfl.ElfSymbolVersion;
-
-abstract class Rule
-{
-    final public boolean addition;
-    final public boolean stackTrace;
-
-    protected Rule(boolean addition, boolean stackTrace) {
-	this.addition = addition;
-	this.stackTrace = stackTrace;
-    }
-
-    public String toString() {
-	return ""
-	    + (this.addition ? "" : "-")
-	    + (this.stackTrace ? "#" : "");
-    }
-
-    public void apply(Logger logger, Collection candidates,
-		    Set workingSet, Set stackTraceSet) {
-	if (this.addition)
-	    // For '+' rules iterate over candidates,
-	    // and add what matches to workingSet, and
-	    // maybe to stackTraceSet.
-	    for (Iterator jt = candidates.iterator(); jt.hasNext(); ) {
-		Object candidate = jt.next();
-		if (this.matches(candidate))
-		{
-		    if (workingSet.add(candidate))
-			logger.log(Level.CONFIG, this + ": add " + candidate + "'.");
-		    if (this.stackTrace
-			&& stackTraceSet.add(candidate))
-			logger.log(Level.CONFIG, this + ": stack trace on " + candidate + ".");
-		}
-	    }
-	else {
-	    // For '-' or '-#' rules iterate over
-	    // workingSet or stackTraceSet, and remove
-	    // what matches.
-	    Set iterateOver = this.stackTrace ? stackTraceSet : workingSet;
-	    for (Iterator jt = iterateOver.iterator(); jt.hasNext(); ) {
-		Object candidate = jt.next();
-		if (this.matches(candidate)) {
-		    jt.remove();
-		    if (!this.stackTrace)
-			stackTraceSet.remove(candidate);
-		    logger.log(Level.CONFIG, this + ": remove " + candidate + ".");
-		}
-	    }
-	}
-    }
-
-    abstract public boolean matches(Object traceable);
-}
-
-class SymbolRule
-    extends Rule
-{
-    /** See namePattern */
-    final public Pattern sonamePattern, versionPattern;
-
-    /**
-     * Object that performs a pattern matching of a symbol name. null
-     * for "anything" matcher.
-     */
-    final public Pattern namePattern;
-
-    public SymbolRule(boolean addition, boolean stackTrace,
-		      String nameRe, String sonameRe, String versionRe) {
-	super (addition, stackTrace);
-	this.sonamePattern = Glob.compile((sonameRe != null) ? sonameRe : "*");
-	this.versionPattern = Glob.compile((versionRe != null) ? versionRe : "*");
-	this.namePattern = Glob.compile((nameRe != null) ? nameRe : "*");
-    }
-
-    public String toString() {
-	return super.toString()
-	    + this.namePattern.pattern()
-	    + "@" + this.sonamePattern.pattern()
-	    + "@@" + this.versionPattern.pattern();
-    }
-
-
-    private boolean checkVersionMatches(final TracePoint tp)
-    {
-	ElfSymbolVersion[] vers = (tp.origin == TracePointOrigin.PLT)
-	    ? (ElfSymbolVersion[])tp.symbol.verneeds
-	    : (ElfSymbolVersion[])tp.symbol.verdefs;
-
-	// When there is no version assigned to symbol, we pretend it has
-	// a version of ''.  Otherwise we require one of the versions to
-	// match the version pattern.
-	if (vers.length == 0) {
-	    if (this.versionPattern.matcher("").matches())
-		return true;
-	}
-	else
-	    for (int i = 0; i < vers.length; ++i)
-		if (this.versionPattern.matcher(vers[i].name).matches())
-		    return true;
+import frysk.ftrace.Rule;
+import frysk.ftrace.SymbolRule;
+import frysk.ftrace.FtraceController;
+import frysk.rsl.Log;
 
-	return false;
-    }
-
-    private boolean checkNameMatches(final TracePoint tp)
-    {
-	Symbol symbol = tp.symbol;
-
-	if (this.namePattern.matcher(symbol.name).matches())
-	    return true;
-
-	if (symbol.aliases != null)
-	    for (int i = 0; i < symbol.aliases.size(); ++i) {
-		String alias = (String)symbol.aliases.get(i);
-		if (this.namePattern.matcher(alias).matches())
-		    return true;
-	    }
-
-	return false;
-    }
-
-    public boolean matches(Object traceable) {
-	TracePoint tp = (TracePoint)traceable;
-	return checkNameMatches(tp)
-	    && checkVersionMatches(tp);
-    }
-}
-
-class MyFtraceController
-    implements Ftrace.Controller,
-	       Ftrace.StackTracedSymbolsProvider,
-	       Ftrace.TracedSyscallProvider,
-	       Ftrace.TracedSignalProvider
-{
-    protected static final Logger logger = Logger.getLogger("frysk");
-
-    // ArrayList<SymbolRule>
-    private final List pltRules = new ArrayList();
-    private final List dynRules = new ArrayList();
-    private final List symRules = new ArrayList();
-    private final List sysRules = new ArrayList();
-    private final List sigRules = new ArrayList();
-
-    // Which symbols should yield a stack trace.
-    private HashSet symbolsStackTraceSet = new HashSet();
-    private boolean stackTraceEverything = false;
-
-    public void stackTraceEverything() {
-	stackTraceEverything = true;
-    }
-
-    public boolean shouldStackTraceOnSymbol(Symbol symbol) {
-	return stackTraceEverything
-	    || symbolsStackTraceSet.contains(symbol);
-    }
+class ftrace {
+    private static final Log fine = Log.fine(ftrace.class);
 
-    public MyFtraceController() { }
-
-    public void gotPltRules(List rules) {
-	logger.log(Level.FINER, "Got " + rules.size() + " PLT rules.");
-	this.pltRules.addAll(rules);
-    }
-
-    public void gotDynRules(List rules) {
-	logger.log(Level.FINER, "Got " + rules.size() + " DYNAMIC rules.");
-	this.dynRules.addAll(rules);
-    }
-
-    public void gotSymRules(List rules) {
-	logger.log(Level.FINER, "Got " + rules.size() + " SYMTAB rules.");
-	this.symRules.addAll(rules);
-    }
-
-    public void gotSysRules(List rules) {
-	logger.log(Level.FINER, "Got " + rules.size() + " syscall rules.");
-	this.sysRules.addAll(rules);
-    }
-
-    public void gotSigRules(List rules) {
-	logger.log(Level.FINER, "Got " + rules.size() + " signal rules.");
-	this.sigRules.addAll(rules);
-    }
-
-    private Map computeWorkingSet(Task task, String what,
-				 List rules, ArrayList candidates)
-    {
-	HashSet workingSet = new HashSet();
-	HashSet stackTraceSet = new HashSet();
-
-	for (Iterator it = rules.iterator(); it.hasNext(); ) {
-	    final Rule rule = (Rule)it.next();
-	    logger.log(Level.FINEST, "Considering syscall rule " + rule + ".");
-	    rule.apply(logger, candidates, workingSet, stackTraceSet);
-	}
-
-	// Apply the two sets.
-	Map ret = new HashMap();
-	for (Iterator it = workingSet.iterator(); it.hasNext(); ) {
-	    Object syscall = it.next();
-	    ret.put(syscall, Boolean.valueOf(stackTraceEverything
-					     || stackTraceSet.contains(syscall)));
-	}
-	return ret;
-    }
-
-    // Syscall working and stack trace sets can be pre-computed for
-    // each task.  This is in contrast to tracing rules, that are
-    // computed incrementally when DSOs are mapped.
-    public Map computeSyscallWorkingSet(Task task) {
-	SyscallTable syscallTable = task.getSyscallTable();
-	long n = syscallTable.getNumSyscalls();
-	ArrayList candidates = new ArrayList();
-	for (long i = 0; i < n; ++i)
-	    candidates.add(syscallTable.getSyscall(i));
-
-	return computeWorkingSet(task, "syscall", sysRules, candidates);
-    }
-
-    // Compute signal working and stack trace sets.
-    public Map computeSignalWorkingSet(Task task) {
-	frysk.sys.Signal[] hostSignals
-	    = frysk.sys.Signal.getHostSignalSet().toArray();
-	SignalTable signalTable = task.getSignalTable();
-	ArrayList candidates = new ArrayList();
-	for (int i = 0; i < hostSignals.length; i++)
-	    candidates.add(signalTable.get(hostSignals[i].intValue()));
-
-	return computeWorkingSet(task, "signal", sigRules, candidates);
-    }
-
-    private boolean isInterpOf(ObjectFile objf, String exe)
-    {
-	java.io.File exefn = new java.io.File(exe);
-	ObjectFile exef = ObjectFile.buildFromFile(exefn);
-	java.io.File interpfn = exef.resolveInterp();
-	java.io.File objffn = objf.getFilename();
-	return objffn.equals(interpfn);
-    }
-
-    public void applyTracingRules(final Task task, final ObjectFile objf, final Ftrace.Driver driver,
-				  final List rules, final TracePointOrigin origin)
-	throws lib.dwfl.ElfException
-    {
-	logger.log(Level.FINER, "Building working set for origin " + origin + ".");
-
-	// Skip the set if it's empty...
-	if (rules.isEmpty())
-	    return;
-
-	// Set<TracePoint>, all tracepoints in objfile.
-	final Set candidates = new HashSet();
-	// Set<TracePoint>, incrementally built working set.
-	final Set workingSet = new HashSet();
-	// Set<TracePoint>, incrementally built set of tracepoints
-	// that should stacktrace.
-	final Set stackTraceSet = new HashSet();
-
-	// Do a lazy init.  With symbol tables this can be very beneficial, because certain symbol 
-	boolean candidatesInited = false;
-
-	// Loop through all the rules, and use them to build
-	// workingSet from candidates.  Candidates are initialized
-	// lazily inside the loop.
-	for (Iterator it = rules.iterator(); it.hasNext(); ) {
-	    final SymbolRule rule = (SymbolRule)it.next();
-	    logger.log(Level.FINEST, "Considering symbol rule " + rule + ".");
-
-	    // MAIN is meta-soname meaning "main executable".
-	    if ((rule.sonamePattern.pattern().equals("MAIN")
-		 && task.getProc().getExe().equals(objf.getFilename().getPath()))
-		|| (rule.sonamePattern.pattern().equals("INTERP")
-		    && isInterpOf(objf, task.getProc().getExe()))
-		|| rule.sonamePattern.matcher(objf.getSoname()).matches())
-	    {
-		if (!candidatesInited) {
-		    candidatesInited = true;
-		    objf.eachTracePoint(new ObjectFile.TracePointIterator() {
-			    public void tracePoint(TracePoint tp) {
-				if (candidates.add(tp))
-				    logger.log(Level.FINE, "candidate `" + tp.symbol.name + "'.");
-			    }
-			}, origin);
-		}
-
-		rule.apply(logger, candidates, workingSet, stackTraceSet);
-	    }
-	}
-
-	// Finally, apply constructed working set.
-	logger.log(Level.FINER, "Applying working set for origin " + origin + ".");
-	for (Iterator it = workingSet.iterator(); it.hasNext(); )
-	    driver.tracePoint(task, (TracePoint)it.next());
-
-	for (Iterator it = stackTraceSet.iterator(); it.hasNext(); )
-	    symbolsStackTraceSet.add(((TracePoint)it.next()).symbol);
-    }
-
-    public void fileMapped(final Task task, final ObjectFile objf, final Ftrace.Driver driver) {
-	try {
-	    applyTracingRules(task, objf, driver, pltRules, TracePointOrigin.PLT);
-	    applyTracingRules(task, objf, driver, dynRules, TracePointOrigin.DYNAMIC);
-	    applyTracingRules(task, objf, driver, symRules, TracePointOrigin.SYMTAB);
-	}
-	catch (lib.dwfl.ElfException ee) {
-	    ee.printStackTrace();
-	}
-    }
-}
-
-class ftrace
-{
     //Where to send the output.
-    PrintWriter writer;
-
-    protected static final Logger logger = Logger.getLogger("frysk");
+    private PrintWriter writer;
 
     // True if a PID was requested.
-    boolean requestedPid;
+    private boolean requestedPid;
     // Command and arguments to exec.
-    ArrayList commandAndArguments;
+    private ArrayList commandAndArguments;
 
     // For configuration of overall working set.  We need to load and
     // apply rules separately, to get all log messages, that's the
     // reason we need these temporary array lists.
-    final List pltRules = new ArrayList();
-    final List dynRules = new ArrayList();
-    final List symRules = new ArrayList();
-    final List sysRules = new ArrayList();
-    final List sigRules = new ArrayList();
-    final MyFtraceController controller = new MyFtraceController();
-    boolean allowInterpTracing = false;
+    private final List pltRules = new ArrayList();
+    private final List dynRules = new ArrayList();
+    private final List symRules = new ArrayList();
+    private final List sysRules = new ArrayList();
+    private final List sigRules = new ArrayList();
+    private final FtraceController controller = new FtraceController();
+    private boolean allowInterpTracing = false;
 
-    Ftrace tracer = new Ftrace();
+    private Ftrace tracer = new Ftrace();
 
     private List parseSymbolRules(String arg) {
 	String[] strs = arg.split(",", -1);
@@ -454,7 +135,7 @@ class ftrace
 	    else
 		symbolRe = null;
 
-	    logger.log(Level.FINE, i + ": " + str + ": symbol=" + symbolRe + ", soname=" + sonameRe + ", version=" + versionRe);
+	    fine.log(i + ": " + str + ": symbol=" + symbolRe + ", soname=" + sonameRe + ", version=" + versionRe);
 	    SymbolRule rule = new SymbolRule(addition, stackTrace, symbolRe, sonameRe, versionRe);
 	    rules.add(rule);
 	}
@@ -496,7 +177,7 @@ class ftrace
 		stackTrace = false;
 
 	    if (sysnumPat.matcher(str).matches()) {
-		logger.log(Level.FINE, i + ": " + str + ": by number rule");
+		fine.log(i + ": " + str + ": by number rule");
 		final int number = (new Integer(str)).intValue();
 		rule = new Rule(addition, stackTrace) {
 			public boolean matches(final Object traceable) {
@@ -505,7 +186,7 @@ class ftrace
 		    };
 	    }
 	    else if (!str.equals("")) {
-		logger.log(Level.FINE, i + ": " + str + ": by name rule");
+		fine.log(i + ": " + str + ": by name rule");
 		str = str.toLowerCase();
 		if (optionalPrefix != null && !str.startsWith(optionalPrefix))
 		    str = optionalPrefix + str;
@@ -518,7 +199,7 @@ class ftrace
 		    };
 	    }
 	    else {
-		logger.log(Level.FINE, i + ": " + str + ": \"everything\" rule");
+		fine.log(i + ": " + str + ": \"everything\" rule");
 		rule = new Rule(addition, stackTrace) {
 			public boolean matches(Object traceable) {
 			    return true;
diff --git a/frysk-core/frysk/ftrace/ChangeLog b/frysk-core/frysk/ftrace/ChangeLog
index 87e8d9b..b865a35 100644
--- a/frysk-core/frysk/ftrace/ChangeLog
+++ b/frysk-core/frysk/ftrace/ChangeLog
@@ -1,3 +1,9 @@
+2008-02-29  Andrew Cagney  <cagney@redhat.com>
+
+	* FtraceController.java: Extract from frysk.bindir.ftrace.
+	* Rule.java: Extract from frysk.bindir.ftrace.
+	* SymbolRule.java: Extract from frysk.bindir.ftrace.
+
 2008-02-29  Petr Machata  <pmachata@redhat.com>
 
 	* Ftrace.java: Support signal tracing.
diff --git a/frysk-core/frysk/ftrace/FtraceController.java b/frysk-core/frysk/ftrace/FtraceController.java
new file mode 100644
index 0000000..2bd373a
--- /dev/null
+++ b/frysk-core/frysk/ftrace/FtraceController.java
@@ -0,0 +1,233 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, 2006, 2007, 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.ftrace;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;


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


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

only message in thread, other threads:[~2008-02-29 20:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-29 20:31 [SCM] master: Split local classes in frysk.bindir.ftrace into frysk.ftrace 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).