added scarpet to the carpet profiler

This commit is contained in:
gnembon committed 2021-04-04 22:32:34 -03:00
1 parent 51a548991d
commit f0d044a49f
6 files changed
+37 -11

No files matched your search

@@ -13,6 +13,7 @@ import carpet.script.exception.CarpetExpressionException;
import carpet.script.value.FunctionValue; import carpet.script.value.FunctionValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.settings.SettingsManager; import carpet.settings.SettingsManager;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
@@ -396,6 +397,7 @@ public class ScriptCommand
{ {
try try
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet ace", CarpetProfiler.TYPE.GENERAL);
host.setChatErrorSnooper(source); host.setChatErrorSnooper(source);
long start = System.nanoTime(); long start = System.nanoTime();
Value result = call.get(); Value result = call.get();
@@ -412,7 +414,9 @@ public class ScriptCommand
metric = "s"; metric = "s";
} }
Messenger.m(source, "wi = ", "wb "+result.getString(), "gi ("+time+metric+")"); Messenger.m(source, "wi = ", "wb "+result.getString(), "gi ("+time+metric+")");
return (int)result.readInteger(); int intres = (int)result.readInteger();
CarpetProfiler.end_current_section(currentSection);
return intres;
} }
catch (CarpetExpressionException e) catch (CarpetExpressionException e)
{ {
@@ -14,6 +14,7 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import carpet.settings.ParsedRule; import carpet.settings.ParsedRule;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@@ -204,6 +205,7 @@ public class CarpetEventServer
{ {
if (callList.size() > 0) if (callList.size() > 0)
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet events", CarpetProfiler.TYPE.GENERAL);
List<Value> argv = argumentSupplier.get(); // empty for onTickDone List<Value> argv = argumentSupplier.get(); // empty for onTickDone
ServerCommandSource source; ServerCommandSource source;
try try
@@ -225,6 +227,7 @@ public class CarpetEventServer
if (!call.execute(source, argv)) fails.add(call); if (!call.execute(source, argv)) fails.add(call);
} }
for (Callback call : fails) callList.remove(call); for (Callback call : fails) callList.remove(call);
CarpetProfiler.end_current_section(currentSection);
} }
} }
@@ -18,6 +18,7 @@ import carpet.script.value.MapValue;
import carpet.script.value.NumericValue; import carpet.script.value.NumericValue;
import carpet.script.value.StringValue; import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@@ -127,6 +128,7 @@ public class CarpetScriptHost extends ScriptHost
private static int execute(CommandContext<ServerCommandSource> ctx, String hostName, FunctionArgument<Value> funcSpec, List<String> paramNames) throws CommandSyntaxException private static int execute(CommandContext<ServerCommandSource> ctx, String hostName, FunctionArgument<Value> funcSpec, List<String> paramNames) throws CommandSyntaxException
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet command", CarpetProfiler.TYPE.GENERAL);
CarpetScriptHost cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(ctx.getSource()); CarpetScriptHost cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(ctx.getSource());
List<String> argNames = funcSpec.function.getArguments(); List<String> argNames = funcSpec.function.getArguments();
if ((argNames.size()-funcSpec.args.size()) != paramNames.size()) if ((argNames.size()-funcSpec.args.size()) != paramNames.size())
@@ -140,7 +142,9 @@ public class CarpetScriptHost extends ScriptHost
Value response = cHost.handleCommand(ctx.getSource(), funcSpec.function, args); Value response = cHost.handleCommand(ctx.getSource(), funcSpec.function, args);
// will skip prints for new // will skip prints for new
//if (!response.isNull()) Messenger.m(ctx.getSource(), "gi " + response.getString()); //if (!response.isNull()) Messenger.m(ctx.getSource(), "gi " + response.getString());
return (int) response.readInteger(); int intres = (int) response.readInteger();
CarpetProfiler.end_current_section(currentSection);
return intres;
} }
public LiteralArgumentBuilder<ServerCommandSource> addPathToCommand( public LiteralArgumentBuilder<ServerCommandSource> addPathToCommand(
@@ -210,12 +214,15 @@ public class CarpetScriptHost extends ScriptHost
return s -> { return s -> {
try try
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet command", CarpetProfiler.TYPE.GENERAL);
CarpetScriptHost cHost = null; CarpetScriptHost cHost = null;
cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(s); cHost = CarpetServer.scriptServer.modules.get(hostName).retrieveOwnForExecution(s);
Value response = cHost.handleCommand(s, fun, Collections.singletonList( Value response = cHost.handleCommand(s, fun, Collections.singletonList(
(s.getEntity() instanceof ServerPlayerEntity)?new EntityValue(s.getEntity()):Value.NULL) (s.getEntity() instanceof ServerPlayerEntity)?new EntityValue(s.getEntity()):Value.NULL)
); );
return response.getBoolean(); boolean res = response.getBoolean();
CarpetProfiler.end_current_section(currentSection);
return res;
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
@@ -546,7 +553,10 @@ public class CarpetScriptHost extends ScriptHost
{ {
try try
{ {
return callLegacy(source, call, coords, arg); CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet legacy", CarpetProfiler.TYPE.GENERAL);
Value res = callLegacy(source, call, coords, arg);
CarpetProfiler.end_current_section(currentSection);
return res;
} }
catch (CarpetExpressionException exc) catch (CarpetExpressionException exc)
{ {
@@ -1,19 +1,15 @@
package carpet.script; package carpet.script;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.script.argument.FunctionArgument;
import carpet.script.bundled.BundledModule; import carpet.script.bundled.BundledModule;
import carpet.CarpetServer; import carpet.CarpetServer;
import carpet.script.bundled.FileModule; import carpet.script.bundled.FileModule;
import carpet.script.bundled.Module; import carpet.script.bundled.Module;
import carpet.script.command.CommandToken;
import carpet.script.exception.InvalidCallbackException; import carpet.script.exception.InvalidCallbackException;
import carpet.script.value.FunctionValue; import carpet.script.value.FunctionValue;
import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger; import carpet.utils.Messenger;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
@@ -229,6 +225,7 @@ public class CarpetScriptServer
public boolean addScriptHost(ServerCommandSource source, String name, Function<ServerCommandSource, Boolean> commandValidator, public boolean addScriptHost(ServerCommandSource source, String name, Function<ServerCommandSource, Boolean> commandValidator,
boolean perPlayer, boolean autoload, boolean isRuleApp) boolean perPlayer, boolean autoload, boolean isRuleApp)
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet loading", CarpetProfiler.TYPE.GENERAL);
if (commandValidator == null) commandValidator = p -> true; if (commandValidator == null) commandValidator = p -> true;
long start = System.nanoTime(); long start = System.nanoTime();
name = name.toLowerCase(Locale.ROOT); name = name.toLowerCase(Locale.ROOT);
@@ -301,6 +298,7 @@ public class CarpetScriptServer
FunctionValue onStart = newHost.getFunction("__on_start"); FunctionValue onStart = newHost.getFunction("__on_start");
if (onStart != null) newHost.callNow(onStart, Collections.emptyList()); if (onStart != null) newHost.callNow(onStart, Collections.emptyList());
} }
CarpetProfiler.end_current_section(currentSection);
long end = System.nanoTime(); long end = System.nanoTime();
CarpetSettings.LOG.info("App "+name+" loaded in "+(end-start)/1000000+" ms"); CarpetSettings.LOG.info("App "+name+" loaded in "+(end-start)/1000000+" ms");
return true; return true;
@@ -412,11 +410,16 @@ public class CarpetScriptServer
public void tick() public void tick()
{ {
CarpetProfiler.ProfilerToken token;
token = CarpetProfiler.start_section(null, "Scarpet schedule", CarpetProfiler.TYPE.GENERAL);
events.tick(); events.tick();
CarpetProfiler.end_current_section(token);
token = CarpetProfiler.start_section(null, "Scarpet app data", CarpetProfiler.TYPE.GENERAL);
for (CarpetScriptHost host : modules.values()) for (CarpetScriptHost host : modules.values())
{ {
host.tick(); host.tick();
} }
CarpetProfiler.end_current_section(token);
} }
public void onClose() public void onClose()
@@ -14,6 +14,7 @@ import carpet.script.value.NumericValue;
import carpet.script.value.StringValue; import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import carpet.utils.CarpetProfiler;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.ArgumentType;
@@ -365,6 +366,7 @@ public abstract class CommandArgument
{ {
if (customSuggester != null) if (customSuggester != null)
{ {
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet command", CarpetProfiler.TYPE.GENERAL);
Map<Value, Value> params = new HashMap<>(); Map<Value, Value> params = new HashMap<>();
for(ParsedCommandNode<ServerCommandSource> pnode : context.getNodes()) for(ParsedCommandNode<ServerCommandSource> pnode : context.getNodes())
{ {
@@ -379,7 +381,9 @@ public abstract class CommandArgument
args.addAll(customSuggester.args); args.addAll(customSuggester.args);
Value response = host.handleCommand(context.getSource(), customSuggester.function, args); Value response = host.handleCommand(context.getSource(), customSuggester.function, args);
if (!(response instanceof ListValue)) throw error("Custom suggester should return a list of options"+" for custom type "+suffix); if (!(response instanceof ListValue)) throw error("Custom suggester should return a list of options"+" for custom type "+suffix);
return ((ListValue) response).getItems().stream().map(Value::getString).collect(Collectors.toList()); Collection<String> res = ((ListValue) response).getItems().stream().map(Value::getString).collect(Collectors.toList());
CarpetProfiler.end_current_section(currentSection);
return res;
} }
if (needsMatching) return examples; if (needsMatching) return examples;
//return Lists.newArrayList(""); //return Lists.newArrayList("");
@@ -31,7 +31,9 @@ public class CarpetProfiler
private static int tick_health_elapsed = 0; private static int tick_health_elapsed = 0;
private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities; private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities;
private static long current_tick_start = 0; private static long current_tick_start = 0;
private static final String[] GENERAL_SECTIONS = {"Network", "Autosave", "Async Tasks", "Datapacks",}; private static final String[] GENERAL_SECTIONS = {"Network", "Autosave", "Async Tasks", "Datapacks",
"Scarpet ace", "Scarpet legacy", "Scarpet events", "Scarpet schedule",
"Scarpet command", "Scarpet loading", "Scarpet app data"};
private static final String[] SECTIONS = { private static final String[] SECTIONS = {
"Spawning and Random Ticks", "Ticket Manager","Unloading", "Spawning and Random Ticks", "Ticket Manager","Unloading",
"Blocks", "Entities", "Block Entities", "Blocks", "Entities", "Block Entities",