Allow consuming trace events programmatically#400
Merged
Conversation
Tracing only ever printed a formatted call tree to *out*, which made it hard to build anything on top of (an editor trace buffer, say). Add a listener registry: add-trace-listener registers a fn that receives a structured event per call and per return (paired by :id, carrying :name, :depth, :args/:value), and set-output-mode! chooses whether output goes to the REPL, to listeners, or both. The REPL path is unchanged and stays the default. Args are bounded the same way the printed path is, so tracing a fn called with a lazy or infinite arglist (e.g. (apply f (range))) can't OOM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step of giving CIDER a dedicated trace buffer (clojure-emacs/cider, Tier 2 of the enlighten/tracing audit).
Tracing only ever printed a formatted call tree to
*out*, which is hard to build a UI on. This adds a listener registry so trace events can be consumed programmatically:add-trace-listener/remove-trace-listener- register a fn that gets a structured event per call and per return. Events are paired by:idand carry:name,:depth, and:args(on:call) or:value(on:return).set-output-mode!- choose whether output goes to the REPL (:repl, the default), to listeners (:listeners), or:both.The REPL path is unchanged and remains the default, so existing tracing behaves exactly as before. Event args are bounded the same way the printed path already bounds them, so tracing a fn called with a lazy/infinite arglist (e.g.
(apply f (range))) can't blow up the heap.cider-nrepl will register a listener and stream these events to a
*cider-trace*buffer once this is released.