clj-fast icon indicating copy to clipboard operation
clj-fast copied to clipboard

Add instrumentation facilities

Open bsless opened this issue 3 years ago • 8 comments

Add tools required for trace-timing functions and causal profiling

bsless avatar Apr 29 '21 14:04 bsless

cc @joinr I think this will interest you. Do you think this should be a separate project?

bsless avatar Apr 29 '21 14:04 bsless

Is this an attempt to provide more fine-grained information than criterium, or to enable direct profiling from the repl instead of hooking up visualvm or something external?

joinr avatar Apr 29 '21 18:04 joinr

The idea is to provide two things I found I was missing:

  • a tracing timing profiler: let's say I call some -main and it runs for 700ms. If I could instrument all the functions in the project I could see where most time was being wasted quite easily. Visual VM requires hooking up to a running process, not really suitable for a "one-shot" run. I got this idea when trying to analyze leiningen's start-up time.
  • a causal profiler: a more Clojure oriented approach to something like JCoz

bsless avatar Apr 29 '21 19:04 bsless

I was thinking about point 2 after I replied. Yeah, having the ability to introspect and profile locally would be very nice. I think you could replicate jcoz at the sexpr level (or get fancier and go into bytecode, maybe with clojure decompiler, to insert virtual slowdowns). w.r.t. original question, seems like more of a profiling lib than a library for drop-in performance improvement. I would probably fork off a new profiling/instrumentation project since there's no obvious coupling with the stuff in here.

joinr avatar Apr 29 '21 19:04 joinr

Probably doesn't matter if you dev on it this repo for the time being and choose to move it later though.

joinr avatar Apr 29 '21 19:04 joinr

Regarding instrumenting specific sexprs, without a reader macro to pinpoint interesting locations, it would be hard. Slowing down functions inside vars is easy and gets you 90% of the way there, especially if your functions are small

bsless avatar Apr 29 '21 19:04 bsless

without a reader macro to pinpoint interesting locations

You can use metadata, sort of like cider's debugger does with #break and #dbg. I think they just use tagged literals.

joinr avatar Apr 29 '21 19:04 joinr

https://docs.cider.mx/cider/debugging/debugger.html#conditional-breakpoints

joinr avatar Apr 29 '21 19:04 joinr