-
-
Save ricston-git/8d2e63bb2f62c0ad65b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create a sigar object | |
Sigar sigar = new Sigar(); | |
for (int i = 0; i < 100; i++) { | |
ProcessFinder find = new ProcessFinder(sigar); | |
//get the list of current java processes, and optionally query the list to choose which process to monitor | |
long[] pidList = sigar.getProcList(); | |
//assuming we know the process id, we may query the process finder | |
long pid = find.findSingleProcess("Pid.Pid.eq=54730"); | |
//get memory info for the process id | |
ProcMem memory = new ProcMem(); | |
memory.gather(sigar, pid); | |
//get cou info for the oricess id | |
ProcCpu cpu = new ProcCpu(); | |
cpu.gather(sigar, pid); | |
//print the memory used by the process id | |
System.out.println("Current memory used: " + Long.toString(memory.getSize())); | |
//print all memory info | |
System.out.println(memory.toMap()); | |
//print all cpu info | |
System.out.println(cpu.toMap()); | |
Thread.sleep(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment