support pid other than self

This commit is contained in:
Doug MacEachern 2008-10-18 22:41:17 +00:00
parent befbdf13d2
commit 27a8d74436
1 changed files with 18 additions and 7 deletions

View File

@ -35,6 +35,7 @@ public class SigarProcess implements SigarProcessMBean {
private Sigar sigarImpl; private Sigar sigarImpl;
private SigarProxy sigar; private SigarProxy sigar;
private long pid = -1;
public SigarProcess() { public SigarProcess() {
this(new Sigar()); this(new Sigar());
@ -59,8 +60,7 @@ public class SigarProcess implements SigarProcessMBean {
private synchronized ProcMem getMem() { private synchronized ProcMem getMem() {
try { try {
long pid = this.sigar.getPid(); return this.sigar.getProcMem(getPid());
return this.sigar.getProcMem(pid);
} catch (SigarException e) { } catch (SigarException e) {
throw unexpectedError("Mem", e); throw unexpectedError("Mem", e);
} }
@ -68,8 +68,7 @@ public class SigarProcess implements SigarProcessMBean {
private synchronized ProcCpu getCpu() { private synchronized ProcCpu getCpu() {
try { try {
long pid = this.sigar.getPid(); return this.sigar.getProcCpu(getPid());
return this.sigar.getProcCpu(pid);
} catch (SigarException e) { } catch (SigarException e) {
throw unexpectedError("Cpu", e); throw unexpectedError("Cpu", e);
} }
@ -77,13 +76,25 @@ public class SigarProcess implements SigarProcessMBean {
private synchronized ProcFd getFd() { private synchronized ProcFd getFd() {
try { try {
long pid = this.sigar.getPid(); return this.sigar.getProcFd(getPid());
return this.sigar.getProcFd(pid);
} catch (SigarException e) { } catch (SigarException e) {
throw unexpectedError("Fd", e); throw unexpectedError("Fd", e);
} }
} }
public long getPid() {
if (this.pid < 0) {
return this.sigar.getPid();
}
else {
return this.pid;
}
}
public void setPid(long pid) {
this.pid = pid;
}
public Long getMemSize() { public Long getMemSize() {
return new Long(getMem().getSize()); return new Long(getMem().getSize());
} }