Skip to content

Commit

Permalink
Register and make use of tracer unwind capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmonettas committed Jan 31, 2024
1 parent 071c0bb commit 3097fba
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 49 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
thheller/shadow-cljs {:mvn/version "2.23.3"}}}

:storm {:classpath-overrides {org.clojure/clojure nil}
:extra-deps {com.github.flow-storm/clojure {:mvn/version "1.11.1-18"}}
:extra-deps {com.github.flow-storm/clojure {:mvn/version "1.12.0-master-SNAPSHOT"}}
:jvm-opts [
;; "-Xmx20500m"
;;"-Dflowstorm.startRecording=false"
Expand Down
10 changes: 8 additions & 2 deletions resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@
-fx-prompt-text-fill: -fx-theme-button2-text;
}

.conn-status-lbl.ok {
.label.ok {
-fx-background-color: -fx-theme-ok;
-fx-text-fill: #323232;
}
.conn-status-lbl.fail {

.label.warning {
-fx-background-color: -fx-theme-warning;
-fx-text-fill: #323232;
}

.label.fail {
-fx-background-color: -fx-theme-fail;
-fx-text-fill: #323232;
}
Expand Down
1 change: 1 addition & 0 deletions resources/theme_dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
-fx-theme-breadcrums: #de00c0;
-fx-theme-ok: #00ff00;
-fx-theme-fail: #ff0000;
-fx-theme-warning: orange;
-fx-theme-title-label: orange;
-fx-theme-field-label: #de00c0;
-fx-theme-breakpoint: #ff0000;
Expand Down
1 change: 1 addition & 0 deletions resources/theme_light.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
-fx-theme-breadcrums: #9c0084;
-fx-theme-ok: #00ff00;
-fx-theme-fail: #ff0000;
-fx-theme-warning: orange;
-fx-theme-title-label: #336699;
-fx-theme-field-label: #9c0084;
-fx-theme-breakpoint: #ff0000;
Expand Down
15 changes: 9 additions & 6 deletions src-dbg/flow_storm/debugger/ui/flows/call_tree.clj
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,20 @@
(proxy [ChangeListener] []
(changed [changed old-val new-val]
(when new-val
(let [{:keys [args-vec ret]} (runtime-api/callstack-node-frame rt-api (.getValue new-val))]
(let [{:keys [args-vec ret throwable return/kind]} (runtime-api/callstack-node-frame rt-api (.getValue new-val))]
(flow-cmp/update-pprint-pane flow-id
thread-id
"fn_args"
args-vec
{:find-and-jump-same-val (partial flow-code/find-and-jump-same-val flow-id thread-id)})
(flow-cmp/update-pprint-pane flow-id
thread-id
"fn_ret"
ret
{:find-and-jump-same-val (partial flow-code/find-and-jump-same-val flow-id thread-id)}))))))
(flow-cmp/update-return-pprint-pane flow-id
thread-id
"fn_ret"
kind
(case kind
:return ret
:unwind throwable)
{:find-and-jump-same-val (partial flow-code/find-and-jump-same-val flow-id thread-id)}))))))

(store-obj flow-id thread-id "callstack_tree_view" tree-view)
(VBox/setVgrow tree-view Priority/ALWAYS)
Expand Down
27 changes: 24 additions & 3 deletions src-dbg/flow_storm/debugger/ui/flows/components.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
print-level-txt (doto (TextField. "5")
(.setPrefWidth 50)
(.setAlignment Pos/CENTER))
print-wrap-chk (doto (check-box {:on-change (fn [selected?] (.setWrapText result-txt selected?))})
(.setSelected false))
print-wrap-chk (doto (check-box {:on-change (fn [selected?] (.setWrapText result-txt selected?))})
(.setSelected false))
def-btn (button :label "def"
:classes ["def-btn" "btn-sm"]
:tooltip "Define a reference to this value so it can be used from the repl.")
Expand All @@ -42,12 +42,16 @@
(.setAlignment Pos/CENTER_RIGHT)
(.setSpacing 3.0))
result-type-lbl (label "")
extra-lbl (label "")
header-box (doto (h-box [result-type-lbl extra-lbl])
(.setSpacing 3.0))
box (v-box [tools-box
result-type-lbl
header-box
result-txt])]

