Permalink
Browse files

Integrated spy/d and spy/t to handle the mutex on pprint and enable q…

…uerying after basic tracing
  • Loading branch information...
1 parent 8f0d4d5 commit 0de1e6889e9d60c42e1f4196c6098fc40019c74e @dgrnbrg committed Oct 30, 2012
Showing with 22 additions and 12 deletions.
  1. +6 −0 README.md
  2. +16 −12 src/spyscope/core.clj
View
@@ -72,6 +72,12 @@ This is controlled by setting the metadata key `:form` to `true`:
spyscope.repl$eval685.invoke(REPL:16) (- 16 10) => 6
{:a 6, :b 6}
+Under the hood, `#spy/d` actually does all of its printing on another thread
+--the tracing store thread! This provides 2 benefits: if you are printing
+from multiple threads, your output will not be interleaved amongst threads. The
+other benefit is that every trace statement is logged, so that you can use
+the `#spy/t` api to refine your search after you start tracing with `#spy/d`.
+
### `#spy/t`
Finally, let's look at `#spy/t`. Tracing is very similar to detailed
View
@@ -61,11 +61,12 @@
(defn print-log-detailed
"Reader function to pprint a form's value with some extra information."
[form]
- (let [{:keys [fs nses]} (meta form)]
- `(let [f# ~form]
- (println (:message (pretty-render-value f# ~(assoc (meta form)
- ::form (list 'quote form)))))
- f#)))
+ (letfn [(print [m] (assoc m ::print? true))]
+ (->> form
+ meta
+ print
+ (with-meta form)
+ trace)))
(defn print-log
"Reader function to pprint a form's value."
@@ -81,13 +82,16 @@
`(let [f# ~form]
(send trace-storage
(fn [{g# :generation t# :trace :as storage#}]
- (assoc storage#
- :trace
- (conj t# (assoc (pretty-render-value
- f#
- ~(assoc (meta form)
- ::form (list 'quote form)))
- :generation g#)))))
+ (let [value# (pretty-render-value
+ f#
+ ~(assoc (meta form)
+ ::form (list 'quote form)))]
+ (when ~(::print? (meta form))
+ (println (:message value#)))
+ (assoc storage#
+ :trace
+ (conj t# (assoc value#
+ :generation g#))))))
f#))
(comment

0 comments on commit 0de1e68

Please sign in to comment.