This class provides Static system information that may be useful for algorithms that want to adjust their behavior based on the system's hardware information. All information supposes that hardware is consistent, ie: all memory installed is of the same type and all CPUs installed are the same model
| 18 | * @author Edward Raff |
| 19 | */ |
| 20 | public class SystemInfo |
| 21 | { |
| 22 | public final static int LogicalCores = Runtime.getRuntime().availableProcessors(); |
| 23 | public final static String OS_String = System.getProperty("os.name"); |
| 24 | |
| 25 | /** |
| 26 | * |
| 27 | * @return true if this machine is running some version of Windows |
| 28 | */ |
| 29 | public static boolean isWindows() |
| 30 | { |
| 31 | return OS_String.contains("Win"); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * |
| 36 | * @return true is this machine is running some version of Mac OS X |
| 37 | */ |
| 38 | public static boolean isMac() |
| 39 | { |
| 40 | return OS_String.contains("Mac"); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @return true if this machine is running some version of Linux |
| 46 | */ |
| 47 | public static boolean isLinux() |
| 48 | { |
| 49 | return OS_String.contains("Lin"); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Contains the per core L2 Cache size. The value returned will be '0' if there was an error obtaining the size |
| 54 | */ |
| 55 | public final static int L2CacheSize; |
| 56 | static |
| 57 | { |
| 58 | int sizeToUse = 0; |
| 59 | try |
| 60 | { |
| 61 | if(isWindows()) |
| 62 | { |
| 63 | String output = null; |
| 64 | try |
| 65 | { |
| 66 | //On windows, the comand line tool WMIC is used, see http://msdn.microsoft.com/en-us/library/aa394531(v=vs.85).aspx |
| 67 | |
| 68 | Process pr = Runtime.getRuntime().exec("wmic cpu get L2CacheSize, NumberOfCores"); |
| 69 | /* |
| 70 | * Will print out the total L2 Cache for each CPU, and the number of cores - something like this (2 CPUs) |
| 71 | * L2CacheSize NumberOfCores |
| 72 | * 1024 4 |
| 73 | * 1024 4 |
| 74 | */ |
| 75 | |
| 76 | BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream())); |
| 77 | StringBuilder sb = new StringBuilder(); |