(VBox/setVgrow result-txt Priority/ALWAYS)
(store-obj flow-id thread-id (ui-utils/thread-pprint-type-lbl-id pane-id) result-type-lbl)
(store-obj flow-id thread-id (ui-utils/thread-pprint-extra-lbl-id pane-id) extra-lbl)
(store-obj flow-id thread-id (ui-utils/thread-pprint-area-id pane-id) result-txt)
(store-obj flow-id thread-id (ui-utils/thread-pprint-level-txt-id pane-id) print-level-txt)
(store-obj flow-id thread-id (ui-utils/thread-pprint-meta-chk-id pane-id) print-meta-chk)
Expand Down Expand Up @@ -75,3 +79,20 @@

(.setText result-txt val-str)
(.setText result-type-lbl (format "Type: %s" val-type))))

(defn update-return-pprint-pane [flow-id thread-id pane-id kind val opts]
(let [[extra-lbl] (obj-lookup flow-id thread-id (ui-utils/thread-pprint-extra-lbl-id pane-id))]
(case kind
:waiting (do
(.setText extra-lbl "Waiting")
(ui-utils/rm-class extra-lbl "fail")
(ui-utils/add-class extra-lbl "warning"))
:unwind (do
(.setText extra-lbl "Throwed")
(ui-utils/rm-class extra-lbl "warning")
(ui-utils/add-class extra-lbl "fail"))
:return (do
(ui-utils/rm-class extra-lbl "fail")
(ui-utils/rm-class extra-lbl "warning")
(.setText extra-lbl "")))
(update-pprint-pane flow-id thread-id pane-id val opts)))
30 changes: 18 additions & 12 deletions src-dbg/flow_storm/debugger/ui/flows/functions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

(defn- function-call-click [flow-id thread-id mev selected-items {:keys [list-view-pane]}]
(let [idx (-> selected-items first :fn-call-idx)
ret-val (-> selected-items first :ret)
{:keys [ret throwable return/kind]} (first selected-items)
jump-to-idx (fn []
(ui-flows-gral/select-thread-tool-tab flow-id thread-id :code)
(flows-code/jump-to-coord flow-id
Expand All @@ -118,11 +118,14 @@
(and (= MouseButton/PRIMARY (.getButton mev))
(= 1 (.getClickCount mev)))

(flow-cmp/update-pprint-pane flow-id
thread-id
"functions-calls-ret-val"
ret-val
{:find-and-jump-same-val (partial flows-code/find-and-jump-same-val flow-id thread-id)})
(flow-cmp/update-return-pprint-pane flow-id
thread-id
"functions-calls-ret-val"
kind
(case kind
:return ret
:unwind throwable)
{:find-and-jump-same-val (partial flows-code/find-and-jump-same-val flow-id thread-id)})

(and (= MouseButton/PRIMARY (.getButton mev))
(= 2 (.getClickCount mev)))
Expand All @@ -149,12 +152,15 @@
:cell-factory-fn (partial functions-calls-cell-factory selected-args)
:on-click (partial function-call-click flow-id thread-id)
:on-enter (fn [sel-items]
(let [ret-val (-> sel-items first :ret)]
(flow-cmp/update-pprint-pane flow-id
thread-id
"functions-calls-ret-val"
ret-val
{:find-and-jump-same-val (partial flows-code/find-and-jump-same-val flow-id thread-id)})))
(let [{:keys [ret throwable return/kind]} (first sel-items)]
(flow-cmp/update-return-pprint-pane flow-id
thread-id
"functions-calls-ret-val"
kind
(case kind
:return ret
:unwind throwable)
{:find-and-jump-same-val (partial flows-code/find-and-jump-same-val flow-id thread-id)})))
:selection-mode :single})
args-print-type-checks (doto (->> args-checks
(map-indexed (fn [idx cb]
Expand Down
1 change: 1 addition & 0 deletions src-dbg/flow_storm/debugger/ui/timeline/screen.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
(case type
:fn-call [(thread-label thread-id name) idx (format "%s/%s" fn-ns fn-name) "" "" ""]
:fn-return [(thread-label thread-id name) idx "RETURN" "" expr-val-str expr-type]
:fn-unwind [(thread-label thread-id name) idx "UNWIND" "" "" expr-type]
:expr-exec [(thread-label thread-id name) idx "" expr-str expr-val-str expr-type])
(assoc tl-entry :color (thread-color thread-id))))))
add-all)))
Expand Down
3 changes: 3 additions & 0 deletions src-dbg/flow_storm/debugger/ui/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@
(defn thread-pprint-type-lbl-id [pane-id]
(format "pprint_type_lbl_%s" pane-id))

