File tree Expand file tree Collapse file tree 6 files changed +38
-9
lines changed Expand file tree Collapse file tree 6 files changed +38
-9
lines changed Original file line number Diff line number Diff line change 1
1
# omni-trace
2
2
Omnipotent/omniscient tracing core for debugging clojure(script)
3
3
4
- very early alpha, api is still unstable
4
+ very early alpha, api is still unstable but its only for dev time so there shouldn't be any problems
5
5
6
6
7
7
[ ![ Clojars Project] ( https://img.shields.io/clojars/v/org.clojars.cyrik/omni-trace.svg )] ( https://clojars.org/org.clojars.cyrik/omni-trace )
@@ -34,7 +34,8 @@ or just through github source:
34
34
(e/insert-coin :dime )
35
35
(e/insert-coin :nickel )
36
36
(e/insert-coin :penny )
37
- (e/press-button :a1 ))
37
+ (e/press-button :a1 )
38
+ (e/retrieve-change-returned ))
38
39
; look at traces for every function that was traced
39
40
@o/workspace
40
41
; connect to portal
@@ -48,6 +49,13 @@ or just through github source:
48
49
49
50
![ Screenshot] ( docs/flamegraph.png )
50
51
52
+ ## Features
53
+ - Works in clojure and clojurescript
54
+ - Instrument whole namespaces from the repl
55
+ - show the trace as a Flamegraph in Portal or anything else that understands Vega.js
56
+ - remembers the call that caused the exception and shows the arguments
57
+
58
+
51
59
## In the works
52
60
- better trace output to the REPL
53
61
- callbacks from Portal so you can rerun an updated function with the old params by clicking on it in the Flamegraph
Original file line number Diff line number Diff line change 31
31
32
32
o/instrumented-vars
33
33
34
+ (tap> ^{:portal.viewer/default :portal.viewer/hiccup }
35
+ [:div " custom thing here" [:portal.viewer/inspector {:complex :data-structure }]])
36
+
34
37
(o/uninstrument-ns 'omni-trace.testing-ns)
35
38
(macroexpand '(o/instrument-ns 'omni-trace.testing-ns))
36
39
Original file line number Diff line number Diff line change 14
14
(e/insert-coin :dime )
15
15
(e/insert-coin :nickel )
16
16
(e/insert-coin :penny )
17
- (e/press-button :a1 ))
17
+ (e/press-button :a1 )
18
+ (e/retrieve-change-returned ))
18
19
; look at traces for every function that was traced
19
20
@o/workspace
20
21
; connect to portal
21
22
(def portal (p/open ))
22
23
(add-tap #'p/submit)
23
24
; send the trace to portal as a vegajs flamegraph
24
25
(tap> (flame/flamegraph (flame/flamedata @o/workspace)))
26
+ (tap> ^{:portal.viewer/default :portal.viewer/hiccup } [:button {:onclick (str " alert('123')" )} (str " alert('123')" )])
27
+ [:button {:onclick " alert('123')" } " Test it!" ]
25
28
; remove tracing from a namesapce
26
29
(o/uninstrument-ns 'omni-trace.testing-ns)
27
-
30
+ ( o/reset-workspace! )
28
31
o/instrumented-vars
29
32
(macroexpand '(o/uninstrument-ns 'omni-trace.testing-ns))
30
33
(alter-meta! (var omni-trace.testing-ns/insert-coin) assoc-in [:stuffs ] " yeah123" )
Original file line number Diff line number Diff line change 23
23
{:signal
24
24
" {n: datum.name,
25
25
a:datum.args,
26
+ t:datum.thrown,
26
27
r: datum.return}" }}
27
28
:update
28
29
{:x {:field " a0" }
47
48
:parentKey " parent" }
48
49
{:type " partition"
49
50
; :field "size"
50
- :sort {:field " value " }
51
+ :sort {:field " id " }
51
52
:padding 2
52
53
:size
53
54
[{:signal " width" }
Original file line number Diff line number Diff line change 14
14
#? (:clj (System/currentTimeMillis )
15
15
:cljs (.now js/Date)))
16
16
17
+ (defn reset-workspace! []
18
+ (reset! workspace {}))
19
+
20
+ (defn log [workspace id trace]
21
+ (swap! workspace assoc id trace))
22
+
17
23
(defn trace-fn-call [name f args opts]
18
24
(let [parent (or *trace-log-parent*
19
25
{:workspace (::workspace opts) :parent :root })
20
- call-id (keyword (gensym ))
26
+ call-id (keyword (gensym " " ))
21
27
before-time (now )
22
28
this (assoc parent :parent call-id)
23
29
res (binding [*trace-log-parent* this]
24
- (apply f args))]
25
- (swap! (:workspace parent)
26
- #(assoc % call-id {:id call-id :name name :args args :start before-time :end (now ) :parent (:parent parent) :return res}))
30
+ (try
31
+ (apply f args)
32
+ (catch #?(:clj Throwable :cljs :default ) t
33
+ (log (:workspace parent)
34
+ call-id
35
+ {:id call-id :name name :args args :start before-time :end (now ) :parent (:parent parent) :thrown (#?(:clj Throwable->map :cljs identity) t)})
36
+ (throw t))))]
37
+ (log (:workspace parent)
38
+ call-id
39
+ {:id call-id :name name :args args :start before-time :end (now ) :parent (:parent parent) :return res})
27
40
res))
28
41
29
42
(defn instrumented [sym v opts]
Original file line number Diff line number Diff line change 107
107
(defn retrieve-change-returned
108
108
[machine]
109
109
[(:change-returned machine)
110
+ (throw #?(:cljs (js/Error. " Oops" ) :clj (Exception. " Oops" )))
110
111
(dissoc machine :change-returned )])
You can’t perform that action at this time.
0 commit comments