Added Sigar.getProcDiskIO to Java API on Linux
Returns the total bytes read and written for a process using /proc/pid/io.
This commit is contained in:
1 parent
ec489fb336
commit
a62558af50
7 files changed
+122
-1
No files matched your search
@@ -627,6 +627,18 @@ use vars qw(%classes %cmds);
|
||||
plat => '*'
|
||||
},
|
||||
],
|
||||
ProcDiskIO => [
|
||||
{
|
||||
name => 'bytes_read', type => 'Long',
|
||||
desc => 'Bytes Read',
|
||||
plat => 'L'
|
||||
},
|
||||
{
|
||||
name => 'bytes_written', type => 'Long',
|
||||
desc => 'Bytes Written',
|
||||
plat => 'L'
|
||||
}
|
||||
],
|
||||
ProcState => [
|
||||
{
|
||||
name => 'state', type => 'Char',
|
||||
|
||||
@@ -440,7 +440,7 @@ public class Sigar implements SigarProxy {
|
||||
return this.processFinder.findSingleProcess(pid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get process memory info.
|
||||
* @param pid The process id.
|
||||
@@ -638,6 +638,29 @@ public class Sigar implements SigarProxy {
|
||||
Integer.parseInt(port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get process disk IO info.
|
||||
* @param pid THe process id.
|
||||
* @exception SigarException on failure.
|
||||
*/
|
||||
public ProcDiskIO getProcDiskIO(long pid) throws SigarException {
|
||||
try {
|
||||
return ProcDiskIO.fetch(this, pid);
|
||||
} catch (UnsatisfiedLinkError linkErrorException) {
|
||||
// We want to handle exceptions gracefully even if the linked
|
||||
// shared library is older and isn't compiled with the ProcDiskIO APIs.
|
||||
// The downside of this is that we throw SigarNotImplemented exception
|
||||
// also when the shared library can't be loaded.
|
||||
SigarException sigarException = new SigarNotImplementedException();
|
||||
sigarException.initCause(linkErrorException);
|
||||
throw sigarException;
|
||||
}
|
||||
}
|
||||
|
||||
public ProcDiskIO getProcDiskIO(String pid) throws SigarException {
|
||||
return getProcDiskIO(convertPid(pid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cumulative cpu time for the calling thread.
|
||||
*/
|
||||
|
||||
@@ -106,6 +106,10 @@ public interface SigarProxy {
|
||||
|
||||
public long getProcPort(String protocol, String port) throws SigarException;
|
||||
|
||||
public ProcDiskIO getProcDiskIO(long pid) throws SigarException;
|
||||
|
||||
public ProcDiskIO getProcDiskIO(String pid) throws SigarException;
|
||||
|
||||
public FileSystem[] getFileSystemList() throws SigarException;
|
||||
|
||||
public FileSystemMap getFileSystemMap() throws SigarException;
|
||||
|
||||
@@ -100,6 +100,9 @@ public class ProcInfo extends SigarCommandBase {
|
||||
try {
|
||||
println("credname=" + sigar.getProcCredName(pid));
|
||||
} catch (SigarException e) {}
|
||||
try {
|
||||
println("diskio=" + sigar.getProcDiskIO(pid));
|
||||
} catch (SigarException e) {}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.hyperic.sigar.test;
|
||||
|
||||
import org.hyperic.sigar.ProcDiskIO;
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.SigarException;
|
||||
|
||||
public class TestProcDiskIO extends SigarTestCase {
|
||||
|
||||
public TestProcDiskIO(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
private void traceDiskIO(Sigar sigar, long pid) throws Exception {
|
||||
ProcDiskIO procDiskIO;
|
||||
|
||||
try {
|
||||
procDiskIO = sigar.getProcDiskIO(pid);
|
||||
} catch (SigarException e) {
|
||||
traceln("pid " + pid + ": " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
traceln("Pid=" + pid);
|
||||
traceln("Bytes Read=" + Sigar.formatSize(procDiskIO.getBytesRead()));
|
||||
traceln("Bytes Written=" + Sigar.formatSize(procDiskIO.getBytesWritten()));
|
||||
}
|
||||
|
||||
public void testCreate() throws Exception {
|
||||
Sigar sigar = getSigar();
|
||||
|
||||
try {
|
||||
sigar.getProcDiskIO(getInvalidPid());
|
||||
} catch (SigarException e) {
|
||||
}
|
||||
|
||||
long[] pids = sigar.getProcList();
|
||||
for (int i=0; i<pids.length; i++) {
|
||||
traceDiskIO(sigar, pids[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user