|
28 | 28 | import java.util.Map; |
29 | 29 | import java.util.Objects; |
30 | 30 | import java.util.Properties; |
| 31 | +import java.util.SortedMap; |
| 32 | +import java.util.TreeMap; |
| 33 | +import java.util.function.BiConsumer; |
31 | 34 | import java.util.function.Consumer; |
32 | 35 |
|
33 | 36 | /** |
@@ -58,14 +61,18 @@ static SoftwareInfo parse(String key) { |
58 | 61 |
|
59 | 62 | private enum RuntimeInfo { |
60 | 63 | // the ordering is the output ordering |
61 | | - JAVA, USER; |
| 64 | + JAVA, USER, MEMORY; |
62 | 65 |
|
63 | 66 | static final InfoMap<RuntimeInfo> MAP; |
64 | 67 |
|
65 | 68 | static { |
66 | 69 | final EnumMap<RuntimeInfo, String> map = new EnumMap<>(RuntimeInfo.class); |
67 | 70 | final Properties properties = System.getProperties(); |
68 | 71 | map.put(JAVA, properties.getProperty("java.vm.name") + " " + properties.getProperty("java.runtime.version")); |
| 72 | + final Runtime r = Runtime.getRuntime(); |
| 73 | + map.put(MEMORY, "max: " + TraditionalBinaryPrefix.long2String(r.maxMemory()) |
| 74 | + + ", total: " + TraditionalBinaryPrefix.long2String(r.totalMemory()) |
| 75 | + + ", free: " + TraditionalBinaryPrefix.long2String(r.freeMemory())); |
69 | 76 | map.put(USER, properties.getProperty("user.name")); |
70 | 77 | MAP = new InfoMap<>(map); |
71 | 78 | } |
@@ -143,7 +150,17 @@ public void printStartupMessages(Object name, Consumer<String> log) { |
143 | 150 | } |
144 | 151 | } |
145 | 152 |
|
| 153 | + static void printSystemProperties(BiConsumer<String, Object> out) { |
| 154 | + final SortedMap<String, Object> sortedMap = new TreeMap<>(); |
| 155 | + for(Map.Entry<Object, Object> e : System.getProperties().entrySet()) { |
| 156 | + sortedMap.put(e.getKey().toString(), e.getValue()); |
| 157 | + } |
| 158 | + sortedMap.forEach(out); |
| 159 | + } |
| 160 | + |
146 | 161 | public static void main(String[] args) { |
| 162 | + printSystemProperties((key, value) -> System.out.printf("%-40s = %s%n", key, value)); |
| 163 | + |
147 | 164 | VersionInfo.load(VersionInfo.class).printStartupMessages(":", System.out::println); |
148 | 165 | } |
149 | 166 | } |
0 commit comments