Add README.md, some docs

This commit is contained in:
Andras Slemmer 2017-10-11 10:06:27 +01:00
parent 16b26970a9
commit c56c9fd455
2 changed files with 36 additions and 4 deletions

View File

@ -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<StatsEvent> map.
*
* Later we "parse" these lists into a tree.
*/
object KryoHook : ClassFileTransformer { object KryoHook : ClassFileTransformer {
val classPool = ClassPool.getDefault() val classPool = ClassPool.getDefault()
@ -88,17 +94,14 @@ object KryoHook : ClassFileTransformer {
return null return null
} }
// StrandID -> StatsEvent map
val events = ConcurrentHashMap<Long, ArrayList<StatsEvent>>() val events = ConcurrentHashMap<Long, ArrayList<StatsEvent>>()
val eventCount = AtomicInteger(0)
@JvmStatic @JvmStatic
fun writeEnter(kryo: Kryo, output: Output, obj: Any) { fun writeEnter(kryo: Kryo, output: Output, obj: Any) {
events.getOrPut(Strand.currentStrand().id) { ArrayList() }.add( events.getOrPut(Strand.currentStrand().id) { ArrayList() }.add(
StatsEvent.Enter(obj.javaClass.name, output.total()) StatsEvent.Enter(obj.javaClass.name, output.total())
) )
if (eventCount.incrementAndGet() % 100 == 0) {
println("EVENT COUNT ${eventCount}")
}
} }
@JvmStatic @JvmStatic
fun writeExit(kryo: Kryo, output: Output, obj: Any) { 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 { sealed class StatsEvent {
data class Enter(val className: String, val offset: Long) : StatsEvent() data class Enter(val className: String, val offset: Long) : StatsEvent()
data class Exit(val className: String, val offset: Long) : StatsEvent() data class Exit(val className: String, val offset: Long) : StatsEvent()
} }
/**
* TODO add Field constructor.
*/
sealed class StatsTree { sealed class StatsTree {
data class Object( data class Object(
val className: String, val className: String,

View File

@ -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:<PROJECT>/experimental/kryo-hook/build/libs/kryo-hook.jar
```
The agent will dump the output when the JVM shuts down.