本文整理匯總了Java中org.hyperic.sigar.Sigar.getProcMem方法的典型用法代碼示例。如果您正苦於以下問題:Java Sigar.getProcMem方法的具體用法?Java Sigar.getProcMem怎麽用?Java Sigar.getProcMem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hyperic.sigar.Sigar
的用法示例。
在下文中一共展示了Sigar.getProcMem方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Sigar sigar = new Sigar();
if (args.length != 1) {
throw new Exception("Usage: MemWatch pid");
}
long pid = Long.parseLong(args[0]);
long lastTime = System.currentTimeMillis();
ProcMem last = sigar.getProcMem(pid);
while (true) {
ProcMem cur = sigar.getProcMem(pid);
StringBuffer diff = diff(last, cur);
if (diff.length() == 0) {
System.out.println("no change " +
"(size=" +
Sigar.formatSize(cur.getSize()) +
")");
}
else {
long curTime = System.currentTimeMillis();
long timeDiff = curTime - lastTime;
lastTime = curTime;
diff.append(" after " + timeDiff + "ms");
System.out.println(diff);
}
last = cur;
Thread.sleep(SLEEP_TIME);
}
}
示例2: measureMemory
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private void measureMemory(String id, String uid, Collector collector) throws Exception {
// see https://support.hyperic.com/display/SIGAR/PTQL
Sigar sigar = new Sigar();
final ProcessFinder processFinder = new ProcessFinder(sigar);
long pid = processFinder.findSingleProcess("State.Name.eq=java,Args.1.ct="+uid);
Jcmd.gc(pid);
ProcMem procMem = sigar.getProcMem(pid);
long rss = procMem.getResident();
collector.onMeasurement(id, Measure.RSS_AFTER_INVOCATION, bytesToMegabytes(rss));
long javaHeap = Jstat.usedHeap(pid);
collector.onMeasurement(id, Measure.JAVA_HEAP_AFTER_INVOCATION, bytesToMegabytes(javaHeap));
}