diff --git a/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt index 8d57dc8dbc..e9c6f61e34 100644 --- a/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt +++ b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt @@ -47,6 +47,12 @@ fun prettyStatsTree(indent: Int, statsTree: StatsTree, builder: StringBuilder) { } } +/** + * The hook simply records the write() entries and exits together with the output offset at the time of the call. + * This is recorded in a StrandID -> List map. + * + * Later we "parse" these lists into a tree. + */ object KryoHook : ClassFileTransformer { val classPool = ClassPool.getDefault() @@ -88,17 +94,14 @@ object KryoHook : ClassFileTransformer { return null } + // StrandID -> StatsEvent map val events = ConcurrentHashMap>() - val eventCount = AtomicInteger(0) @JvmStatic fun writeEnter(kryo: Kryo, output: Output, obj: Any) { events.getOrPut(Strand.currentStrand().id) { ArrayList() }.add( StatsEvent.Enter(obj.javaClass.name, output.total()) ) - if (eventCount.incrementAndGet() % 100 == 0) { - println("EVENT COUNT ${eventCount}") - } } @JvmStatic fun writeExit(kryo: Kryo, output: Output, obj: Any) { @@ -108,11 +111,17 @@ object KryoHook : ClassFileTransformer { } } +/** + * TODO we could add events on entries/exits to field serializers to get more info on what's being serialised. + */ sealed class StatsEvent { data class Enter(val className: String, val offset: Long) : StatsEvent() data class Exit(val className: String, val offset: Long) : StatsEvent() } +/** + * TODO add Field constructor. + */ sealed class StatsTree { data class Object( val className: String, diff --git a/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/README.md b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/README.md new file mode 100644 index 0000000000..ec7899a290 --- /dev/null +++ b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/README.md @@ -0,0 +1,23 @@ +What is this +------------ + +This is a javaagent that hooks into Kryo serializers to record a breakdown of how many bytes objects take in the output. + +The dump is quite ugly now, but the in-memory representation is a simple tree so we could put some nice visualisation on +top if we want. + +How do I run it +--------------- + +Build the agent: +``` +./gradlew experimental:kryo-hook:jar +``` + +Add this JVM flag to what you're running: + +``` +-javaagent:/experimental/kryo-hook/build/libs/kryo-hook.jar +``` + +The agent will dump the output when the JVM shuts down.