use of org.spongepowered.api.block.entity.BlockEntityType in project SpongeCommon by SpongePowered.
the class TimingsExport method reportTimings.
/**
* Builds an XML report of the timings to be uploaded for parsing.
*/
static void reportTimings() {
if (TimingsExport.requestingReport.isEmpty()) {
return;
}
TimingsReportListener listeners = new TimingsReportListener(TimingsExport.requestingReport);
TimingsExport.requestingReport.clear();
long now = System.currentTimeMillis();
final long lastReportDiff = now - TimingsExport.lastReport;
if (lastReportDiff < 60000) {
listeners.send(Component.text("Please wait at least 1 minute in between Timings reports. (" + (int) ((60000 - lastReportDiff) / 1000) + " seconds)", NamedTextColor.RED));
listeners.done();
return;
}
final long lastStartDiff = now - TimingsManager.timingStart;
if (lastStartDiff < 180000) {
listeners.send(Component.text("Please wait at least 3 minutes before generating a Timings report. Unlike Timings v1, v2 benefits from longer timings and is not as useful with short timings. (" + (int) ((180000 - lastStartDiff) / 1000) + " seconds)", NamedTextColor.RED));
listeners.done();
return;
}
listeners.send(Component.text("Preparing Timings Report...", NamedTextColor.GREEN));
TimingsExport.lastReport = now;
Platform platform = SpongeCommon.game().platform();
JsonObjectBuilder builder = JSONUtil.objectBuilder().add("version", platform.container(IMPLEMENTATION).metadata().version()).add("maxplayers", SpongeCommon.game().server().maxPlayers()).add("start", TimingsManager.timingStart / 1000).add("end", System.currentTimeMillis() / 1000).add("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
if (!TimingsManager.privacy) {
builder.add("server", TimingsExport.getServerName()).add("motd", PlainTextComponentSerializer.plainText().serialize(Sponge.server().motd())).add("online-mode", Sponge.server().isOnlineModeEnabled()).add("icon", SpongeCommon.server().getStatus().getFavicon());
}
final Runtime runtime = Runtime.getRuntime();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
builder.add("system", JSONUtil.objectBuilder().add("timingcost", TimingsExport.getCost()).add("name", System.getProperty("os.name")).add("version", System.getProperty("os.version")).add("jvmversion", System.getProperty("java.version")).add("arch", System.getProperty("os.arch")).add("maxmem", runtime.maxMemory()).add("cpu", runtime.availableProcessors()).add("runtime", ManagementFactory.getRuntimeMXBean().getUptime()).add("flags", TimingsExport.RUNTIME_FLAG_JOINER.join(runtimeBean.getInputArguments())).add("gc", JSONUtil.mapArrayToObject(ManagementFactory.getGarbageCollectorMXBeans(), (input) -> {
return JSONUtil.singleObjectPair(input.getName(), JSONUtil.arrayOf(input.getCollectionCount(), input.getCollectionTime()));
})));
Set<BlockEntityType> blockEntityTypeSet = Sets.newHashSet();
Set<EntityType<?>> entityTypeSet = Sets.newHashSet();
int size = TimingsManager.HISTORY.size();
TimingHistory[] history = new TimingHistory[size + 1];
int i = 0;
for (TimingHistory timingHistory : TimingsManager.HISTORY) {
blockEntityTypeSet.addAll(timingHistory.tileEntityTypeSet);
entityTypeSet.addAll(timingHistory.entityTypeSet);
history[i++] = timingHistory;
}
// Current snapshot
history[i] = new TimingHistory();
blockEntityTypeSet.addAll(history[i].tileEntityTypeSet);
entityTypeSet.addAll(history[i].entityTypeSet);
JsonObjectBuilder handlersBuilder = JSONUtil.objectBuilder();
for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
for (TimingHandler id : group.handlers) {
if (!id.timed && !id.isSpecial()) {
continue;
}
handlersBuilder.add(id.id, JSONUtil.arrayOf(group.id, id.name));
}
}
builder.add("idmap", JSONUtil.objectBuilder().add("groups", JSONUtil.mapArrayToObject(TimingIdentifier.GROUP_MAP.values(), (group) -> JSONUtil.singleObjectPair(group.id, group.name))).add("handlers", handlersBuilder).add("worlds", JSONUtil.mapArrayToObject(TimingHistory.worldMap.entrySet(), (entry) -> JSONUtil.singleObjectPair(entry.getValue(), entry.getKey()))).add("blockentity", JSONUtil.mapArrayToObject(blockEntityTypeSet, (blockEntityType) -> {
final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.BLOCK_ENTITY_TYPE).valueKey(blockEntityType);
return JSONUtil.singleObjectPair(TimingsPls.getBlockEntityId(blockEntityType), resourceKey);
})).add("entity", JSONUtil.mapArrayToObject(entityTypeSet, (entityType) -> {
final ResourceKey resourceKey = (ResourceKey) (Object) Registry.ENTITY_TYPE.getKey((net.minecraft.world.entity.EntityType<?>) entityType);
return JSONUtil.singleObjectPair(TimingsPls.getEntityId(entityType), resourceKey);
})));
// Information about loaded plugins
builder.add("plugins", JSONUtil.mapArrayToObject(SpongeCommon.game().pluginManager().plugins(), (plugin) -> {
@Nullable final URL homepageUrl = plugin.metadata().links().homepage().orElse(null);
final String homepage = homepageUrl != null ? homepageUrl.toString() : "<not specified>";
return JSONUtil.objectBuilder().add(plugin.metadata().id(), JSONUtil.objectBuilder().add("version", plugin.metadata().version()).add("description", plugin.metadata().description().orElse("")).add("website", homepage).add("authors", TimingsExport.AUTHOR_LIST_JOINER.join(plugin.metadata().contributors()))).build();
}));
// Information on the users Config
builder.add("config", JSONUtil.objectBuilder().add("sponge", TimingsExport.serializeConfigNode(SpongeConfigs.getCommon().getNode())));
new TimingsExport(listeners, builder.build(), history).start();
}
Aggregations