test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File open Cdiff test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java

test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 18,44 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! import java.io.BufferedReader; ! import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; - import java.io.FileReader; import java.util.ArrayList; - import java.util.Optional; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.test.lib.Asserts; // A simple CPU sets reader and parser public class CPUSetsReader { ! public static String PROC_SELF_STATUS_PATH="/proc/self/status"; // Test the parser public static void test() { assertParse("0-7", "0,1,2,3,4,5,6,7"); assertParse("1,3,6", "1,3,6"); --- 18,45 ---- * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! ! package jdk.test.lib.containers.cgroup; ! import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; + import java.util.Optional; import java.util.stream.Collectors; + import java.util.stream.IntStream; import java.util.stream.Stream; import jdk.test.lib.Asserts; // A simple CPU sets reader and parser public class CPUSetsReader { ! public static String PROC_SELF_STATUS_PATH = "/proc/self/status"; // Test the parser public static void test() { assertParse("0-7", "0,1,2,3,4,5,6,7"); assertParse("1,3,6", "1,3,6");
*** 49,58 **** --- 50,69 ---- private static void assertParse(String cpuSet, String expectedResult) { Asserts.assertEquals(listToString(parseCpuSet(cpuSet)), expectedResult); } + public static int getNumCpus() { + String path = "/proc/cpuinfo"; + try { + Stream<String> stream = Files.lines(Paths.get(path)); + return (int) stream.filter(line -> line.startsWith("processor")).count(); + } catch (IOException e) { + return 0; + } + } + public static String readFromProcStatus(String setType) { String path = PROC_SELF_STATUS_PATH; Optional<String> o = Optional.empty();
*** 68,78 **** if (!o.isPresent()) { return null; // entry not found } ! String[] parts = o.get().replaceAll("\\s","").split(":"); // Should be 2 parts, before and after ":" Asserts.assertEquals(parts.length, 2); String result = parts[1]; --- 79,89 ---- if (!o.isPresent()) { return null; // entry not found } ! String[] parts = o.get().replaceAll("\\s", "").split(":"); // Should be 2 parts, before and after ":" Asserts.assertEquals(parts.length, 2); String result = parts[1];
*** 100,113 **** } return result; } - private static void addRange(ArrayList<Integer> list, String s) { String[] range = s.split("-"); ! if ( range.length != 2 ) { throw new RuntimeException("Range should only contain two items, but contains " + range.length + " items"); } int min = Integer.parseInt(range[0]); --- 111,123 ---- } return result; } private static void addRange(ArrayList<Integer> list, String s) { String[] range = s.split("-"); ! if (range.length != 2) { throw new RuntimeException("Range should only contain two items, but contains " + range.length + " items"); } int min = Integer.parseInt(range[0]);
*** 136,141 **** --- 146,155 ---- return list.stream() .limit(maxCount) .map(Object::toString) .collect(Collectors.joining(",")); } + + public static String numberToString(int num) { + return IntStream.range(0, num).boxed().map(Object::toString).collect(Collectors.joining(",")); + } }
test/lib/jdk/test/lib/containers/cgroup/CPUSetsReader.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File