args[0]); ProcfsBasedProcessTree procfsBasedProcessTree = new ProcfsBasedProcessTree(args[0]); procfsBasedProcessTree.updateProcessTree(); System.out.println(procfsBasedProcessTree.getProcessTreeDump()); System.out.println("Get cpu usage " + procfsBasedProcessTree .getCpuUsagePercent()); procfsBasedProcessTree.updateProcessTree(); System.out.println(procfsBasedProcessTree.getProcessTreeDump()); System.out.println("Cpu usage " + procfsBasedProcessTree .getCpuUsagePercent()); System.out.println("Vmem usage in bytes " + procfsBasedProcessTree .getVirtualMemorySize()); System.out.println("Rss mem usage in bytes " + procfsBasedProcessTree .getRssMemorySize());
/** Verify that the given process id is same as its process group id. * @return true if the process id matches else return false. */ @Override public boolean checkPidPgrpidForMatch() { return checkPidPgrpidForMatch(pid, PROCFS); }
@Override public float getCpuUsagePercent() { float cgroupUsage = cgroup.getCpuUsagePercent(); if (LOG.isDebugEnabled()) { float procfsUsage = procfs.getCpuUsagePercent(); LOG.debug("CPU Comparison:" + procfsUsage + " " + cgroupUsage); LOG.debug("Jiffy Comparison:" + procfs.getCumulativeCpuTime() + " " + cgroup.getCumulativeCpuTime()); } return cgroupUsage; }
ProcfsBasedProcessTree processTree = createProcessTree("100", procfsRootDir.getAbsolutePath(), testClock); processTree.setConf(conf); processTree.updateProcessTree(); processTree.getVirtualMemorySize()); ResourceCalculatorProcessTree.UNAVAILABLE; Assert.assertEquals("rss memory does not match", cumuRssMem, processTree.getRssMemorySize()); ? 7200L * ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS : 0L; Assert.assertEquals("Cumulative cpu time does not match", cumuCpuTime, processTree.getCumulativeCpuTime()); -1.0, processTree.getCpuUsagePercent(), 0.01); (20 * KB_TO_BYTES * 3), processTree.getRssMemorySize()); processTree.updateProcessTree(); ? 9400L * ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS : 0L; Assert.assertEquals("Cumulative cpu time does not match", cumuCpuTime, processTree.getCumulativeCpuTime()); Assert.assertEquals("Percent CPU time is not correct expected " + expectedCpuUsagePercent, expectedCpuUsagePercent,
public void testProcessTree() throws Exception { try { Assert.assertTrue(ProcfsBasedProcessTree.isAvailable()); } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); LOG.info("Root process pid: " + pid); ProcfsBasedProcessTree p = createProcessTree(pid); p.updateProcessTree(); // initialize LOG.info("ProcessTree: " + p.toString()); p.updateProcessTree(); // reconstruct LOG.info("ProcessTree: " + p.toString()); LOG.info("Orphaned pid: " + lostpid); Assert.assertTrue("Child process owned by init escaped process tree.", p.contains(lostpid)); String processTreeDump = p.getProcessTreeDump(); p.updateProcessTree(); Assert.assertFalse("ProcessTree must have been gone", isAlive(pid)); "vmem for the gone-process is " + p.getVirtualMemorySize() + " . It should be UNAVAILABLE(-1).", p.getVirtualMemorySize() == UNAVAILABLE); Assert.assertTrue( "vmem (old API) for the gone-process is " + p.getCumulativeVmem() + " . It should be UNAVAILABLE(-1).",
processTree.getVirtualMemorySize()); processTree.getCumulativeVmem()); processTree.updateProcessTree(); Assert.assertEquals("vmem does not include new process", 1200000L, processTree.getVirtualMemorySize()); 1200000L, processTree.getCumulativeVmem()); ResourceCalculatorProcessTree.UNAVAILABLE; Assert.assertEquals("rssmem does not include new process", cumuRssMem, processTree.getRssMemorySize()); cumuRssMem, processTree.getCumulativeRssmem()); } else { Assert.assertEquals("rssmem does not include new process", 100 * KB_TO_BYTES * 4, processTree.getRssMemorySize()); 100 * KB_TO_BYTES * 4, processTree.getCumulativeRssmem()); processTree.getVirtualMemorySize(1)); processTree.getCumulativeVmem(1)); Assert.assertEquals( "rssmem shouldn't have included new process", cumuRssMem, processTree.getRssMemorySize(1));
SystemClock.getInstance()); processTree.updateProcessTree(); String processTreeDump = processTree.getProcessTreeDump();
private void setSmapsInProceTree(ProcfsBasedProcessTree processTree, boolean enableFlag) { Configuration conf = processTree.getConf(); if (conf == null) { conf = new Configuration(); } conf.setBoolean(YarnConfiguration.PROCFS_USE_SMAPS_BASED_RSS_ENABLED, enableFlag); processTree.setConf(conf); processTree.updateProcessTree(); }
if (ProcfsBasedProcessTree.isAvailable()) { return new ProcfsBasedProcessTree(pid);
processTree.getVirtualMemorySize()); processTree.updateProcessTree(); Assert.assertEquals("vmem does not include new process", 1200000L, processTree.getVirtualMemorySize()); if (!smapEnabled) { long cumuRssMem = ResourceCalculatorProcessTree.UNAVAILABLE; Assert.assertEquals("rssmem does not include new process", cumuRssMem, processTree.getRssMemorySize()); } else { Assert.assertEquals("rssmem does not include new process", 20 * KB_TO_BYTES * 4, processTree.getRssMemorySize()); processTree.getVirtualMemorySize(1)); if (!smapEnabled) { long cumuRssMem = Assert.assertEquals( "rssmem shouldn't have included new process", cumuRssMem, processTree.getRssMemorySize(1)); } else { Assert.assertEquals( "rssmem shouldn't have included new process", 20 * KB_TO_BYTES * 3, processTree.getRssMemorySize(1)); processTree.updateProcessTree();
if (!pid.equals(deadPid)) { List<String> processList = getProcessList(); if (constructProcessInfo(pInfo, procfsDir) != null) { allProcessInfo.put(proc, pInfo); if (proc.equals(this.pid)) { LOG.debug(this.toString()); constructProcessSMAPInfo(memInfo, procfsDir); processSMAPTree.put(p.getPid(), memInfo);
public CombinedResourceCalculator(String pid) { super(pid); procfs = new ProcfsBasedProcessTree(pid); cgroup = new CGroupsResourceCalculator(pid); }
@Override @SuppressWarnings("deprecation") public long getCumulativeVmem(int olderThanAge) { return getVirtualMemorySize(olderThanAge); }
@Override @SuppressWarnings("deprecation") public long getCumulativeRssmem(int olderThanAge) { return getRssMemorySize(olderThanAge); }
@Override public String getProcessTreeDump() { return procfs.getProcessTreeDump(); }
@Override public void updateProcessTree() { procfs.updateProcessTree(); cgroup.updateProcessTree(); }
@Override public long getCumulativeCpuTime() { if (LOG.isDebugEnabled()) { LOG.debug("CPU Comparison:" + procfs.getCumulativeCpuTime() + " " + cgroup.getCumulativeCpuTime()); } return cgroup.getCumulativeCpuTime(); }
ProcfsBasedProcessTree processTree = createProcessTree("100", procfsRootDir.getAbsolutePath(), testClock); processTree.setConf(conf); processTree.updateProcessTree(); processTree.getVirtualMemorySize()); ResourceCalculatorProcessTree.UNAVAILABLE; Assert.assertEquals("rss memory does not match", cumuRssMem, processTree.getRssMemorySize()); processTree.getCumulativeRssmem()); ? 7200L * ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS : 0L; Assert.assertEquals("Cumulative cpu time does not match", cumuCpuTime, processTree.getCumulativeCpuTime()); -1.0, processTree.getCpuUsagePercent(), 0.01); (100 * KB_TO_BYTES * 3), processTree.getRssMemorySize()); (100 * KB_TO_BYTES * 3), processTree.getCumulativeRssmem()); processTree.updateProcessTree(); ? 9400L * ProcfsBasedProcessTree.JIFFY_LENGTH_IN_MILLIS : 0L; Assert.assertEquals("Cumulative cpu time does not match", cumuCpuTime,
public void testProcessTree() throws Exception { try { Assert.assertTrue(ProcfsBasedProcessTree.isAvailable()); } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); LOG.info("Root process pid: " + pid); ProcfsBasedProcessTree p = createProcessTree(pid); p.updateProcessTree(); // initialize LOG.info("ProcessTree: " + p.toString()); p.updateProcessTree(); // reconstruct LOG.info("ProcessTree: " + p.toString()); LOG.info("Orphaned pid: " + lostpid); Assert.assertTrue("Child process owned by init escaped process tree.", p.contains(lostpid)); String processTreeDump = p.getProcessTreeDump(); p.updateProcessTree(); Assert.assertFalse("ProcessTree must have been gone", isAlive(pid)); "vmem for the gone-process is " + p.getVirtualMemorySize() + " . It should be UNAVAILABLE(-1).", p.getVirtualMemorySize() == UNAVAILABLE); Assert.assertTrue( "vmem (old API) for the gone-process is " + p.getCumulativeVmem() + " . It should be UNAVAILABLE(-1).",
processTree.getVirtualMemorySize()); processTree.getCumulativeVmem()); processTree.updateProcessTree(); Assert.assertEquals("vmem does not include new process", 1200000L, processTree.getVirtualMemorySize()); 1200000L, processTree.getCumulativeVmem()); ResourceCalculatorProcessTree.UNAVAILABLE; Assert.assertEquals("rssmem does not include new process", cumuRssMem, processTree.getRssMemorySize()); cumuRssMem, processTree.getCumulativeRssmem()); } else { Assert.assertEquals("rssmem does not include new process", 100 * KB_TO_BYTES * 4, processTree.getRssMemorySize()); 100 * KB_TO_BYTES * 4, processTree.getCumulativeRssmem()); processTree.getVirtualMemorySize(1)); processTree.getCumulativeVmem(1)); Assert.assertEquals( "rssmem shouldn't have included new process", cumuRssMem, processTree.getRssMemorySize(1));