Skip to content

Commit a55bcc2

Browse files
author
Lukas Domagala
committed
fixed flamegraph sorting and added exception tracing
1 parent a3c41a6 commit a55bcc2

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# omni-trace
22
Omnipotent/omniscient tracing core for debugging clojure(script)
33

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
55

66

77
[![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:
3434
(e/insert-coin :dime)
3535
(e/insert-coin :nickel)
3636
(e/insert-coin :penny)
37-
(e/press-button :a1))
37+
(e/press-button :a1)
38+
(e/retrieve-change-returned))
3839
;look at traces for every function that was traced
3940
@o/workspace
4041
;connect to portal
@@ -48,6 +49,13 @@ or just through github source:
4849

4950
![Screenshot](docs/flamegraph.png)
5051

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+
5159
## In the works
5260
- better trace output to the REPL
5361
- callbacks from Portal so you can rerun an updated function with the old params by clicking on it in the Flamegraph

dev/user.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131

3232
o/instrumented-vars
3333

34+
(tap> ^{:portal.viewer/default :portal.viewer/hiccup}
35+
[:div "custom thing here" [:portal.viewer/inspector {:complex :data-structure}]])
36+
3437
(o/uninstrument-ns 'omni-trace.testing-ns)
3538
(macroexpand '(o/instrument-ns 'omni-trace.testing-ns))
3639

dev/user.cljs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414
(e/insert-coin :dime)
1515
(e/insert-coin :nickel)
1616
(e/insert-coin :penny)
17-
(e/press-button :a1))
17+
(e/press-button :a1)
18+
(e/retrieve-change-returned))
1819
;look at traces for every function that was traced
1920
@o/workspace
2021
;connect to portal
2122
(def portal (p/open))
2223
(add-tap #'p/submit)
2324
;send the trace to portal as a vegajs flamegraph
2425
(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!"]
2528
;remove tracing from a namesapce
2629
(o/uninstrument-ns 'omni-trace.testing-ns)
27-
30+
(o/reset-workspace!)
2831
o/instrumented-vars
2932
(macroexpand '(o/uninstrument-ns 'omni-trace.testing-ns))
3033
(alter-meta! (var omni-trace.testing-ns/insert-coin) assoc-in [:stuffs] "yeah123")

src/omni_trace/flamegraph.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
{:signal
2424
"{n: datum.name,
2525
a:datum.args,
26+
t:datum.thrown,
2627
r: datum.return}"}}
2728
:update
2829
{:x {:field "a0"}
@@ -47,7 +48,7 @@
4748
:parentKey "parent"}
4849
{:type "partition"
4950
;:field "size"
50-
:sort {:field "value"}
51+
:sort {:field "id"}
5152
:padding 2
5253
:size
5354
[{:signal "width"}

src/omni_trace/omni_trace.cljc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,29 @@
1414
#?(:clj (System/currentTimeMillis)
1515
:cljs (.now js/Date)))
1616

17+
(defn reset-workspace! []
18+
(reset! workspace {}))
19+
20+
(defn log [workspace id trace]
21+
(swap! workspace assoc id trace))
22+
1723
(defn trace-fn-call [name f args opts]
1824
(let [parent (or *trace-log-parent*
1925
{:workspace (::workspace opts) :parent :root})
20-
call-id (keyword (gensym))
26+
call-id (keyword (gensym ""))
2127
before-time (now)
2228
this (assoc parent :parent call-id)
2329
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})
2740
res))
2841

2942
(defn instrumented [sym v opts]

src/omni_trace/testing_ns.cljc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,5 @@
107107
(defn retrieve-change-returned
108108
[machine]
109109
[(:change-returned machine)
110+
(throw #?(:cljs (js/Error. "Oops") :clj (Exception. "Oops")))
110111
(dissoc machine :change-returned)])

0 commit comments

Comments
 (0)