Skip to content

Commit

Permalink
changed namespace structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Domagala committed Nov 25, 2021
1 parent 0857271 commit 0d74874
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 31 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# omni-trace
Omnipotent/omniscient tracing core for debugging clojure(script)

very early alpha, api is still unstable but its only for dev time so there shouldn't be any problems
very early alpha, api is still unstable but its only for dev time so there shouldn't be any problems.
moved namespaces to cyrik.omni-trace and below. cyrik.omni-trace is the main entry point.


[![Clojars Project](https://img.shields.io/clojars/v/org.clojars.cyrik/omni-trace.svg)](https://clojars.org/org.clojars.cyrik/omni-trace)
Expand All @@ -17,11 +18,13 @@ or just through github source:

## Usage

[contrived example](https://github.com/bpiel/contrived-example) code for demo debugging pupose

```clojure
(ns user
(:require [omni-trace.omni-trace :as o]
[omni-trace.testing-ns :as e]
[omni-trace.flamegraph :as flame]
(:require [cyrik.omni-trace :as o]
[cyrik.omni-trace.testing-ns :as e]
[cyrik.omni-trace.flamegraph :as flame]
[portal.web :as p]))


Expand All @@ -35,7 +38,7 @@ or just through github source:
(e/insert-coin :nickel)
(e/insert-coin :penny)
(e/press-button :a1)
(e/retrieve-change-returned))
(e/retrieve-change-returned)) ;throws on purpose for demonstration
;look at traces for every function that was traced
@o/workspace
;connect to portal
Expand Down
14 changes: 7 additions & 7 deletions dev/user.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns user
(:require [omni-trace.omni-trace :as o]
[omni-trace.testing-ns :as e]
(:require [cyrik.omni-trace :as o]
[cyrik.omni-trace.testing-ns :as e]
[clojure.java.io :as io]
[portal.api :as po]
[criterium.core :as crit]
[clojure.walk :as walk]
[test-console :as tc]
[clojure.pprint :as pprint]
[omni-trace.flamegraph :as flame]))
[cyrik.omni-trace.graph :as flame]))

(defn spit-pretty!
"Writes the pretty-printed edn `data` into the `file`."
Expand All @@ -30,15 +30,15 @@

(o/instrument-fn 'test-inc)
(mapv test-inc (range 1000))
(o/instrument-ns 'omni-trace.testing-ns
{::o/workspace omni-trace.omni-trace/workspace})
(o/instrument-ns 'cyrik.omni-trace.testing-ns
{::o/workspace o/workspace})
(-> e/machine-init
(e/insert-coin :quarter)
(e/insert-coin :dime)
(e/insert-coin :nickel)
(e/insert-coin :penny)
(e/press-button :a1))
(tap> (flame/flamegraph (flame/flamedata @o/workspace)))
(tap> (o/flamegraph o/workspace))
(meta #'e/insert-coin)


Expand All @@ -62,7 +62,7 @@
(crit/with-progress-reporting (crit/quick-bench (into {} (map (juxt :id identity)) values) :verbose))
(crit/with-progress-reporting (crit/quick-bench (zipmap (map :id values) values) :verbose))


(count (:log @o/workspace))
(o/reset-workspace!)
(intern *ns* '~'symname "<<symdefinition>>")
Expand Down
21 changes: 11 additions & 10 deletions dev/user.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
(ns user
(:require [omni-trace.omni-trace :as o]
[omni-trace.testing-ns :as e]
(:require [cyrik.omni-trace :as o]
[cyrik.omni-trace.testing-ns :as e]
[cyrik.cljs-macroexpand :as macro]
[cyrik.omni-trace.testing-ns :as testin-ns]
[portal.console :as console]
[test-console :as tc]
[omni-trace.flamegraph :as flame]
[cyrik.omni-trace.graph :as flame]
[portal.web :as p]))

(defn test-inc [x]
Expand All @@ -24,11 +25,12 @@

(test-log 1)


(defonce portal (p/open))
(add-tap #'p/submit)

(comment
;instrument a namespace
(o/instrument-ns 'omni-trace.testing-ns)
(o/instrument-ns 'cyrik.omni-trace.testing-ns)
;or instrument a single function
(o/instrument-fn 'test-inc)
(test-inc 5)
Expand All @@ -43,8 +45,7 @@
;look at traces for every function that was traced
@o/workspace
;connect to portal
(def portal (p/open))
(add-tap #'p/submit)

(add-tap print)
;send the trace to portal as a vegajs flamegraph
(tap> (flame/flamegraph (flame/flamedata @o/workspace)))
Expand All @@ -54,14 +55,14 @@
(o/uninstrument-ns 'omni-trace.testing-ns)
(o/reset-workspace!)
o/instrumented-vars
(macroexpand '(o/instrument-ns 'omni-trace.testing-ns))
(macroexpand '(o/instrument-ns 'cyrik.omni-trace.testing-ns))
(macroexpand '(o/instrument-fn 'omni-trace.testing-ns/insert-coin))
(macro/cljs-macroexpand-all '(o/instrument-ns 'portal.web))
(macro/cljs-macroexpand-all '(o/instrument-fn 'omni-trace.testing-ns/insert-coin))
(test-log 5)
(macro/cljs-macroexpand-all '(tc/log 5))
(alter-meta! (var omni-trace.testing-ns/insert-coin) assoc-in [:stuffs] "yeah123")
(.log js/console (meta (var omni-trace.testing-ns/insert-coin)))
(alter-meta! (var cyrik.omni-trace.testing-ns/insert-coin) assoc-in [:stuffs] "yeah123")
(.log js/console (meta (var cyrik.omni-trace.testing-ns/insert-coin)))

(when-let [open js/OpenFileInEditor] (open "some/file.cljs" 10 1))
(.log js/console (throw (js/Error. "Oops")))
Expand Down
2 changes: 1 addition & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:builds {:app {:target :browser
:output-dir "resources/public/js/compiled"
:asset-path "/js/compiled"
:modules {:app {:init-fn omni-trace.omni-trace/init}}
:modules {:app {:entries [cyrik.omni-trace]}}
:devtools {:preloads [#_devtools.preload
#_user]
:after-load portal.ui.core/reload!
Expand Down
15 changes: 9 additions & 6 deletions src/omni_trace/omni_trace.cljc → src/cyrik/omni_trace.cljc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns omni-trace.omni-trace
(ns cyrik.omni-trace
(:require #?(:clj [net.cgrand.macrovich :as macros])
#?(:clj [cljs.analyzer :as analyzer])
#?(:clj [clojure.java.io :as io])
[cljs.analyzer.api :as ana])
[cljs.analyzer.api :as ana]
[cyrik.omni-trace.graph :as flame])

#?(:cljs (:require-macros [net.cgrand.macrovich :as macros]
[omni-trace.omni-trace :refer [instrument-ns uninstrument-ns]])))
[cyrik.omni-trace :refer [instrument-ns uninstrument-ns]])))

(defonce instrumented-vars (atom {}))
(def ^:dynamic *trace-log-parent* nil)
Expand Down Expand Up @@ -162,8 +162,11 @@
:cljs `(cljs-uninstrument-ns ~sym-or-syms ~opts)))))


(defn init [& args]
(print "yeah"))
(defn flamegraph
([]
(flamegraph workspace))
([workspace]
(flame/flamegraph (flame/flamedata @workspace))))

(comment

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns omni-trace.flamegraph)
(ns cyrik.omni-trace.graph)

(defn flamedata [worksapce]
(into [] (conj (vals (:log worksapce)) {:parent nil :name "root" :id :root})))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns omni-trace.testing-ns)
(ns cyrik.omni-trace.testing-ns)

(def coin-values
{:quarter 0.25
Expand Down

0 comments on commit 0d74874

Please sign in to comment.