78 String[] tokens = cpuset.split("-"); 79 if (tokens.length > 1) { // we are given range of CPUs 80 ipCpuSet = IntStream.rangeClosed(Integer.parseInt(tokens[0]), 81 Integer.parseInt(tokens[1])).toArray(); 82 } else if (cpuset.split(",").length > 1) { // list of cpus 83 ipCpuSet = Stream.of(cpuset.split(",")).mapToInt(Integer::parseInt).toArray(); 84 } else { // just a single cpu 85 ipCpuSet = new int[]{Integer.parseInt(cpuset)}; 86 } 87 88 Metrics metrics = Metrics.systemMetrics(); 89 int[] cpuSets = metrics.getCpuSetCpus(); 90 91 int[] effectiveCpus = metrics.getEffectiveCpuSetCpus(); 92 93 if (!Arrays.equals(ipCpuSet, cpuSets)) { 94 throw new RuntimeException("Cpusets not equal, expected : " 95 + Arrays.toString(ipCpuSet) + ", got : " + Arrays.toString(cpuSets)); 96 } 97 98 if (!Arrays.equals(ipCpuSet, effectiveCpus)) { 99 throw new RuntimeException("Effective Cpusets not equal, expected : " 100 + Arrays.toString(ipCpuSet) + ", got : " 101 + Arrays.toString(effectiveCpus)); 102 } 103 System.out.println("TEST PASSED!!!"); 104 } 105 106 private static void testCpuSetMemNodes(String cpusetMems) { 107 Metrics metrics = Metrics.systemMetrics(); 108 int[] cpuSets = metrics.getCpuSetMems(); 109 110 int[] ipCpuSet; 111 String[] tokens = cpusetMems.split("-"); 112 if (tokens.length > 1) { // we are given range of CPUs 113 ipCpuSet = IntStream.rangeClosed(Integer.parseInt(tokens[0]), 114 Integer.parseInt(tokens[1])).toArray(); 115 } else if (cpusetMems.split(",").length > 1) { // list of cpus 116 ipCpuSet = Stream.of(cpusetMems.split(",")).mapToInt(Integer::parseInt).toArray(); 117 } else { // just a single cpu 118 ipCpuSet = new int[]{Integer.parseInt(cpusetMems)}; 119 } 120 121 int[] effectiveMems = metrics.getEffectiveCpuSetMems(); 122 123 124 if (!Arrays.equals(ipCpuSet, cpuSets)) { 125 throw new RuntimeException("Cpuset.mems not equal, expected : " 126 + Arrays.toString(ipCpuSet) + ", got : " 127 + Arrays.toString(cpuSets)); 128 } 129 130 if (!Arrays.equals(ipCpuSet, effectiveMems)) { 131 throw new RuntimeException("Effective mem nodes not equal, expected : " 132 + Arrays.toString(ipCpuSet) + ", got : " 133 + Arrays.toString(effectiveMems)); 134 } 135 System.out.println("TEST PASSED!!!"); 136 } 137 138 private static void testCpuShares(long shares) { 139 Metrics metrics = Metrics.systemMetrics(); 140 long newShares = metrics.getCpuShares(); 141 if (newShares != shares) { 142 throw new RuntimeException("CPU shares not equal, expected : [" 143 + shares + "]" + ", got : " + "[" + newShares + "]"); 144 } 145 System.out.println("TEST PASSED!!!"); 146 } 147 148 private static void testCpuThrottling() { 149 Metrics metrics = Metrics.systemMetrics(); 150 long throttledTime = metrics.getCpuThrottledTime(); 151 long numThrottled = metrics.getCpuNumThrottled(); 152 153 long current = System.currentTimeMillis(); | 78 String[] tokens = cpuset.split("-"); 79 if (tokens.length > 1) { // we are given range of CPUs 80 ipCpuSet = IntStream.rangeClosed(Integer.parseInt(tokens[0]), 81 Integer.parseInt(tokens[1])).toArray(); 82 } else if (cpuset.split(",").length > 1) { // list of cpus 83 ipCpuSet = Stream.of(cpuset.split(",")).mapToInt(Integer::parseInt).toArray(); 84 } else { // just a single cpu 85 ipCpuSet = new int[]{Integer.parseInt(cpuset)}; 86 } 87 88 Metrics metrics = Metrics.systemMetrics(); 89 int[] cpuSets = metrics.getCpuSetCpus(); 90 91 int[] effectiveCpus = metrics.getEffectiveCpuSetCpus(); 92 93 if (!Arrays.equals(ipCpuSet, cpuSets)) { 94 throw new RuntimeException("Cpusets not equal, expected : " 95 + Arrays.toString(ipCpuSet) + ", got : " + Arrays.toString(cpuSets)); 96 } 97 98 // Check to see if this metric is supported on this platform 99 if (effectiveCpus.length != 0) { 100 if (!Arrays.equals(ipCpuSet, effectiveCpus)) { 101 throw new RuntimeException("Effective Cpusets not equal, expected : " 102 + Arrays.toString(ipCpuSet) + ", got : " 103 + Arrays.toString(effectiveCpus)); 104 } 105 } 106 System.out.println("TEST PASSED!!!"); 107 } 108 109 private static void testCpuSetMemNodes(String cpusetMems) { 110 Metrics metrics = Metrics.systemMetrics(); 111 int[] cpuSets = metrics.getCpuSetMems(); 112 113 int[] ipCpuSet; 114 String[] tokens = cpusetMems.split("-"); 115 if (tokens.length > 1) { // we are given range of CPUs 116 ipCpuSet = IntStream.rangeClosed(Integer.parseInt(tokens[0]), 117 Integer.parseInt(tokens[1])).toArray(); 118 } else if (cpusetMems.split(",").length > 1) { // list of cpus 119 ipCpuSet = Stream.of(cpusetMems.split(",")).mapToInt(Integer::parseInt).toArray(); 120 } else { // just a single cpu 121 ipCpuSet = new int[]{Integer.parseInt(cpusetMems)}; 122 } 123 124 int[] effectiveMems = metrics.getEffectiveCpuSetMems(); 125 126 127 if (!Arrays.equals(ipCpuSet, cpuSets)) { 128 throw new RuntimeException("Cpuset.mems not equal, expected : " 129 + Arrays.toString(ipCpuSet) + ", got : " 130 + Arrays.toString(cpuSets)); 131 } 132 133 // Check to see if this metric is supported on this platform 134 if (effectiveMems.length != 0) { 135 if (!Arrays.equals(ipCpuSet, effectiveMems)) { 136 throw new RuntimeException("Effective mem nodes not equal, expected : " 137 + Arrays.toString(ipCpuSet) + ", got : " 138 + Arrays.toString(effectiveMems)); 139 } 140 } 141 System.out.println("TEST PASSED!!!"); 142 } 143 144 private static void testCpuShares(long shares) { 145 Metrics metrics = Metrics.systemMetrics(); 146 long newShares = metrics.getCpuShares(); 147 if (newShares != shares) { 148 throw new RuntimeException("CPU shares not equal, expected : [" 149 + shares + "]" + ", got : " + "[" + newShares + "]"); 150 } 151 System.out.println("TEST PASSED!!!"); 152 } 153 154 private static void testCpuThrottling() { 155 Metrics metrics = Metrics.systemMetrics(); 156 long throttledTime = metrics.getCpuThrottledTime(); 157 long numThrottled = metrics.getCpuNumThrottled(); 158 159 long current = System.currentTimeMillis(); |