use -s to test single-process ptql queries

This commit is contained in:
Doug MacEachern 2006-08-25 00:16:00 +00:00
parent 4b5a270033
commit 84dcdd1fa6
1 changed files with 35 additions and 11 deletions

View File

@ -26,6 +26,8 @@ import org.hyperic.sigar.SigarPermissionDeniedException;
*/ */
public class ProcInfo extends SigarCommandBase { public class ProcInfo extends SigarCommandBase {
private boolean isSingleProcess;
public ProcInfo(Shell shell) { public ProcInfo(Shell shell) {
super(shell); super(shell);
} }
@ -47,25 +49,47 @@ public class ProcInfo extends SigarCommandBase {
} }
public void output(String[] args) throws SigarException { public void output(String[] args) throws SigarException {
long[] pids = this.shell.findPids(args); this.isSingleProcess = false;
for (int i=0; i<pids.length; i++) { if ((args.length != 0) && args[0].startsWith("-s")) {
try { this.isSingleProcess = true;
output(pids[i]); }
} catch (SigarPermissionDeniedException e) {
println(this.shell.getUserDeniedMessage(pids[i])); if (this.isSingleProcess) {
} catch (SigarException e) { for (int i=1; i<args.length; i++) {
println("(" + e.getMessage() + ")"); try {
output(args[i]);
} catch (SigarException e) {
println("(" + e.getMessage() + ")");
}
println("\n------------------------\n");
}
}
else {
long[] pids = this.shell.findPids(args);
for (int i=0; i<pids.length; i++) {
try {
output(String.valueOf(pids[i]));
} catch (SigarPermissionDeniedException e) {
println(this.shell.getUserDeniedMessage(pids[i]));
} catch (SigarException e) {
println("(" + e.getMessage() + ")");
}
println("\n------------------------\n");
} }
println("\n------------------------\n");
} }
} }
public void output(long pid) throws SigarException { public void output(String pid) throws SigarException {
println("pid=" + pid); println("pid=" + pid);
try { try {
println("state=" + sigar.getProcState(pid)); println("state=" + sigar.getProcState(pid));
} catch (SigarException e) {} } catch (SigarException e) {
if (this.isSingleProcess) {
println(e.getMessage());
}
}
try { try {
println("mem=" + sigar.getProcMem(pid)); println("mem=" + sigar.getProcMem(pid));
} catch (SigarException e) {} } catch (SigarException e) {}