Package org.openjdk.jmh.util
Class Utils
- java.lang.Object
-
- org.openjdk.jmh.util.Utils
-
public class Utils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Iterable<T>
adaptForLoop(Iterator<T> it)
Adapts Iterator for Iterable.static void
check(Class<?> klass, String fieldName)
static void
check(Class<?> klass, String... fieldNames)
static String[]
concat(String[] t1, String[] t2)
static int
figureOutHotCPUs()
Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity.static String
getCurrentJvm()
static String
getCurrentJvmVersion()
static String
getCurrentOSVersion()
static long
getOffset(Class<?> klass, String fieldName)
static long
getPid()
Gets PID of the current JVM.static long
getPid(Process process)
Gets the PID of the target process.static Properties
getRecordedSystemProperties()
We don't access the complete system properties viaSystem.getProperties()
because this would require read/write permissions to the properties.static Charset
guessConsoleEncoding()
static boolean
isWindows()
static String
join(String[] src, String delim)
static String
join(Collection<String> src, String delim)
static String
marshalIntArray(int[] arr)
static <T extends Comparable<T>>
Tmax(Collection<T> ts)
static <T extends Comparable<T>>
Tmin(Collection<T> ts)
static Properties
readPropertiesFromCommand(List<String> cmd)
static void
reflow(PrintWriter pw, String src, int width, int indent)
static Collection<String>
rewrap(String lines)
static int
roundUp(int v, int quant)
static Process
runAsync(String... cmd)
static Collection<String>
runWith(List<String> cmd)
static Collection<String>
splitQuotedEscape(String src)
static int
sum(int[] arr)
static String
throwableToString(Throwable t)
static Collection<String>
tryWith(String... cmd)
static int[]
unmarshalIntArray(String src)
-
-
-
Method Detail
-
min
public static <T extends Comparable<T>> T min(Collection<T> ts)
-
max
public static <T extends Comparable<T>> T max(Collection<T> ts)
-
join
public static String join(Collection<String> src, String delim)
-
splitQuotedEscape
public static Collection<String> splitQuotedEscape(String src)
-
sum
public static int sum(int[] arr)
-
roundUp
public static int roundUp(int v, int quant)
-
unmarshalIntArray
public static int[] unmarshalIntArray(String src)
-
marshalIntArray
public static String marshalIntArray(int[] arr)
-
figureOutHotCPUs
public static int figureOutHotCPUs()
Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity. Some systems, notably embedded Linuxes, power down the idle CPUs and so availableProcessors() may report lower CPU count than would be present after the load-up.- Returns:
- max CPU count
-
guessConsoleEncoding
public static Charset guessConsoleEncoding()
-
reflow
public static void reflow(PrintWriter pw, String src, int width, int indent)
-
rewrap
public static Collection<String> rewrap(String lines)
-
isWindows
public static boolean isWindows()
-
getCurrentJvm
public static String getCurrentJvm()
-
getCurrentJvmVersion
public static String getCurrentJvmVersion()
-
getCurrentOSVersion
public static String getCurrentOSVersion()
-
getPid
public static long getPid()
Gets PID of the current JVM.- Returns:
- PID.
-
getPid
public static long getPid(Process process)
Gets the PID of the target process.- Parameters:
process
- to poll- Returns:
- PID, or zero if no PID is found
-
tryWith
public static Collection<String> tryWith(String... cmd)
-
runWith
public static Collection<String> runWith(List<String> cmd)
-
getRecordedSystemProperties
public static Properties getRecordedSystemProperties()
We don't access the complete system properties viaSystem.getProperties()
because this would require read/write permissions to the properties. Just copy the properties we want to record in the result.- Returns:
- Copy of system properties we want to record in the results.
-
readPropertiesFromCommand
public static Properties readPropertiesFromCommand(List<String> cmd)
-
-