Paper icon indicating copy to clipboard operation
Paper copied to clipboard

New event verbose command

Open TheRealRyGuy opened this issue 2 years ago • 7 comments

Saw a message from Machine Maker on Discord bringing this up, figured it'd be a fun random thing to do

Essentially just adds a /paper dumpevents command. Running this once will begin logging events, and running it again will save the events in order with timestamp and event class fields in JSON to a file in the debug directory. Attached below is an example output

Two issues that aren't too big of a deal with this

Does not handle inheritance of event classes well, Field#getDeclaredFields only retrieves minimal fields, could use a superclass check working all the way up to org.bukkit.Event Could further serialize non primitive event fields just for a bit more info, stringified versions of them are typically fine though

event-verbose-2023-03-21_18.03.40.txt

TheRealRyGuy avatar Mar 21 '23 22:03 TheRealRyGuy

Part of what I had described was logging to be able to see event class fields before and after each listener for an event. That way if an an event had 50 listeners, you could try and find what listener changed what.

EDIT: Another thing, is I feel some events should be excluded by default. Like the tick events, ones that are just spammed a ton. Can have something that does include those, but most of the time they are just gonna clog up the system. We can also exclude events who don't have "changeable" values.

Machine-Maker avatar Mar 21 '23 22:03 Machine-Maker

Most QoL way to do that would be with an EventExecutor and listen for a specific event - not sure if there's a way to register one internally though. My thought process was that this was just for all of the "what event runs when xyz" questions pop up.

Will exclude tick start and end events, not sure what you mean by "changeable" values though.

TheRealRyGuy avatar Mar 21 '23 22:03 TheRealRyGuy

In the SimplePluginManager#fireEvent and PaperEventManager#callEvent, can't you just get the values of the event before and after each call to the listeners?

"changeable" is hard to define. Generally I think events that have all final fields with no mutable things exposed don't need to be included. These events are just events used to inform that something happened, and a listener can't actually change anything about the event. The VehicleUpdateEvent is one of those. You can't change anythinga bout the event, so it doesn't need to be logged. Although I'm not sure there's a good way of knowing this automatically.

Machine-Maker avatar Mar 21 '23 22:03 Machine-Maker

Now ignores all final fields and can take specific exclusions, right now just tick starting and ending

Worth keeping this as its own system? Can just make a new command for watching specific events, can also just nuke this feature entirely for what you were more thinking of

TheRealRyGuy avatar Mar 21 '23 23:03 TheRealRyGuy

I would exclude final collections (Collection, Map) and ItemStack from the final check. It's possible to have a final one of those that can be mutated via a getter.

I suppose both are useful. Seeing what events fire between two points, and a deeper look at what changes for each listener for those events. Might be best for the system I imagined to specify a single event to do that for.

Machine-Maker avatar Mar 21 '23 23:03 Machine-Maker

Added in the general premise for what you were looking for through /paper watchevent [event], attached an example output that's just one listener modifying async chat's format.

Also moved the event verbose to paper's event manager to ignore bad event calls. The final check of that also now excludes org.bukkit.inventory.ItemStack as well as collections and maps, however, if we're just looking for the general flow of things, don't we want to just include every event?

event-AsyncPlayerChatEvent-2023-03-21_20.43.03.txt

TheRealRyGuy avatar Mar 22 '23 00:03 TheRealRyGuy

All should be done unless I missed anything dumpevents now saves to the event-debug folder, whereas watchevent will log into event-debug/[event name]/ dir

TheRealRyGuy avatar Mar 25 '23 02:03 TheRealRyGuy