SystemReport.java
net.minecraft.SystemReport
信息
- 全限定名:net.minecraft.SystemReport
- 类型:public class
- 包:net.minecraft
- 源码路径:src/main/java/net/minecraft/SystemReport.java
- 起始行号:L28
- 职责:
TODO
字段/常量
-
BYTES_PER_MEBIBYTE- 类型:
long - 修饰符:
public static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
ONE_GIGA- 类型:
long - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L31 - 说明:
TODO
- 类型:
-
OPERATING_SYSTEM- 类型:
String - 修饰符:
private static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
JAVA_VERSION- 类型:
String - 修饰符:
private static final - 源码定位:
L37 - 说明:
TODO
- 类型:
-
JAVA_VM_VERSION- 类型:
String - 修饰符:
private static final - 源码定位:
L38 - 说明:
TODO
- 类型:
-
entries- 类型:
Map<String,String> - 修饰符:
private final - 源码定位:
L43 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public SystemReport() @ L45
- 构造器名:SystemReport
- 源码定位:L45
- 修饰符:public
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
private static String printMemoryUsage(MemoryUsage memoryUsage) @ L69
- 方法名:printMemoryUsage
- 源码定位:L69
- 返回类型:String
- 修饰符:private static
参数:
- memoryUsage: MemoryUsage
说明:
TODO
private static String printJvmFlags(Predicate<String> selector) @ L80
- 方法名:printJvmFlags
- 源码定位:L80
- 返回类型:String
- 修饰符:private static
参数:
- selector: Predicate
说明:
TODO
public void setDetail(String key, String value) @ L86
- 方法名:setDetail
- 源码定位:L86
- 返回类型:void
- 修饰符:public
参数:
- key: String
- value: String
说明:
TODO
public void setDetail(String key, Supplier<String> valueSupplier) @ L90
- 方法名:setDetail
- 源码定位:L90
- 返回类型:void
- 修饰符:public
参数:
- key: String
- valueSupplier: Supplier
说明:
TODO
private void putHardware(SystemInfo systemInfo) @ L99
- 方法名:putHardware
- 源码定位:L99
- 返回类型:void
- 修饰符:private
参数:
- systemInfo: SystemInfo
说明:
TODO
private void ignoreErrors(String group, Runnable action) @ L107
- 方法名:ignoreErrors
- 源码定位:L107
- 返回类型:void
- 修饰符:private
参数:
- group: String
- action: Runnable
说明:
TODO
public static float sizeInMiB(long bytes) @ L115
- 方法名:sizeInMiB
- 源码定位:L115
- 返回类型:float
- 修饰符:public static
参数:
- bytes: long
说明:
TODO
private void putPhysicalMemory(List<PhysicalMemory> memoryPackages) @ L119
- 方法名:putPhysicalMemory
- 源码定位:L119
- 返回类型:void
- 修饰符:private
参数:
- memoryPackages: List
说明:
TODO
private void putVirtualMemory(VirtualMemory virtualMemory) @ L130
- 方法名:putVirtualMemory
- 源码定位:L130
- 返回类型:void
- 修饰符:private
参数:
- virtualMemory: VirtualMemory
说明:
TODO
private void putMemory(GlobalMemory memory) @ L137
- 方法名:putMemory
- 源码定位:L137
- 返回类型:void
- 修饰符:private
参数:
- memory: GlobalMemory
说明:
TODO
private void putGraphics(List<GraphicsCard> graphicsCards) @ L142
- 方法名:putGraphics
- 源码定位:L142
- 返回类型:void
- 修饰符:private
参数:
- graphicsCards: List
说明:
TODO
private void putProcessor(CentralProcessor processor) @ L155
- 方法名:putProcessor
- 源码定位:L155
- 返回类型:void
- 修饰符:private
参数:
- processor: CentralProcessor
说明:
TODO
private void putStorage() @ L167
- 方法名:putStorage
- 源码定位:L167
- 返回类型:void
- 修饰符:private
参数:
- 无
说明:
TODO
private void putSpaceForProperty(String env) @ L175
- 方法名:putSpaceForProperty
- 源码定位:L175
- 返回类型:void
- 修饰符:private
参数:
- env: String
说明:
TODO
private void putSpaceForPath(String id, Supplier<String> pathSupplier) @ L179
- 方法名:putSpaceForPath
- 源码定位:L179
- 返回类型:void
- 修饰符:private
参数:
- id: String
- pathSupplier: Supplier
说明:
TODO
public void appendToCrashReportString(StringBuilder sb) @ L200
- 方法名:appendToCrashReportString
- 源码定位:L200
- 返回类型:void
- 修饰符:public
参数:
- sb: StringBuilder
说明:
TODO
public String toLineSeparatedString() @ L211
- 方法名:toLineSeparatedString
- 源码定位:L211
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class SystemReport {
public static final long BYTES_PER_MEBIBYTE = 1048576L;
private static final long ONE_GIGA = 1000000000L;
private static final Logger LOGGER = LogUtils.getLogger();
private static final String OPERATING_SYSTEM = System.getProperty("os.name")
+ " ("
+ System.getProperty("os.arch")
+ ") version "
+ System.getProperty("os.version");
private static final String JAVA_VERSION = System.getProperty("java.version") + ", " + System.getProperty("java.vendor");
private static final String JAVA_VM_VERSION = System.getProperty("java.vm.name")
+ " ("
+ System.getProperty("java.vm.info")
+ "), "
+ System.getProperty("java.vm.vendor");
private final Map<String, String> entries = Maps.newLinkedHashMap();
public SystemReport() {
this.setDetail("Minecraft Version", SharedConstants.getCurrentVersion().name());
this.setDetail("Minecraft Version ID", SharedConstants.getCurrentVersion().id());
this.setDetail("Operating System", OPERATING_SYSTEM);
this.setDetail("Java Version", JAVA_VERSION);
this.setDetail("Java VM Version", JAVA_VM_VERSION);
this.setDetail("Memory", () -> {
Runtime runtime = Runtime.getRuntime();
long max = runtime.maxMemory();
long total = runtime.totalMemory();
long free = runtime.freeMemory();
long maxMb = max / 1048576L;
long totalMb = total / 1048576L;
long freeMb = free / 1048576L;
return free + " bytes (" + freeMb + " MiB) / " + total + " bytes (" + totalMb + " MiB) up to " + max + " bytes (" + maxMb + " MiB)";
});
this.setDetail("Memory (heap)", () -> printMemoryUsage(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()));
this.setDetail("Memory (non-head)", () -> printMemoryUsage(ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()));
this.setDetail("CPUs", () -> String.valueOf(Runtime.getRuntime().availableProcessors()));
this.ignoreErrors("hardware", () -> this.putHardware(new SystemInfo()));
this.setDetail("JVM Flags", () -> printJvmFlags(arg -> arg.startsWith("-X")));
this.setDetail("Debug Flags", () -> printJvmFlags(arg -> arg.startsWith("-DMC_DEBUG_")));
}
private static String printMemoryUsage(MemoryUsage memoryUsage) {
return String.format(
Locale.ROOT,
"init: %03dMiB, used: %03dMiB, committed: %03dMiB, max: %03dMiB",
memoryUsage.getInit() / 1048576L,
memoryUsage.getUsed() / 1048576L,
memoryUsage.getCommitted() / 1048576L,
memoryUsage.getMax() / 1048576L
);
}
private static String printJvmFlags(Predicate<String> selector) {
List<String> allArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
List<String> selectedArguments = allArguments.stream().filter(selector).toList();
return String.format(Locale.ROOT, "%d total; %s", selectedArguments.size(), String.join(" ", selectedArguments));
}
public void setDetail(String key, String value) {
this.entries.put(key, value);
}
public void setDetail(String key, Supplier<String> valueSupplier) {
try {
this.setDetail(key, valueSupplier.get());
} catch (Exception var4) {
LOGGER.warn("Failed to get system info for {}", key, var4);
this.setDetail(key, "ERR");
}
}
private void putHardware(SystemInfo systemInfo) {
HardwareAbstractionLayer hardware = systemInfo.getHardware();
this.ignoreErrors("processor", () -> this.putProcessor(hardware.getProcessor()));
this.ignoreErrors("graphics", () -> this.putGraphics(hardware.getGraphicsCards()));
this.ignoreErrors("memory", () -> this.putMemory(hardware.getMemory()));
this.ignoreErrors("storage", this::putStorage);
}
private void ignoreErrors(String group, Runnable action) {
try {
action.run();
} catch (Throwable var4) {
LOGGER.warn("Failed retrieving info for group {}", group, var4);
}
}
public static float sizeInMiB(long bytes) {
return (float)bytes / 1048576.0F;
}
private void putPhysicalMemory(List<PhysicalMemory> memoryPackages) {
int memorySlot = 0;
for (PhysicalMemory physicalMemory : memoryPackages) {
String prefix = String.format(Locale.ROOT, "Memory slot #%d ", memorySlot++);
this.setDetail(prefix + "capacity (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(physicalMemory.getCapacity())));
this.setDetail(prefix + "clockSpeed (GHz)", () -> String.format(Locale.ROOT, "%.2f", (float)physicalMemory.getClockSpeed() / 1.0E9F));
this.setDetail(prefix + "type", physicalMemory::getMemoryType);
}
}
private void putVirtualMemory(VirtualMemory virtualMemory) {
this.setDetail("Virtual memory max (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(virtualMemory.getVirtualMax())));
this.setDetail("Virtual memory used (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(virtualMemory.getVirtualInUse())));
this.setDetail("Swap memory total (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(virtualMemory.getSwapTotal())));
this.setDetail("Swap memory used (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(virtualMemory.getSwapUsed())));
}
private void putMemory(GlobalMemory memory) {
this.ignoreErrors("physical memory", () -> this.putPhysicalMemory(memory.getPhysicalMemory()));
this.ignoreErrors("virtual memory", () -> this.putVirtualMemory(memory.getVirtualMemory()));
}
private void putGraphics(List<GraphicsCard> graphicsCards) {
int gpuIndex = 0;
for (GraphicsCard graphicsCard : graphicsCards) {
String prefix = String.format(Locale.ROOT, "Graphics card #%d ", gpuIndex++);
this.setDetail(prefix + "name", graphicsCard::getName);
this.setDetail(prefix + "vendor", graphicsCard::getVendor);
this.setDetail(prefix + "VRAM (MiB)", () -> String.format(Locale.ROOT, "%.2f", sizeInMiB(graphicsCard.getVRam())));
this.setDetail(prefix + "deviceId", graphicsCard::getDeviceId);
this.setDetail(prefix + "versionInfo", graphicsCard::getVersionInfo);
}
}
private void putProcessor(CentralProcessor processor) {
ProcessorIdentifier processorIdentifier = processor.getProcessorIdentifier();
this.setDetail("Processor Vendor", processorIdentifier::getVendor);
this.setDetail("Processor Name", processorIdentifier::getName);
this.setDetail("Identifier", processorIdentifier::getIdentifier);
this.setDetail("Microarchitecture", processorIdentifier::getMicroarchitecture);
this.setDetail("Frequency (GHz)", () -> String.format(Locale.ROOT, "%.2f", (float)processorIdentifier.getVendorFreq() / 1.0E9F));
this.setDetail("Number of physical packages", () -> String.valueOf(processor.getPhysicalPackageCount()));
this.setDetail("Number of physical CPUs", () -> String.valueOf(processor.getPhysicalProcessorCount()));
this.setDetail("Number of logical CPUs", () -> String.valueOf(processor.getLogicalProcessorCount()));
}
private void putStorage() {
this.putSpaceForProperty("jna.tmpdir");
this.putSpaceForProperty("org.lwjgl.system.SharedLibraryExtractPath");
this.putSpaceForProperty("io.netty.native.workdir");
this.putSpaceForProperty("java.io.tmpdir");
this.putSpaceForPath("workdir", () -> "");
}
private void putSpaceForProperty(String env) {
this.putSpaceForPath(env, () -> System.getProperty(env));
}
private void putSpaceForPath(String id, Supplier<@Nullable String> pathSupplier) {
String key = "Space in storage for " + id + " (MiB)";
try {
String path = pathSupplier.get();
if (path == null) {
this.setDetail(key, "<path not set>");
return;
}
FileStore store = Files.getFileStore(Path.of(path));
this.setDetail(key, String.format(Locale.ROOT, "available: %.2f, total: %.2f", sizeInMiB(store.getUsableSpace()), sizeInMiB(store.getTotalSpace())));
} catch (InvalidPathException var6) {
LOGGER.warn("{} is not a path", id, var6);
this.setDetail(key, "<invalid path>");
} catch (Exception var7) {
LOGGER.warn("Failed retrieving storage space for {}", id, var7);
this.setDetail(key, "ERR");
}
}
public void appendToCrashReportString(StringBuilder sb) {
sb.append("-- ").append("System Details").append(" --\n");
sb.append("Details:");
this.entries.forEach((key, value) -> {
sb.append("\n\t");
sb.append(key);
sb.append(": ");
sb.append(value);
});
}
public String toLineSeparatedString() {
return this.entries.entrySet().stream().map(e -> e.getKey() + ": " + e.getValue()).collect(Collectors.joining(System.lineSeparator()));
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
SharedConstants.getCurrentVersion()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
System.getProperty(), System.lineSeparator()
- 引用位置: