Skip to content

Commit

Permalink
Improve dev ns
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Oct 31, 2023
1 parent bb2d37c commit 496aa01
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 112 deletions.
169 changes: 60 additions & 109 deletions src-dev/dev.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
(ns dev

"A bunch of utilities to help with development.
After loading this ns you can :
- `start-local` to start the UI and runtime
- `start-remote` to run only the UI and connect it to a remote process. Looks at the body for config.
- `stop` for gracefully stopping the system
- `refresh` to make tools.namespace unmap and reload all the modified files"

(:require [flow-storm.debugger.ui.main :as ui-main]
[flow-storm.debugger.main :as main]
[flow-storm.debugger.state :as dbg-state]
[cljs.main :as cljs-main]
[hansel.api :as hansel]
[flow-storm.api :as fs-api]
[flow-storm.runtime.indexes.api :as index-api]
Expand All @@ -20,12 +29,8 @@

(javafx.embed.swing.JFXPanel.)

(comment (add-tap (bound-fn* println)) )

(comment


(remove-watch state :spec-validator)
(add-tap (bound-fn* println))
)

#_(Thread/setDefaultUncaughtExceptionHandler
Expand All @@ -39,7 +44,7 @@
;; Utilities for reloading everything ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn instrument-state []
(defn spec-instrument-state []
(add-watch
dbg-state/state
:spec-validator
Expand All @@ -48,61 +53,47 @@
(s/explain ::dbg-state/state s))))
nil)

(comment
(remove-watch state :spec-validator)
)

(defn start-local []
(fs-api/local-connect {:theme :ligth})
(instrument-state))
(spec-instrument-state))


(defn start-remote []

(comment

(main/start-debugger {:port 9000
:repl-type :shadow
:build-id :browser-repl})

(main/start-debugger {:port 9000
:repl-type :shadow
:build-id :app})

(main/start-debugger {})
(main/start-debugger {:port 9000})

(main/start-debugger {:port 46000
:repl-type :shadow
:build-id :analysis-viewer})
(main/stop-debugger)

)

(main/start-debugger {:port 9000
:repl-type :shadow
:build-id :browser-repl}))
:build-id :browser-repl})
(spec-instrument-state))

(defn stop []
(fs-api/stop))

