Skip to content

Commit da078d3

Browse files
committed
Big refactor
1 parent 5241593 commit da078d3

File tree

9 files changed

+221
-218
lines changed

9 files changed

+221
-218
lines changed

build.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[clojure.spec.alpha :as s]))
66

77
(def version (or (System/getenv "VERSION")
8-
"4.3.0"))
8+
"4.4.0-SNAPSHOT"))
99

1010
(def target-dir "target")
1111
(def class-dir (str target-dir "/classes"))

src-dbg/flow_storm/debugger/events_processor.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@
124124
(= 1 (count (dbg-state/flow-exceptions flow-id))))
125125
(flows-screen/goto-location unwind-data)))))
126126

127-
(defn expression-bookmark-event [{:keys [flow-id thread-id idx note] :as bookmark-location}]
127+
(defn expression-bookmark-event [{:keys [flow-id thread-id idx note source] :as bookmark-location}]
128128
(ui-utils/run-later
129129
(dbg-state/add-bookmark {:flow-id flow-id
130130
:thread-id thread-id
131131
:idx idx
132-
:source :bookmark.source/api
132+
:source (or source :bookmark.source/api)
133133
:note note})
134134
(bookmarks/update-bookmarks)
135135
;; jump to the first mark, unless, we've already jumped to an exception

src-dbg/flow_storm/debugger/ui/components.clj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
[org.fxmisc.richtext CodeArea]
2424
[org.fxmisc.flowless VirtualFlow]
2525
[javafx.stage Stage]
26-
[javafx.scene.web WebView WebEngine]))
26+
[javafx.scene.web WebView WebEngine]
27+
[javafx.concurrent Worker$State]))
2728

2829
(defn pane [& {:keys [childs classes]}]
2930
(let [p (Pane. (into-array Node childs))]
@@ -855,4 +856,14 @@
855856
^WebEngine web-engine (.getEngine wv)]
856857
{:web-view wv
857858
:set-html (fn [html] (.loadContent web-engine html))
858-
:load-url (fn [url] (.load web-engine url))}))
859+
:load-url (fn [url] (.load web-engine url))
860+
:set-handlers (fn [handlers-map]
861+
(-> web-engine
862+
.getLoadWorker
863+
.stateProperty
864+
(.addListener (proxy [ChangeListener] []
865+
(changed [_ old-state new-state]
866+
(when (= new-state Worker$State/SUCCEEDED)
867+
(let [window (.executeScript web-engine "window")]
868+
(doseq [[method-name method-fn] handlers-map]
869+
(.setMember window method-name method-fn)))))))))}))

src-inst/flow_storm/runtime/indexes/api.cljc

Lines changed: 143 additions & 145 deletions
Large diffs are not rendered by default.

src-inst/flow_storm/runtime/indexes/protocols.cljc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
(defprotocol TimelineP
1818
(flow-id [_])
19-
(thread-id [_ idx]))
19+
(thread-id [_ idx])
20+
(thread-name [_ idx]))
2021

2122
(defprotocol TimelineEntryP
2223
(entry-type [_]))
@@ -74,18 +75,16 @@
7475
;; Thread registry protocols ;;
7576
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7677

77-
(defprotocol ThreadRegistryP
78+
(defprotocol FlowsThreadsRegistryP
7879
(all-threads [_])
7980
(flow-threads-info [_ flow-id])
8081
(set-thread-blocked [_ flow-id thread-id breakpoint])
81-
(get-thread-indexes [_ flow-id thread-id])
82+
(get-thread-tracker [_ flow-id thread-id])
8283
(flow-exists? [_ flow-id])
83-
(register-thread-indexes [_ flow-id thread-id thread-name form-id indexes])
84+
(register-thread [_ flow-id thread-id thread-name timeline init-fn-call-limits])
8485
(record-total-order-entry [_ flow-id th-timeline th-idx])
8586
(total-order-timeline [_ flow-id])
86-
(discard-threads [_ flow-threads-ids])
87-
(start-thread-registry [_ callbacks])
88-
(stop-thread-registry [_]))
87+
(discard-threads [_ flow-threads-ids]))
8988

9089
;;;;;;;;;;;;;;;;;;;;;;;
9190
;; Entries protocols ;;

src-inst/flow_storm/runtime/indexes/thread_registry.cljc

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,21 @@
66
#?(:clj (:import [clojure.data.int_map PersistentIntMap])))
77

88

