< prev index next >

test/jdk/jdk/internal/platform/docker/MetricsCpuTester.java

Print this page
@  rev 56863 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~


 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();
 160 
 161         while (System.currentTimeMillis() - current < 2000) ;  // 2 sec
 162 
 163         long newthrottledTime = metrics.getCpuThrottledTime();
 164         long newnumThrottled = metrics.getCpuNumThrottled();
 165         if (newthrottledTime <= throttledTime) {


 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         if ("cgroupv2".equals(metrics.getProvider()) && shares < 1024) {
 147             // Adjust input shares for < 1024 cpu shares as the
 148             // impl. rounds up to the next multiple of 1024
 149             shares = 1024;
 150         }
 151         long newShares = metrics.getCpuShares();
 152         if (newShares != shares) {
 153             throw new RuntimeException("CPU shares not equal, expected : ["
 154                     + shares + "]" + ", got : " + "[" + newShares + "]");
 155         }
 156         System.out.println("TEST PASSED!!!");
 157     }
 158 
 159     private static void testCpuThrottling() {
 160         Metrics metrics = Metrics.systemMetrics();
 161         long throttledTime = metrics.getCpuThrottledTime();
 162         long numThrottled = metrics.getCpuNumThrottled();
 163 
 164         long current = System.currentTimeMillis();
 165 
 166         while (System.currentTimeMillis() - current < 2000) ;  // 2 sec
 167 
 168         long newthrottledTime = metrics.getCpuThrottledTime();
 169         long newnumThrottled = metrics.getCpuNumThrottled();
 170         if (newthrottledTime <= throttledTime) {
< prev index next >