public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Make Host, Proc, and Task comparable; use. Date: Fri, 08 Feb 2008 16:42:00 -0000 [thread overview] Message-ID: <20080208164254.19073.qmail@sourceware.org> (raw) The branch, master has been updated via 804d992e99f52887737f4e329db5460485aced04 (commit) from b5f3352b84deae5f16bbd33f4e736f6a82d6ee07 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 804d992e99f52887737f4e329db5460485aced04 Author: Andrew Cagney <cagney@redhat.com> Date: Fri Feb 8 11:42:02 2008 -0500 Make Host, Proc, and Task comparable; use. frysk-core/frysk/hpd/ChangeLog 2008-02-08 Andrew Cagney <cagney@redhat.com> * ActionPointCommands.java: Don't use Comparator; rely on the task's 'natural' order. frysk-core/frysk/proc/ChangeLog 2008-02-08 Andrew Cagney <cagney@redhat.com> * Task.java (compareTo(Object)): New. * Proc.java (compareTo(Object)): New. * Host.java (compareTo(Object)): New. frysk-core/frysk/proc/dummy/ChangeLog 2008-02-08 Andrew Cagney <cagney@redhat.com> * DummyTask.java (DummyTask(Proc,int)): New. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/hpd/ActionPointCommands.java | 21 +----- frysk-core/frysk/hpd/ChangeLog | 5 + frysk-core/frysk/proc/ChangeLog | 4 + frysk-core/frysk/proc/Host.java | 6 +- frysk-core/frysk/proc/Proc.java | 10 ++- frysk-core/frysk/proc/Task.java | 7 ++ frysk-core/frysk/proc/TestComparable.java | 101 +++++++++++++++++++++++++ frysk-core/frysk/proc/dummy/ChangeLog | 2 + frysk-core/frysk/proc/dummy/DummyTask.java | 6 +- 9 files changed, 140 insertions(+), 22 deletions(-) create mode 100644 frysk-core/frysk/proc/TestComparable.java First 500 lines of diff: diff --git a/frysk-core/frysk/hpd/ActionPointCommands.java b/frysk-core/frysk/hpd/ActionPointCommands.java index 7c954c6..32623dc 100644 --- a/frysk-core/frysk/hpd/ActionPointCommands.java +++ b/frysk-core/frysk/hpd/ActionPointCommands.java @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2007, Red Hat Inc. +// Copyright 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 @@ -49,7 +49,6 @@ import java.util.Arrays; import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.Comparator; abstract class ActionPointCommands extends ParameterizedCommand { @@ -143,22 +142,6 @@ abstract class ActionPointCommands extends ParameterizedCommand { Actions() { super(false, "actions", "actions", "List action points"); } - private static class TaskComparator implements Comparator { - public int compare(Object o1, Object o2) { - Map.Entry me1 = (Map.Entry) o1; - Map.Entry me2 = (Map.Entry) o2; - int id1 = ((Task) me1.getKey()).getTaskId().intValue(); - int id2 = ((Task) me2.getKey()).getTaskId().intValue(); - if (id1 < id2) - return -1; - else if (id1 > id2) - return 1; - else - return 0; - } - } - private final TaskComparator taskComparator = new TaskComparator(); - /* * Print out the specified actionpoints. These will be * filtered as per the possible arguments in the hpd. We have @@ -230,7 +213,7 @@ abstract class ActionPointCommands extends ParameterizedCommand { Map.Entry[] taskEntries = new Map.Entry[taskEntrySet.size()]; taskEntrySet.toArray(taskEntries); - Arrays.sort(taskEntries, taskComparator); + Arrays.sort(taskEntries); for (int i = 0; i < taskEntries.length; i++) { int id = ((Task) taskEntries[i].getKey()).getTaskId() .intValue(); diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog index b4cc7d4..9901ec4 100644 --- a/frysk-core/frysk/hpd/ChangeLog +++ b/frysk-core/frysk/hpd/ChangeLog @@ -1,3 +1,8 @@ +2008-02-08 Andrew Cagney <cagney@redhat.com> + + * ActionPointCommands.java: Don't use Comparator; rely on the + task's 'natural' order. + 2008-02-07 Stan Cox <scox@redhat.com> * ListCommand.java (interpret): Don't attempt "repeat" behavior. diff --git a/frysk-core/frysk/proc/ChangeLog b/frysk-core/frysk/proc/ChangeLog index ed52f58..7158823 100644 --- a/frysk-core/frysk/proc/ChangeLog +++ b/frysk-core/frysk/proc/ChangeLog @@ -1,5 +1,9 @@ 2008-02-08 Andrew Cagney <cagney@redhat.com> + * Task.java (compareTo(Object)): New. + * Proc.java (compareTo(Object)): New. + * Host.java (compareTo(Object)): New. + * Host.java (getName()): Make abstract. 2008-02-07 Andrew Cagney <cagney@redhat.com> diff --git a/frysk-core/frysk/proc/Host.java b/frysk-core/frysk/proc/Host.java index 3ecc2b0..7aff0a1 100644 --- a/frysk-core/frysk/proc/Host.java +++ b/frysk-core/frysk/proc/Host.java @@ -54,7 +54,7 @@ import java.util.logging.Logger; * process that is running this code - frysk is self aware. */ -public abstract class Host { +public abstract class Host implements Comparable { static protected final Logger logger = Logger.getLogger("frysk");//.proc /** * The host corresponds to a specific system. @@ -231,4 +231,8 @@ public abstract class Host { * Returns the name of the host */ public abstract String getName(); + + public int compareTo(Object o) { + return getName().compareTo(((Host)o).getName()); + } } diff --git a/frysk-core/frysk/proc/Proc.java b/frysk-core/frysk/proc/Proc.java index aaf0b48..9539182 100644 --- a/frysk-core/frysk/proc/Proc.java +++ b/frysk-core/frysk/proc/Proc.java @@ -59,7 +59,7 @@ import frysk.sys.Signal; * A UNIX Process, containing tasks, memory, ... */ -public abstract class Proc { +public abstract class Proc implements Comparable { protected static final Logger logger = Logger.getLogger(ProcLogger.LOGGER_ID); final ProcId id; @@ -393,4 +393,12 @@ public abstract class Proc { + ",state=" + getStateFIXME() + "}"); } + + public int compareTo(Object o) { + Proc other = (Proc)o; + int comp = getHost().compareTo(other.getHost()); + if (comp == 0) + comp = getPid() - other.getPid(); + return comp; + } } diff --git a/frysk-core/frysk/proc/Task.java b/frysk-core/frysk/proc/Task.java index 5e41213..99c7be1 100644 --- a/frysk-core/frysk/proc/Task.java +++ b/frysk-core/frysk/proc/Task.java @@ -359,4 +359,11 @@ public abstract class Task { } private SignalTable signalTable; + public int compareTo(Object o) { + Task other = (Task)o; + int comp = getProc().compareTo(other.getProc()); + if (comp == 0) + comp = getTid() - other.getTid(); + return comp; + } } diff --git a/frysk-core/frysk/proc/TestComparable.java b/frysk-core/frysk/proc/TestComparable.java new file mode 100644 index 0000000..2ddc6e5 --- /dev/null +++ b/frysk-core/frysk/proc/TestComparable.java @@ -0,0 +1,101 @@ +// This file is part of the program FRYSK. +// +// Copyright 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.proc; + +import frysk.proc.dummy.DummyHost; +import frysk.proc.dummy.DummyProc; +import frysk.proc.dummy.DummyTask; +import frysk.junit.TestCase; + +public class TestComparable extends TestCase { + private DummyHost h1 = new DummyHost("h1"); + private DummyProc h1p1 = new DummyProc(h1, 1); + private DummyTask h1p1t1 = new DummyTask(h1p1, 1); + private DummyTask h1p1t2 = new DummyTask(h1p1, 2); + private DummyProc h1p2 = new DummyProc(h1, 2); + private DummyTask h1p2t1 = new DummyTask(h1p2, 1); + private DummyTask h1p2t2 = new DummyTask(h1p2, 2); + private DummyHost h2 = new DummyHost("h2"); + private DummyProc h2p1 = new DummyProc(h2, 1); + private DummyTask h2p1t1 = new DummyTask(h2p1, 1); + // private DummyTask h2p1t2 = new DummyTask(h2p1, 2); + private DummyProc h2p2 = new DummyProc(h2, 2); + // private DummyTask h2p2t1 = new DummyTask(h2p2, 1); + private DummyTask h2p2t2 = new DummyTask(h2p2, 2); + + public void testCompareHost() { + assertTrue("h1 == h1", h1.compareTo(h1) == 0); + assertTrue("h1 < h2", h1.compareTo(h2) < 0); + assertTrue("h2 > h1", h2.compareTo(h1) > 0); + } + + public void testCompareProcsOnSameHost() { + assertTrue("h1p1 == h1p1", h1p1.compareTo(h1p1) == 0); + assertTrue("h1p1 < h1p2", h1p1.compareTo(h1p2) < 0); + assertTrue("h1p2 > h1p1", h1p2.compareTo(h1p1) > 0); + } + + public void testCompareTasksOnSameProc() { + assertTrue("h1p1t1 == h1p1t1", h1p1t1.compareTo(h1p1t1) == 0); + assertTrue("h1p1t1 < h1p1t2", h1p1t1.compareTo(h1p1t2) < 0); + assertTrue("h1p1t2 > h1p1t1", h1p1t2.compareTo(h1p1t1) > 0); + } + + public void testCompareProcsOnDifferentHost() { + assertTrue("h1p1 < h2p1", h1p1.compareTo(h2p1) < 0); + assertTrue("h1p2 < h2p1", h1p2.compareTo(h2p1) < 0); + assertTrue("h2p1 > h1p2", h2p1.compareTo(h1p2) > 0); + assertTrue("h2p2 > h1p2", h2p2.compareTo(h1p2) > 0); + } + + public void testCompareTasksOnDifferentProcsOnSameHost() { + assertTrue("h1p1t1 < h1p2t1", h1p1t1.compareTo(h1p2t1) < 0); + assertTrue("h1p1t2 < h1p2t1", h1p1t2.compareTo(h1p2t1) < 0); + assertTrue("h1p2t1 > h1p1t2", h1p2t1.compareTo(h1p1t2) > 0); + assertTrue("h1p2t2 > h1p1t2", h1p2t2.compareTo(h1p1t2) > 0); + } + + public void testCompareTasksOnDifferentHosts() { + assertTrue("h1p1t1 < h2p2t2", h1p1t1.compareTo(h2p2t2) < 0); + assertTrue("h2p2t2 > h1p1t1", h2p2t2.compareTo(h1p1t1) > 0); + assertTrue("h1p2t2 < h2p1t1", h1p2t2.compareTo(h2p1t1) < 0); + assertTrue("h2p1t1 > h1p2t2", h2p1t1.compareTo(h1p2t2) > 0); + } +} diff --git a/frysk-core/frysk/proc/dummy/ChangeLog b/frysk-core/frysk/proc/dummy/ChangeLog index 4b86ce2..f326bb1 100644 --- a/frysk-core/frysk/proc/dummy/ChangeLog +++ b/frysk-core/frysk/proc/dummy/ChangeLog @@ -1,5 +1,7 @@ 2008-02-08 Andrew Cagney <cagney@redhat.com> + * DummyTask.java (DummyTask(Proc,int)): New. + * DummyProc.java (DummyProc(DummyHost,int)): New. * DummyHost.java (getName()): Implement. (DummyHost(String)): New. diff --git a/frysk-core/frysk/proc/dummy/DummyTask.java b/frysk-core/frysk/proc/dummy/DummyTask.java index 27a0b9e..f01de93 100644 --- a/frysk-core/frysk/proc/dummy/DummyTask.java +++ b/frysk-core/frysk/proc/dummy/DummyTask.java @@ -45,11 +45,15 @@ import frysk.isa.ISA; import frysk.isa.banks.RegisterBanks; import frysk.proc.Task; import frysk.proc.Proc; +import frysk.proc.TaskId; public class DummyTask extends Task { public DummyTask (Proc parent) { - super (parent, (TaskObserver.Attached) null); + super (parent, new TaskId(parent.getPid())); + } + public DummyTask (Proc parent, int pid) { + super(parent, new TaskId(pid)); } public String getStateString() { return "Attached"; hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-02-08 16:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080208164254.19073.qmail@sourceware.org \ --to=cagney@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).