當前位置: 首頁>>代碼示例>>Java>>正文


Java Sigar.getProcMem方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:37,代碼來源:MemWatch.java

示例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));
}
 
開發者ID:wildfly-swarm,項目名稱:process-monitor,代碼行數:16,代碼來源:Monitor.java


注:本文中的org.hyperic.sigar.Sigar.getProcMem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。