(defn after-refresh []
(alter-var-root #'utils/out-print-writer (constantly *out*))
(log "Refresh done"))

(defn stop []
(fs-api/stop))

(defn refresh []
(tools-namespace-repl/refresh :after 'dev/after-refresh))
(let [running? dbg-state/state]
(when running?
(log "System is running, stopping first ...")
(stop))
(tools-namespace-repl/refresh :after 'dev/after-refresh )))

;;;;;;;;;;;;;;;;;;;;;;;;;
;; Playing at the repl ;;
;;;;;;;;;;;;;;;;;;;;;;;;;

(comment

(local-restart-everything)

)


;; instrument and run dev-tester namespaces
(comment

;;;;;;;;;;;;;;;;;;;;;;;
;; Vanilla FlowStorm ;;
;;;;;;;;;;;;;;;;;;;;;;;

(fs-api/instrument-namespaces-clj
#{"dev-tester"}
{:disable #{} #_#{:expr-exec :anonymous-fn :bind}})
Expand All @@ -111,18 +102,39 @@

#rtrace (dev-tester/boo [2 "hello" 6])

)
;;;;;;;;;;
;; Docs ;;
;;;;;;;;;;

;; local start with different themes
(comment
(def r (sampler/sample
{:result-name "dev-tester-flow-docs-0.1.0"
:inst-ns-prefixes #{"dev-tester"}
:verbose? true
:print-unsampled? true}
(dev-tester/boo [1 "hello" 6])))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Example expressions to generate trace data ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn bar [a b] (+ a b))
(defn foo [a b] (let [c (+ a b)] (bar c c)))

(fs-api/local-connect {:theme :light})
(fs-api/stop)
(fs-api/local-connect {:theme :dark})
(doall (pmap (fn [i] (foo i (inc i))) (range 4)))

(dev-tester/boo [1 "hello" 4])

(flow-storm.api/continue)

(defn my-sum [a b] (+ a b))

(doall (pmap (fn my-sum [i] (+ i i)) (range 4)))
)

;; ideas for accessing the indexes programmatically
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Querying indexes programatically ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(comment

(index-api/print-threads)
Expand Down Expand Up @@ -191,70 +203,9 @@

;; use the debugger
(index-api/print-threads)
(index-api/select-thread 0 16)
(index-api/select-thread nil 18)

(step-next)
(step-prev)

;; ---------------------------------------------------------------------------------------------


)

;; forms instrumentation
(comment

(inst-forms/instrument {:disable #{}} '(defn foo [a b] ^{:meta true} (conj [] b)))

)


;; Function sampler

(comment

(def r (sampler/sample
{:result-name "dev-tester-flow-docs-0.1.0"
:inst-ns-prefixes #{"dev-tester"}
:verbose? true
:print-unsampled? true}
(dev-tester/boo [1 "hello" 6])))

(io/copy (io/file "/tmp/1670878691457-36075814-1/samples.edn")
(io/file "samples.edn"))

(defn bar [a b] (+ a b))
(defn foo [a b] (let [c (+ a b)] (bar c c)))

(doall (pmap (fn [i] (foo i (inc i))) (range 4)))

(dev-tester/boo [1 "hello" 4])

(flow-storm.api/continue)

(defn my-sum [a b] (+ a b))

(doall (pmap (fn my-sum [i] (+ i i)) (range 4)))

)

(defn cljs-repl []
(cljs.main/-main "--repl"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Steps to debug the ClojureScriptStorm compiler ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; - cider-jackin to start a clj repl and load this dev namespace
;; - on other term run a dbg : clj -X:dev flow-storm.debugger.main/start-debugger
;; - on term run ./repl-conn to connect another repl to the jackin process
;; - eval (dev/cljs-repl) to start a Cljs repl, this will open the browser
;; - on cljs repl : (require 'flow-storm.preload)
;; - on cljs repl : (ns dev)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Compile and run ClojureScriptStorm cljs.main repl ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; clj -J-Dcljs.storm.instrumentOnlyPrefixes=dev -J-Dcljs.storm.instrumentEnable=true -Sdeps '{:paths ["src"] :deps {com.github.jpmonettas/clojurescript {:mvn/version "1.11.124"} com.github.jpmonettas/flow-storm-inst {:local/root "/home/jmonetta/my-projects/flow-storm-debugger"}}}' -M -m cljs.main -co '{:preloads [cljs.storm.tracer flow-storm.preload] :main org.foo.dev-tester}' --compile
;; clj -J-Dcljs.storm.instrumentOnlyPrefixes=dev -J-Dcljs.storm.instrumentEnable=true -Sdeps '{:paths ["src"] :deps {com.github.jpmonettas/clojurescript {:mvn/version "1.11.124"} com.github.jpmonettas/flow-storm-inst {:local/root "/home/jmonetta/my-projects/flow-storm-debugger"}}}' -M -m cljs.main -co '{:preloads [cljs.storm.tracer flow-storm.preload] :main org.foo.dev-tester}' --repl
6 changes: 3 additions & 3 deletions src-inst/flow_storm/tutorials/basics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ Before closing this are some tips I've found for using FlowStorm efficiently :
- Use the jvm options described in :help to configure it so you don't record unnecessary stuff.
And that is all for the basics. If you find any issues or suggestions feel free
to open a issue in https://github.com/jpmonettas/flow-storm-debugger
to open a issue in https://github.com/flow-storm/flow-storm-debugger
Now let's go add it to your current project and give it a try.
All you have to do is to edit your deps.edn file and add a :dev alias with a config like:
----------------------------------
{:classpath-overrides {org.clojure/clojure nil}
:extra-deps {com.github.jpmonettas/clojure {:mvn/version \"LATEST-AVAILABLE-VERSION\"}
com.github.jpmonettas/flow-storm-dbg {:mvn/version \"LATEST-AVAILABLE-VERSION\"}}
:extra-deps {com.github.flow-storm/clojure {:mvn/version \"LATEST-AVAILABLE-VERSION\"}
com.github.flow-storm/flow-storm-dbg {:mvn/version \"LATEST-AVAILABLE-VERSION\"}}
:jvm-opts [\"-Dflowstorm.startRecording=true\"
\"-Dclojure.storm.instrumentEnable=true\"
\"-Dclojure.storm.instrumentOnlyPrefixes=YOUR-PROJECT-TOP-NS\"]}
Expand Down

0 comments on commit 496aa01

Please sign in to comment.