YARN-3304. Addendum patch. Cleaning up ResourceCalculatorProcessTree APIs for public use and removing inconsistencies in the default values. (Junping Du and Karthik Kambatla via vinodkv)
This commit is contained in:
parent
18a91fe4df
commit
7610925e90
@ -344,16 +344,24 @@ public String getProcessTreeDump() {
|
|||||||
public long getVirtualMemorySize(int olderThanAge) {
|
public long getVirtualMemorySize(int olderThanAge) {
|
||||||
long total = UNAVAILABLE;
|
long total = UNAVAILABLE;
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
if ((p != null) && (p.getAge() > olderThanAge)) {
|
if (p != null) {
|
||||||
if (total == UNAVAILABLE ) {
|
if (total == UNAVAILABLE ) {
|
||||||
total = 0;
|
total = 0;
|
||||||
}
|
}
|
||||||
total += p.getVmem();
|
if (p.getAge() > olderThanAge) {
|
||||||
|
total += p.getVmem();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeVmem(int olderThanAge) {
|
||||||
|
return getVirtualMemorySize(olderThanAge);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getRssMemorySize(int olderThanAge) {
|
public long getRssMemorySize(int olderThanAge) {
|
||||||
if (PAGE_SIZE < 0) {
|
if (PAGE_SIZE < 0) {
|
||||||
@ -365,14 +373,22 @@ public long getRssMemorySize(int olderThanAge) {
|
|||||||
boolean isAvailable = false;
|
boolean isAvailable = false;
|
||||||
long totalPages = 0;
|
long totalPages = 0;
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
if ((p != null) && (p.getAge() > olderThanAge)) {
|
if ((p != null) ) {
|
||||||
totalPages += p.getRssmemPage();
|
if (p.getAge() > olderThanAge) {
|
||||||
|
totalPages += p.getRssmemPage();
|
||||||
|
}
|
||||||
isAvailable = true;
|
isAvailable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isAvailable ? totalPages * PAGE_SIZE : UNAVAILABLE; // convert # pages to byte
|
return isAvailable ? totalPages * PAGE_SIZE : UNAVAILABLE; // convert # pages to byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeRssmem(int olderThanAge) {
|
||||||
|
return getRssMemorySize(olderThanAge);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the resident set size (RSS) memory used by all the processes
|
* Get the resident set size (RSS) memory used by all the processes
|
||||||
* in the process-tree that are older than the passed in age. RSS is
|
* in the process-tree that are older than the passed in age. RSS is
|
||||||
@ -388,36 +404,42 @@ public long getRssMemorySize(int olderThanAge) {
|
|||||||
private long getSmapBasedRssMemorySize(int olderThanAge) {
|
private long getSmapBasedRssMemorySize(int olderThanAge) {
|
||||||
long total = UNAVAILABLE;
|
long total = UNAVAILABLE;
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
if ((p != null) && (p.getAge() > olderThanAge)) {
|
if (p != null) {
|
||||||
ProcessTreeSmapMemInfo procMemInfo = processSMAPTree.get(p.getPid());
|
// set resource to 0 instead of UNAVAILABLE
|
||||||
if (procMemInfo != null) {
|
if (total == UNAVAILABLE){
|
||||||
for (ProcessSmapMemoryInfo info : procMemInfo.getMemoryInfoList()) {
|
total = 0;
|
||||||
// Do not account for r--s or r-xs mappings
|
}
|
||||||
if (info.getPermission().trim()
|
if (p.getAge() > olderThanAge) {
|
||||||
.equalsIgnoreCase(READ_ONLY_WITH_SHARED_PERMISSION)
|
ProcessTreeSmapMemInfo procMemInfo = processSMAPTree.get(p.getPid());
|
||||||
|| info.getPermission().trim()
|
if (procMemInfo != null) {
|
||||||
.equalsIgnoreCase(READ_EXECUTE_WITH_SHARED_PERMISSION)) {
|
for (ProcessSmapMemoryInfo info : procMemInfo.getMemoryInfoList()) {
|
||||||
continue;
|
// Do not account for r--s or r-xs mappings
|
||||||
}
|
if (info.getPermission().trim()
|
||||||
if (total == UNAVAILABLE){
|
.equalsIgnoreCase(READ_ONLY_WITH_SHARED_PERMISSION)
|
||||||
total = 0;
|
|| info.getPermission().trim()
|
||||||
}
|
.equalsIgnoreCase(READ_EXECUTE_WITH_SHARED_PERMISSION)) {
|
||||||
total +=
|
continue;
|
||||||
Math.min(info.sharedDirty, info.pss) + info.privateDirty
|
}
|
||||||
+ info.privateClean;
|
|
||||||
if (LOG.isDebugEnabled()) {
|
total +=
|
||||||
LOG.debug(" total(" + olderThanAge + "): PID : " + p.getPid()
|
Math.min(info.sharedDirty, info.pss) + info.privateDirty
|
||||||
+ ", SharedDirty : " + info.sharedDirty + ", PSS : "
|
+ info.privateClean;
|
||||||
+ info.pss + ", Private_Dirty : " + info.privateDirty
|
if (LOG.isDebugEnabled()) {
|
||||||
+ ", Private_Clean : " + info.privateClean + ", total : "
|
LOG.debug(" total(" + olderThanAge + "): PID : " + p.getPid()
|
||||||
+ (total * KB_TO_BYTES));
|
+ ", SharedDirty : " + info.sharedDirty + ", PSS : "
|
||||||
|
+ info.pss + ", Private_Dirty : " + info.privateDirty
|
||||||
|
+ ", Private_Clean : " + info.privateClean + ", total : "
|
||||||
|
+ (total * KB_TO_BYTES));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug(procMemInfo.toString());
|
LOG.debug(procMemInfo.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
total *= KB_TO_BYTES; // convert to bytes
|
total *= KB_TO_BYTES; // convert to bytes
|
||||||
|
@ -79,6 +79,18 @@ public long getVirtualMemorySize() {
|
|||||||
return getVirtualMemorySize(0);
|
return getVirtualMemorySize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the virtual memory used by all the processes in the
|
||||||
|
* process-tree.
|
||||||
|
*
|
||||||
|
* @return virtual memory used by the process-tree in bytes,
|
||||||
|
* {@link #UNAVAILABLE} if it cannot be calculated.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCumulativeVmem() {
|
||||||
|
return getCumulativeVmem(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the resident set size (rss) memory used by all the processes
|
* Get the resident set size (rss) memory used by all the processes
|
||||||
* in the process-tree.
|
* in the process-tree.
|
||||||
@ -90,6 +102,18 @@ public long getRssMemorySize() {
|
|||||||
return getRssMemorySize(0);
|
return getRssMemorySize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the resident set size (rss) memory used by all the processes
|
||||||
|
* in the process-tree.
|
||||||
|
*
|
||||||
|
* @return rss memory used by the process-tree in bytes,
|
||||||
|
* {@link #UNAVAILABLE} if it cannot be calculated.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCumulativeRssmem() {
|
||||||
|
return getCumulativeRssmem(0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the virtual memory used by all the processes in the
|
* Get the virtual memory used by all the processes in the
|
||||||
* process-tree that are older than the passed in age.
|
* process-tree that are older than the passed in age.
|
||||||
@ -104,6 +128,21 @@ public long getVirtualMemorySize(int olderThanAge) {
|
|||||||
return UNAVAILABLE;
|
return UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the virtual memory used by all the processes in the
|
||||||
|
* process-tree that are older than the passed in age.
|
||||||
|
*
|
||||||
|
* @param olderThanAge processes above this age are included in the
|
||||||
|
* memory addition
|
||||||
|
* @return virtual memory used by the process-tree in bytes for
|
||||||
|
* processes older than the specified age, {@link #UNAVAILABLE} if it
|
||||||
|
* cannot be calculated.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCumulativeVmem(int olderThanAge) {
|
||||||
|
return UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the resident set size (rss) memory used by all the processes
|
* Get the resident set size (rss) memory used by all the processes
|
||||||
* in the process-tree that are older than the passed in age.
|
* in the process-tree that are older than the passed in age.
|
||||||
@ -118,6 +157,21 @@ public long getRssMemorySize(int olderThanAge) {
|
|||||||
return UNAVAILABLE;
|
return UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the resident set size (rss) memory used by all the processes
|
||||||
|
* in the process-tree that are older than the passed in age.
|
||||||
|
*
|
||||||
|
* @param olderThanAge processes above this age are included in the
|
||||||
|
* memory addition
|
||||||
|
* @return rss memory used by the process-tree in bytes for
|
||||||
|
* processes older than specified age, {@link #UNAVAILABLE} if it cannot be
|
||||||
|
* calculated.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCumulativeRssmem(int olderThanAge) {
|
||||||
|
return UNAVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the CPU time in millisecond used by all the processes in the
|
* Get the CPU time in millisecond used by all the processes in the
|
||||||
* process-tree since the process-tree was created
|
* process-tree since the process-tree was created
|
||||||
@ -158,7 +212,6 @@ public float getCpuUsagePercent() {
|
|||||||
* @return ResourceCalculatorProcessTree or null if ResourceCalculatorPluginTree
|
* @return ResourceCalculatorProcessTree or null if ResourceCalculatorPluginTree
|
||||||
* is not available for this system.
|
* is not available for this system.
|
||||||
*/
|
*/
|
||||||
@Private
|
|
||||||
public static ResourceCalculatorProcessTree getResourceCalculatorProcessTree(
|
public static ResourceCalculatorProcessTree getResourceCalculatorProcessTree(
|
||||||
String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf) {
|
String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf) {
|
||||||
|
|
||||||
|
@ -176,30 +176,46 @@ public String getProcessTreeDump() {
|
|||||||
public long getVirtualMemorySize(int olderThanAge) {
|
public long getVirtualMemorySize(int olderThanAge) {
|
||||||
long total = UNAVAILABLE;
|
long total = UNAVAILABLE;
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
if ((p != null) && (p.age > olderThanAge)) {
|
if (p != null) {
|
||||||
if (total == UNAVAILABLE) {
|
if (total == UNAVAILABLE) {
|
||||||
total = 0;
|
total = 0;
|
||||||
}
|
}
|
||||||
total += p.vmem;
|
if (p.age > olderThanAge) {
|
||||||
|
total += p.vmem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeVmem(int olderThanAge) {
|
||||||
|
return getVirtualMemorySize(olderThanAge);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getRssMemorySize(int olderThanAge) {
|
public long getRssMemorySize(int olderThanAge) {
|
||||||
long total = UNAVAILABLE;
|
long total = UNAVAILABLE;
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
if ((p != null) && (p.age > olderThanAge)) {
|
if (p != null) {
|
||||||
if (total == UNAVAILABLE) {
|
if (total == UNAVAILABLE) {
|
||||||
total = 0;
|
total = 0;
|
||||||
}
|
}
|
||||||
total += p.workingSet;
|
if (p.age > olderThanAge) {
|
||||||
|
total += p.workingSet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeRssmem(int olderThanAge) {
|
||||||
|
return getRssMemorySize(olderThanAge);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCumulativeCpuTime() {
|
public long getCumulativeCpuTime() {
|
||||||
for (ProcessInfo p : processTree.values()) {
|
for (ProcessInfo p : processTree.values()) {
|
||||||
|
@ -117,6 +117,7 @@ public void setup() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testProcessTree() throws Exception {
|
public void testProcessTree() throws Exception {
|
||||||
try {
|
try {
|
||||||
Assert.assertTrue(ProcfsBasedProcessTree.isAvailable());
|
Assert.assertTrue(ProcfsBasedProcessTree.isAvailable());
|
||||||
@ -226,9 +227,13 @@ public void testProcessTree() throws Exception {
|
|||||||
// ProcessTree is gone now. Any further calls should be sane.
|
// ProcessTree is gone now. Any further calls should be sane.
|
||||||
p.updateProcessTree();
|
p.updateProcessTree();
|
||||||
Assert.assertFalse("ProcessTree must have been gone", isAlive(pid));
|
Assert.assertFalse("ProcessTree must have been gone", isAlive(pid));
|
||||||
|
|
||||||
Assert.assertTrue(
|
Assert.assertTrue(
|
||||||
"vmem for the gone-process is " + p.getVirtualMemorySize()
|
"vmem for the gone-process is " + p.getVirtualMemorySize()
|
||||||
+ " . It should be zero.", p.getVirtualMemorySize() == 0);
|
+ " . It should be zero.", p.getVirtualMemorySize() == 0);
|
||||||
|
Assert.assertTrue(
|
||||||
|
"vmem (old API) for the gone-process is " + p.getCumulativeVmem()
|
||||||
|
+ " . It should be zero.", p.getCumulativeVmem() == 0);
|
||||||
Assert.assertTrue(p.toString().equals("[ ]"));
|
Assert.assertTrue(p.toString().equals("[ ]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,6 +390,7 @@ public void createMemoryMappingInfo(ProcessTreeSmapMemInfo[] procMemInfo) {
|
|||||||
* files.
|
* files.
|
||||||
*/
|
*/
|
||||||
@Test(timeout = 30000)
|
@Test(timeout = 30000)
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testCpuAndMemoryForProcessTree() throws IOException {
|
public void testCpuAndMemoryForProcessTree() throws IOException {
|
||||||
|
|
||||||
// test processes
|
// test processes
|
||||||
@ -437,9 +443,13 @@ public void testCpuAndMemoryForProcessTree() throws IOException {
|
|||||||
// verify rss memory
|
// verify rss memory
|
||||||
long cumuRssMem =
|
long cumuRssMem =
|
||||||
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
||||||
? 600L * ProcfsBasedProcessTree.PAGE_SIZE : 0L;
|
? 600L * ProcfsBasedProcessTree.PAGE_SIZE :
|
||||||
|
ResourceCalculatorProcessTree.UNAVAILABLE;
|
||||||
Assert.assertEquals("rss memory does not match", cumuRssMem,
|
Assert.assertEquals("rss memory does not match", cumuRssMem,
|
||||||
processTree.getRssMemorySize());
|
processTree.getRssMemorySize());
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals("rss memory (old API) does not match", cumuRssMem,
|
||||||
|
processTree.getCumulativeRssmem());
|
||||||
|
|
||||||
// verify cumulative cpu time
|
// verify cumulative cpu time
|
||||||
long cumuCpuTime =
|
long cumuCpuTime =
|
||||||
@ -459,6 +469,9 @@ public void testCpuAndMemoryForProcessTree() throws IOException {
|
|||||||
// r--s)
|
// r--s)
|
||||||
Assert.assertEquals("rss memory does not match",
|
Assert.assertEquals("rss memory does not match",
|
||||||
(100 * KB_TO_BYTES * 3), processTree.getRssMemorySize());
|
(100 * KB_TO_BYTES * 3), processTree.getRssMemorySize());
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals("rss memory (old API) does not match",
|
||||||
|
(100 * KB_TO_BYTES * 3), processTree.getCumulativeRssmem());
|
||||||
|
|
||||||
// test the cpu time again to see if it cumulates
|
// test the cpu time again to see if it cumulates
|
||||||
procInfos[0] =
|
procInfos[0] =
|
||||||
@ -524,6 +537,7 @@ public void testMemForOlderProcesses() throws IOException {
|
|||||||
testMemForOlderProcesses(true);
|
testMemForOlderProcesses(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
||||||
// initial list of processes
|
// initial list of processes
|
||||||
String[] pids = { "100", "200", "300", "400" };
|
String[] pids = { "100", "200", "300", "400" };
|
||||||
@ -565,8 +579,12 @@ private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
|||||||
setSmapsInProceTree(processTree, smapEnabled);
|
setSmapsInProceTree(processTree, smapEnabled);
|
||||||
|
|
||||||
// verify virtual memory
|
// verify virtual memory
|
||||||
Assert.assertEquals("Cumulative memory does not match", 700000L,
|
Assert.assertEquals("Virtual memory does not match", 700000L,
|
||||||
processTree.getVirtualMemorySize());
|
processTree.getVirtualMemorySize());
|
||||||
|
|
||||||
|
Assert.assertEquals("Virtual memory (old API) does not match", 700000L,
|
||||||
|
processTree.getCumulativeVmem());
|
||||||
|
|
||||||
// write one more process as child of 100.
|
// write one more process as child of 100.
|
||||||
String[] newPids = { "500" };
|
String[] newPids = { "500" };
|
||||||
setupPidDirs(procfsRootDir, newPids);
|
setupPidDirs(procfsRootDir, newPids);
|
||||||
@ -584,32 +602,58 @@ private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
|||||||
processTree.updateProcessTree();
|
processTree.updateProcessTree();
|
||||||
Assert.assertEquals("vmem does not include new process",
|
Assert.assertEquals("vmem does not include new process",
|
||||||
1200000L, processTree.getVirtualMemorySize());
|
1200000L, processTree.getVirtualMemorySize());
|
||||||
|
|
||||||
|
Assert.assertEquals("vmem (old API) does not include new process",
|
||||||
|
1200000L, processTree.getCumulativeVmem());
|
||||||
|
|
||||||
if (!smapEnabled) {
|
if (!smapEnabled) {
|
||||||
long cumuRssMem =
|
long cumuRssMem =
|
||||||
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
||||||
? 1200L * ProcfsBasedProcessTree.PAGE_SIZE : 0L;
|
? 1200L * ProcfsBasedProcessTree.PAGE_SIZE :
|
||||||
|
ResourceCalculatorProcessTree.UNAVAILABLE;
|
||||||
Assert.assertEquals("rssmem does not include new process",
|
Assert.assertEquals("rssmem does not include new process",
|
||||||
cumuRssMem, processTree.getRssMemorySize());
|
cumuRssMem, processTree.getRssMemorySize());
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals("rssmem (old API) does not include new process",
|
||||||
|
cumuRssMem, processTree.getCumulativeRssmem());
|
||||||
} else {
|
} else {
|
||||||
Assert.assertEquals("rssmem does not include new process",
|
Assert.assertEquals("rssmem does not include new process",
|
||||||
100 * KB_TO_BYTES * 4, processTree.getRssMemorySize());
|
100 * KB_TO_BYTES * 4, processTree.getRssMemorySize());
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals("rssmem (old API) does not include new process",
|
||||||
|
100 * KB_TO_BYTES * 4, processTree.getCumulativeRssmem());
|
||||||
}
|
}
|
||||||
|
|
||||||
// however processes older than 1 iteration will retain the older value
|
// however processes older than 1 iteration will retain the older value
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"vmem shouldn't have included new process", 700000L,
|
"vmem shouldn't have included new process", 700000L,
|
||||||
processTree.getVirtualMemorySize(1));
|
processTree.getVirtualMemorySize(1));
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"vmem (old API) shouldn't have included new process", 700000L,
|
||||||
|
processTree.getCumulativeVmem(1));
|
||||||
|
|
||||||
if (!smapEnabled) {
|
if (!smapEnabled) {
|
||||||
long cumuRssMem =
|
long cumuRssMem =
|
||||||
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
||||||
? 700L * ProcfsBasedProcessTree.PAGE_SIZE : 0L;
|
? 700L * ProcfsBasedProcessTree.PAGE_SIZE :
|
||||||
|
ResourceCalculatorProcessTree.UNAVAILABLE;
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new process", cumuRssMem,
|
"rssmem shouldn't have included new process", cumuRssMem,
|
||||||
processTree.getRssMemorySize(1));
|
processTree.getRssMemorySize(1));
|
||||||
|
// Verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new process", cumuRssMem,
|
||||||
|
processTree.getCumulativeRssmem(1));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new process",
|
"rssmem shouldn't have included new process",
|
||||||
100 * KB_TO_BYTES * 3, processTree.getRssMemorySize(1));
|
100 * KB_TO_BYTES * 3, processTree.getRssMemorySize(1));
|
||||||
|
// Verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new process",
|
||||||
|
100 * KB_TO_BYTES * 3, processTree.getCumulativeRssmem(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// one more process
|
// one more process
|
||||||
@ -632,17 +676,32 @@ private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
|||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"vmem shouldn't have included new processes", 700000L,
|
"vmem shouldn't have included new processes", 700000L,
|
||||||
processTree.getVirtualMemorySize(2));
|
processTree.getVirtualMemorySize(2));
|
||||||
|
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"vmem (old API) shouldn't have included new processes", 700000L,
|
||||||
|
processTree.getCumulativeVmem(2));
|
||||||
|
|
||||||
if (!smapEnabled) {
|
if (!smapEnabled) {
|
||||||
long cumuRssMem =
|
long cumuRssMem =
|
||||||
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
||||||
? 700L * ProcfsBasedProcessTree.PAGE_SIZE : 0L;
|
? 700L * ProcfsBasedProcessTree.PAGE_SIZE :
|
||||||
|
ResourceCalculatorProcessTree.UNAVAILABLE;
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new processes",
|
"rssmem shouldn't have included new processes",
|
||||||
cumuRssMem, processTree.getRssMemorySize(2));
|
cumuRssMem, processTree.getRssMemorySize(2));
|
||||||
|
// Verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new processes",
|
||||||
|
cumuRssMem, processTree.getCumulativeRssmem(2));
|
||||||
} else {
|
} else {
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new processes",
|
"rssmem shouldn't have included new processes",
|
||||||
100 * KB_TO_BYTES * 3, processTree.getRssMemorySize(2));
|
100 * KB_TO_BYTES * 3, processTree.getRssMemorySize(2));
|
||||||
|
// Verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new processes",
|
||||||
|
100 * KB_TO_BYTES * 3, processTree.getCumulativeRssmem(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// processes older than 1 iteration should not include new process,
|
// processes older than 1 iteration should not include new process,
|
||||||
@ -650,29 +709,46 @@ private void testMemForOlderProcesses(boolean smapEnabled) throws IOException {
|
|||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"vmem shouldn't have included new processes", 1200000L,
|
"vmem shouldn't have included new processes", 1200000L,
|
||||||
processTree.getVirtualMemorySize(1));
|
processTree.getVirtualMemorySize(1));
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"vmem (old API) shouldn't have included new processes", 1200000L,
|
||||||
|
processTree.getCumulativeVmem(1));
|
||||||
if (!smapEnabled) {
|
if (!smapEnabled) {
|
||||||
long cumuRssMem =
|
long cumuRssMem =
|
||||||
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
ProcfsBasedProcessTree.PAGE_SIZE > 0
|
||||||
? 1200L * ProcfsBasedProcessTree.PAGE_SIZE : 0L;
|
? 1200L * ProcfsBasedProcessTree.PAGE_SIZE :
|
||||||
|
ResourceCalculatorProcessTree.UNAVAILABLE;
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new processes",
|
"rssmem shouldn't have included new processes",
|
||||||
cumuRssMem, processTree.getRssMemorySize(1));
|
cumuRssMem, processTree.getRssMemorySize(1));
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new processes",
|
||||||
|
cumuRssMem, processTree.getCumulativeRssmem(1));
|
||||||
} else {
|
} else {
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"rssmem shouldn't have included new processes",
|
"rssmem shouldn't have included new processes",
|
||||||
100 * KB_TO_BYTES * 4, processTree.getRssMemorySize(1));
|
100 * KB_TO_BYTES * 4, processTree.getRssMemorySize(1));
|
||||||
|
Assert.assertEquals(
|
||||||
|
"rssmem (old API) shouldn't have included new processes",
|
||||||
|
100 * KB_TO_BYTES * 4, processTree.getCumulativeRssmem(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// no processes older than 3 iterations
|
// no processes older than 3 iterations
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Getting non-zero vmem for processes older than 3 iterations",
|
"Getting non-zero vmem for processes older than 3 iterations",
|
||||||
UNAVAILABLE, processTree.getVirtualMemorySize(3));
|
0, processTree.getVirtualMemorySize(3));
|
||||||
|
// verify old API
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Getting non-zero vmem (old API) for processes older than 3 iterations",
|
||||||
|
0, processTree.getCumulativeVmem(3));
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Getting non-zero rssmem for processes older than 3 iterations",
|
"Getting non-zero rssmem for processes older than 3 iterations",
|
||||||
UNAVAILABLE, processTree.getRssMemorySize(3));
|
0, processTree.getRssMemorySize(3));
|
||||||
|
// verify old API
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Getting non-zero rssmem for processes older than 3 iterations",
|
"Getting non-zero rssmem (old API) for processes older than 3 iterations",
|
||||||
UNAVAILABLE, processTree.getRssMemorySize(3));
|
0, processTree.getCumulativeRssmem(3));
|
||||||
} finally {
|
} finally {
|
||||||
FileUtil.fullyDelete(procfsRootDir);
|
FileUtil.fullyDelete(procfsRootDir);
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,20 @@ public long getRssMemorySize(int age) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeRssmem(int age) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public long getVirtualMemorySize(int age) {
|
public long getVirtualMemorySize(int age) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public long getCumulativeVmem(int age) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public long getCumulativeCpuTime() {
|
public long getCumulativeCpuTime() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ String getAllProcessInfoFromShell() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test (timeout = 30000)
|
@Test (timeout = 30000)
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void tree() {
|
public void tree() {
|
||||||
if( !Shell.WINDOWS) {
|
if( !Shell.WINDOWS) {
|
||||||
LOG.info("Platform not Windows. Not testing");
|
LOG.info("Platform not Windows. Not testing");
|
||||||
@ -49,30 +50,42 @@ public void tree() {
|
|||||||
assertTrue("WindowsBasedProcessTree should be available on Windows",
|
assertTrue("WindowsBasedProcessTree should be available on Windows",
|
||||||
WindowsBasedProcessTree.isAvailable());
|
WindowsBasedProcessTree.isAvailable());
|
||||||
|
|
||||||
|
|
||||||
WindowsBasedProcessTreeTester pTree = new WindowsBasedProcessTreeTester("-1");
|
WindowsBasedProcessTreeTester pTree = new WindowsBasedProcessTreeTester("-1");
|
||||||
pTree.infoStr = "3524,1024,1024,500\r\n2844,1024,1024,500\r\n";
|
pTree.infoStr = "3524,1024,1024,500\r\n2844,1024,1024,500\r\n";
|
||||||
pTree.updateProcessTree();
|
pTree.updateProcessTree();
|
||||||
assertTrue(pTree.getVirtualMemorySize() == 2048);
|
assertTrue(pTree.getVirtualMemorySize() == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeVmem() == 2048);
|
||||||
assertTrue(pTree.getVirtualMemorySize(0) == 2048);
|
assertTrue(pTree.getVirtualMemorySize(0) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeVmem(0) == 2048);
|
||||||
|
|
||||||
assertTrue(pTree.getRssMemorySize() == 2048);
|
assertTrue(pTree.getRssMemorySize() == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem() == 2048);
|
||||||
assertTrue(pTree.getRssMemorySize(0) == 2048);
|
assertTrue(pTree.getRssMemorySize(0) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem(0) == 2048);
|
||||||
assertTrue(pTree.getCumulativeCpuTime() == 1000);
|
assertTrue(pTree.getCumulativeCpuTime() == 1000);
|
||||||
|
|
||||||
pTree.infoStr = "3524,1024,1024,1000\r\n2844,1024,1024,1000\r\n1234,1024,1024,1000\r\n";
|
pTree.infoStr = "3524,1024,1024,1000\r\n2844,1024,1024,1000\r\n1234,1024,1024,1000\r\n";
|
||||||
pTree.updateProcessTree();
|
pTree.updateProcessTree();
|
||||||
assertTrue(pTree.getVirtualMemorySize() == 3072);
|
assertTrue(pTree.getVirtualMemorySize() == 3072);
|
||||||
|
assertTrue(pTree.getCumulativeVmem() == 3072);
|
||||||
assertTrue(pTree.getVirtualMemorySize(1) == 2048);
|
assertTrue(pTree.getVirtualMemorySize(1) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeVmem(1) == 2048);
|
||||||
assertTrue(pTree.getRssMemorySize() == 3072);
|
assertTrue(pTree.getRssMemorySize() == 3072);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem() == 3072);
|
||||||
assertTrue(pTree.getRssMemorySize(1) == 2048);
|
assertTrue(pTree.getRssMemorySize(1) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem(1) == 2048);
|
||||||
assertTrue(pTree.getCumulativeCpuTime() == 3000);
|
assertTrue(pTree.getCumulativeCpuTime() == 3000);
|
||||||
|
|
||||||
pTree.infoStr = "3524,1024,1024,1500\r\n2844,1024,1024,1500\r\n";
|
pTree.infoStr = "3524,1024,1024,1500\r\n2844,1024,1024,1500\r\n";
|
||||||
pTree.updateProcessTree();
|
pTree.updateProcessTree();
|
||||||
assertTrue(pTree.getVirtualMemorySize() == 2048);
|
assertTrue(pTree.getVirtualMemorySize() == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeVmem() == 2048);
|
||||||
assertTrue(pTree.getVirtualMemorySize(2) == 2048);
|
assertTrue(pTree.getVirtualMemorySize(2) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeVmem(2) == 2048);
|
||||||
assertTrue(pTree.getRssMemorySize() == 2048);
|
assertTrue(pTree.getRssMemorySize() == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem() == 2048);
|
||||||
assertTrue(pTree.getRssMemorySize(2) == 2048);
|
assertTrue(pTree.getRssMemorySize(2) == 2048);
|
||||||
|
assertTrue(pTree.getCumulativeRssmem(2) == 2048);
|
||||||
assertTrue(pTree.getCumulativeCpuTime() == 4000);
|
assertTrue(pTree.getCumulativeCpuTime() == 4000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user