9-
(defrecord ThreadRegistry [;; atom of int-map with flow-id -> thread-id -> indexes
10-
registry
9+
(defrecord FlowsThreadsRegistry [;; atom of int-map with flow-id -> thread-id -> thread-info
10+
registry
1111

12-
;; atom of int-map with flow-id -> TotalOrderTimeline
13-
total-order-timelines
12+
;; atom of int-map with flow-id -> TotalOrderTimeline
13+
total-order-timelines]
1414

15-
;; atom with threads events callbacks, like thread creation
16-
callbacks]
17-
18-
index-protos/ThreadRegistryP
15+
index-protos/FlowsThreadsRegistryP
1916

2017
(all-threads [_]
2118
(reduce-kv (fn [all-ths fid threads]
2219
(into all-ths (mapv
2320
(fn [tid] [fid tid])
2421
(keys threads))))
2522
#{}
26-
@registry))
23+
@registry))
2724

2825
(flow-threads-info [_ flow-id]
2926
(->> (get @registry flow-id)
@@ -37,40 +34,35 @@
3734
(flow-exists? [_ flow-id]
3835
(contains? @registry flow-id))
3936

40-
(get-thread-indexes [_ flow-id thread-id]
37+
(get-thread-tracker [_ flow-id thread-id]
4138
#?(:clj
4239
(some-> ^PersistentIntMap @registry
4340
^PersistentIntMap (.get flow-id)
44-
^clojure.lang.PersistentArrayMap (.get thread-id)
45-
(.get :thread/indexes))
41+
^clojure.lang.PersistentArrayMap (.get thread-id))
4642
:cljs
4743
(some-> @registry
4844
(get flow-id)
49-
(get thread-id)
50-
(get :thread/indexes))))
51-
52-
(register-thread-indexes [this flow-id thread-id thread-name form-id indexes]
53-
(when-not (index-protos/flow-exists? this flow-id)
54-
(swap! total-order-timelines assoc flow-id (total-order-timeline/make-total-order-timeline flow-id)))
55-
56-
(swap! registry update flow-id
57-
(fn [threads]
58-
(assoc (or threads (int-map)) thread-id {:thread/id thread-id
59-
:thread/name (if (str/blank? thread-name)
60-
(str "Thread-" thread-id)
61-
thread-name)
62-
:thread/indexes indexes
63-
:thread/blocked nil})))
64-
65-
(when-let [otc (:on-thread-created @callbacks)]
66-
(otc {:flow-id flow-id
67-
:thread-id thread-id
68-
:thread-name thread-name
69-
:form-id form-id})))
70-
71-
(set-thread-blocked [this flow-id thread-id breakpoint]
72-
(when (index-protos/get-thread-indexes this flow-id thread-id)
73-
(swap! registry assoc-in [flow-id thread-id :thread/blocked] breakpoint)))
45+
(get thread-id))))
46+
47+
(register-thread [this flow-id thread-id thread-name timeline init-fn-call-limits]
48+
(let [thread-tracker {:thread/id thread-id
49+
:thread/name (if (str/blank? thread-name)
50+
(str "Thread-" thread-id)
51+
thread-name)
52+
:thread/timeline timeline
53+
:thread/*fn-call-limits (atom init-fn-call-limits)
54+
:thread/*thread-limited (atom nil)
55+
:thread/blocked nil}]
56+
(when-not (index-protos/flow-exists? this flow-id)
57+
(swap! total-order-timelines assoc flow-id (total-order-timeline/make-total-order-timeline flow-id)))
58+
59+
(swap! registry update flow-id
60+
(fn [threads]
61+
(assoc (or threads (int-map)) thread-id thread-tracker)))
62+
thread-tracker))
63+
64+
(set-thread-blocked [_ flow-id thread-id breakpoint]
65+
(swap! registry assoc-in [flow-id thread-id :thread/blocked] breakpoint))
7466

7567
(discard-threads [this flow-threads-ids]
7668
(doseq [[fid tid] flow-threads-ids]
@@ -79,30 +71,23 @@
7971
;; remove empty flows from the registry since flow-exist? uses it
8072
;; kind of HACKY...
8173
(let [empty-flow-ids (reduce-kv (fn [efids fid threads-map]
82-
(if (empty? threads-map)
83-
(conj efids fid)
84-
efids))
85-
#{}
86-
@registry)]
74+
(if (empty? threads-map)
75+
(conj efids fid)
76+
efids))
77+
#{}
78+
@registry)]
8779
(swap! registry (fn [flows-map] (apply dissoc flows-map empty-flow-ids))))
8880

8981
(doseq [[fid] flow-threads-ids]
9082
(index-protos/tot-clear-all (index-protos/total-order-timeline this fid))))
9183

92-
(start-thread-registry [thread-reg cbs]
93-
(reset! callbacks cbs)
94-
thread-reg)
95-
96-
(stop-thread-registry [_] nil)
97-
9884
(record-total-order-entry [_ flow-id th-timeline th-idx]
9985
(-> (get @total-order-timelines flow-id)
10086
(index-protos/tot-add-entry th-timeline th-idx)))
10187

10288
(total-order-timeline [_ flow-id]
10389
(get @total-order-timelines flow-id)))
10490

105-
(defn make-thread-registry []
106-
(map->ThreadRegistry {:registry (atom (int-map))
107-
:total-order-timelines (atom (int-map))
108-
:callbacks (atom {})}))
91+
(defn make-flows-threads-registry []
92+
(map->FlowsThreadsRegistry {:registry (atom (int-map))
93+
:total-order-timelines (atom (int-map))}))

src-inst/flow_storm/runtime/indexes/timeline_index.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363

6464
;; this timeline thread id
6565
tid
66+
67+
;; the thread name that created this timeilne
68+
tname
6669

6770
;; an array of FnCall, Expr, FnRet, FnUnwind
6871
timeline
@@ -80,6 +83,7 @@
8083
index-protos/TimelineP
8184
(flow-id [_] flow-id)
8285
(thread-id [_ _] tid)
86+
(thread-name [_ _] tname)
8387

8488
index-protos/ThreadTimelineRecorderP
8589

@@ -276,11 +280,11 @@
276280
(defmethod print-method ExecutionTimelineTree [timeline ^java.io.Writer w]
277281
(.write w ^String (print-it timeline))))
278282

279-
(defn make-index [flow-id thread-id]
283+
(defn make-index [flow-id thread-id thread-name]
280284
(let [build-stack (make-mutable-stack)
281285
timeline (make-mutable-list)
282286
stats (make-mutable-hashmap)]
283-
(->ExecutionTimelineTree flow-id thread-id timeline build-stack stats 0)))
287+
(->ExecutionTimelineTree flow-id thread-id thread-name timeline build-stack stats 0)))
284288

285289
(defn- fn-call-exprs [timeline fn-call-idx]
286290
(locking timeline

src-inst/flow_storm/runtime/values.cljc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
(defprotocol PValueRefRegistry
4444
(add-val-ref [_ v])
4545
(get-value [_ vref])
46-
(get-value-ref [_ v]))
46+
(get-value-ref [_ v])
47+
(all-val-ref-tuples [_]))
4748

4849
;; Fast way of going from
4950
;; value-ref -> value
@@ -63,7 +64,7 @@
6364
(if (contains? wv->vref wv)
6465
this
6566
(let [next-vid (inc max-vid)
66-
vref (types/make-value-ref next-vid)]
67+
vref (types/make-value-ref max-vid)]
6768
(-> this
6869
(assoc :max-vid next-vid)
6970
(update :vref->wv assoc vref wv)
@@ -74,11 +75,16 @@
7475

7576
(get-value-ref [_ v]
7677
(let [wv (hashable-obj-wrap v)]
77-
(get wv->vref wv))))
78+
(get wv->vref wv)))
7879

79-
(def init-ref-registry (map->ValueRefRegistry {:vref->wv {} :wv->vref {} :max-vid 0}))
80+
(all-val-ref-tuples [_]
81+
(->> (seq wv->vref)
82+
(map (fn [[wv vref]] [(unwrap wv) vref])))))
8083

81-
(defonce values-ref-registry (atom init-ref-registry))
84+
(defn make-empty-value-ref-registry []
85+
(map->ValueRefRegistry {:vref->wv {} :wv->vref {} :max-vid 0}))
86+
87+
(defonce values-ref-registry (atom (make-empty-value-ref-registry)))
8288

8389
(defn deref-value [vref]
8490
(if (types/value-ref? vref)
@@ -109,7 +115,7 @@
109115
(reference-value! :flow-storm/error-referencing-value)))))
110116

111117
(defn clear-vals-ref-registry []
112-
(reset! values-ref-registry init-ref-registry))
118+
(reset! values-ref-registry (make-empty-value-ref-registry)))
113119

114120
(defprotocol SnapshotP
115121
(snapshot-value [_]))

src-inst/flow_storm/tracer.cljc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
(contains? brks [fn-ns fn-name])
125125
(apply (-> (get brks [fn-ns fn-name]) meta :predicate) fn-args))
126126
;; before blocking, let's make sure the thread exists
127-
(indexes-api/get-or-create-thread-indexes flow-id thread-id thread-name form-id)
127+
(indexes-api/get-or-create-thread-tracker flow-id thread-id thread-name)
128128
(block-this-thread flow-id [fn-ns fn-name]))))
129129

130130
(when @recording

0 commit comments

Comments
 (0)