(defn thread-pprint-extra-lbl-id [pane-id]
(format "pprint_extra_lbl_%s" pane-id))

(defn thread-pprint-def-btn-id [pane-id]
(format "pprint_def_btn_id_%s" pane-id))

Expand Down
18 changes: 9 additions & 9 deletions src-inst/flow_storm/runtime/debuggers_api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@

(def timeline-count index-api/timeline-count)

(defn- reference-frame-data! [{:keys [dispatch-val] :as frame-data}]
(defn- reference-frame-data! [{:keys [dispatch-val return/kind] :as frame-data}]
(cond-> frame-data
true (dissoc :frame)
dispatch-val (update :dispatch-val reference-value!)
true (update :args-vec reference-value!)
true (update :ret reference-value!)
true (update :bindings (fn [bs]
(mapv #(update % :value reference-value!) bs)))
true (update :expr-executions (fn [ee]
(mapv #(update % :result reference-value!) ee)))))
true (dissoc :frame)
dispatch-val (update :dispatch-val reference-value!)
true (update :args-vec reference-value!)
(= kind :return) (update :ret reference-value!)
(= kind :unwind) (update :throwable reference-value!)
true (update :bindings (fn [bs] (mapv #(update % :value reference-value!) bs)))
true (update :expr-executions (fn [ee] (mapv #(update % :result reference-value!) ee)))))

(defn reference-timeline-entry! [entry]
(case (:type entry)
:fn-call (update entry :fn-args reference-value!)
:fn-return (update entry :result reference-value!)
:fn-unwind (update entry :throwable reference-value!)
:bind (update entry :value reference-value!)
:expr (update entry :result reference-value!)))

Expand Down
6 changes: 4 additions & 2 deletions src-inst/flow_storm/runtime/indexes/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@
(when forms-registry
(try
(index-protos/get-form forms-registry form-id)
(catch Exception _ nil))))
#?(:clj (catch Exception _ nil)
:cljs (catch js/Error _ nil)))))

(defn all-threads []
(when flow-thread-registry
Expand Down Expand Up @@ -284,6 +285,7 @@
[entry-coord entry-idx] (case (:type entry)
:fn-call [[] fn-call-idx]
:fn-return [(:coord entry) (:idx entry)]
:fn-unwind [(:coord entry) (:idx entry)]
:expr [(:coord entry) (:idx entry)])]

(cond->> (:bindings frame-data)
Expand Down Expand Up @@ -502,7 +504,7 @@
(fn-call-trace/fn-call-trace? tl-entry)
(recur rest-entries (conj thread-stack tl-entry) prints)

(fn-return-trace/fn-return-trace? tl-entry)
(fn-return-trace/fn-end-trace? tl-entry)
(recur rest-entries (pop thread-stack) (maybe-print-entry prints (first thread-stack) tl-entry))

(expr-trace/expr-trace? tl-entry)
Expand Down
3 changes: 3 additions & 0 deletions src-inst/flow_storm/runtime/indexes/protocols.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
(defprotocol ExpressionTimelineEntryP
(get-expr-val [_]))

(defprotocol UnwindTimelineEntryP
(get-throwable [_]))

(defprotocol TreeP
(tree-root-index [_])
(tree-childs-indexes [_ fn-call-idx])
Expand Down
4 changes: 2 additions & 2 deletions src-inst/flow_storm/runtime/indexes/thread_registry.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [flow-storm.runtime.indexes.protocols :as index-protos]
[flow-storm.runtime.indexes.utils :refer [int-map make-mutable-list ml-add ml-clear]]
[flow-storm.runtime.types.fn-call-trace :as fn-call-trace :refer [fn-call-trace?]]
[flow-storm.runtime.types.fn-return-trace :as fn-return-trace :refer [fn-return-trace?]]
[flow-storm.runtime.types.fn-return-trace :as fn-return-trace :refer [fn-end-trace?]]
[flow-storm.runtime.types.expr-trace :as expr-trace :refer [expr-trace?]]
[clojure.string :as str]
[hansel.utils :as hansel-utils])
Expand Down Expand Up @@ -150,7 +150,7 @@
:fn-ns (fn-call-trace/get-fn-ns entry)
:fn-name (fn-call-trace/get-fn-name entry)}))

(fn-return-trace? entry)
(fn-end-trace? entry)
(recur r
(update threads-stacks tid pop)
(conj! timeline-ret {:type :fn-return
Expand Down
22 changes: 18 additions & 4 deletions src-inst/flow_storm/runtime/indexes/timeline_index.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
(let [last-idx (dec (ml-count timeline))
init-entry (ml-get timeline idx)
init-fn-call-idx (index-protos/fn-call-idx init-entry)]
(if (fn-return-trace/fn-return-trace? init-entry)
(if (fn-return-trace/fn-end-trace? init-entry)
;; if we are on a return just move next
(inc idx)

Expand Down Expand Up @@ -137,7 +137,7 @@
(+ 2 idx))
(+ 1 idx))))))

(defrecord ExecutionTimelineTree [;; an array of FnCall, Expr, FnRet
(defrecord ExecutionTimelineTree [;; an array of FnCall, Expr, FnRet, FnUnwind
timeline

;; a stack of pointers to prev FnCall
Expand Down Expand Up @@ -296,6 +296,16 @@
(conj ch-indexes i))

(recur (inc i) ch-indexes)))))))))

#?@(:clj
[Object
(toString [_]
(.toString
(reduce (fn [^StringBuilder sb tl-entry]
(.append sb (str tl-entry))
(.append sb "\n"))
(StringBuilder.)
timeline)))])

(tree-frame-data [this fn-call-idx {:keys [include-path? include-exprs? include-binds?]}]
(if (= fn-call-idx tree-root-idx)
Expand All @@ -309,11 +319,15 @@
fr-data {:fn-ns (fn-call-trace/get-fn-ns fn-call)
:fn-name (fn-call-trace/get-fn-name fn-call)
:args-vec (fn-call-trace/get-fn-args fn-call)
:ret (when fn-return
(index-protos/get-expr-val fn-return))
:form-id (fn-call-trace/get-form-id fn-call)
:fn-call-idx fn-call-idx
:parent-fn-call-idx (fn-call-trace/get-parent-idx fn-call)}
fr-data (cond-> fr-data
(nil? fn-return) (assoc :return/kind :waiting)
(fn-return-trace/fn-unwind-trace? fn-return) (assoc :return/kind :unwind
:throwable (index-protos/get-throwable fn-return))
(fn-return-trace/fn-return-trace? fn-return) (assoc :return/kind :return
:ret (index-protos/get-expr-val fn-return)))
fr-data (if include-path?
(assoc fr-data :fn-call-idx-path (get-fn-call-idx-path timeline fn-call-idx))
fr-data)
Expand Down
2 changes: 1 addition & 1 deletion src-inst/flow_storm/runtime/types/expr_trace.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

#?@(:clj
[Object
(toString [_] (utils/format "[ExprTrace] coord: %s, valType: %s" coord (type exprVal)))]))
(toString [_] (utils/format "[%d ExprTrace] coord: %s, valType: %s" thisIdx coord (type exprVal)))]))

(defn make-expr-trace [coord expr-val]
(->ExprTrace coord expr-val nil-idx nil-idx))
Expand Down
2 changes: 1 addition & 1 deletion src-inst/flow_storm/runtime/types/fn_call_trace.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

#?@(:clj
[Object
(toString [_] (utils/format "[FnCallTrace] %s/%s form-id: %d" fnNs fnName formId))]))
(toString [_] (utils/format "[%d FnCallTrace] %s/%s form-id: %d ret: %d" thisIdx fnNs fnName formId retIdx))]))

(defn make-fn-call-trace [fn-ns fn-name form-id fn-args]
(->FnCallTrace fn-name
Expand Down
Loading

0 comments on commit 3097fba

Please sign in to comment.