mirror of
https://github.com/status-im/re-frame-10x.git
synced 2025-01-16 09:24:47 +00:00
Incrementally parse traces
Rather than re-parsing them every time we get a new set of traces. This is much more efficient and lets us do more useful things in the future.
This commit is contained in:
parent
af4afbae88
commit
631fa68448
@ -485,34 +485,35 @@
|
|||||||
(rf/reg-event-db
|
(rf/reg-event-db
|
||||||
:epochs/receive-new-traces
|
:epochs/receive-new-traces
|
||||||
(fn [db [_ new-traces]]
|
(fn [db [_ new-traces]]
|
||||||
(if-let [new-traces (->> (filter log-trace? new-traces)
|
(if-let [filtered-traces (->> (filter log-trace? new-traces)
|
||||||
(sort-by :id))]
|
(sort-by :id))]
|
||||||
(let [number-of-epochs-to-retain (get-in db [:settings :number-of-epochs])
|
(let [number-of-epochs-to-retain (get-in db [:settings :number-of-epochs])
|
||||||
events-to-ignore (->> (get-in db [:settings :ignored-events]) vals (map :event-id) set)
|
events-to-ignore (->> (get-in db [:settings :ignored-events]) vals (map :event-id) set)
|
||||||
previous-traces (get-in db [:traces :all-traces] [])
|
previous-traces (get-in db [:traces :all-traces] [])
|
||||||
all-traces (reduce conj previous-traces new-traces)
|
parse-state (get-in db [:epochs :parse-state] metam/initial-parse-state)
|
||||||
matches (:matches (metam/parse-traces all-traces))
|
all-traces (reduce conj previous-traces filtered-traces)
|
||||||
matches (remove (fn [match]
|
parse-state (metam/parse-traces parse-state filtered-traces)
|
||||||
|
new-matches (:partitions parse-state)
|
||||||
|
previous-matches (get-in db [:epochs :matches] [])
|
||||||
|
parse-state (assoc parse-state :partitions []) ;; Remove matches we know about
|
||||||
|
new-matches (remove (fn [match]
|
||||||
(let [event (get-in (metam/matched-event match) [:tags :event])]
|
(let [event (get-in (metam/matched-event match) [:tags :event])]
|
||||||
(contains? events-to-ignore (first event)))) matches)
|
(contains? events-to-ignore (first event)))) new-matches)
|
||||||
retained-epochs (take-last number-of-epochs-to-retain matches)
|
all-matches (reduce conj previous-matches new-matches)
|
||||||
first-id-to-retain (:id (ffirst retained-epochs))
|
retained-matches (into [] (take-last number-of-epochs-to-retain all-matches))
|
||||||
|
first-id-to-retain (:id (ffirst retained-matches))
|
||||||
retained-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) all-traces)]
|
retained-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) all-traces)]
|
||||||
(rf/dispatch [:epochs/update-epochs {:matches retained-epochs}])
|
(-> db
|
||||||
(assoc-in db [:traces :all-traces] retained-traces))
|
(assoc-in [:traces :all-traces] retained-traces)
|
||||||
|
(update :epochs (fn [epochs]
|
||||||
|
(assoc epochs
|
||||||
|
:matches retained-matches
|
||||||
|
:matches-by-id (into {} (map (juxt first-match-id identity)) retained-matches)
|
||||||
|
:match-ids (mapv first-match-id retained-matches)
|
||||||
|
:parse-state parse-state)))))
|
||||||
;; Else
|
;; Else
|
||||||
db)))
|
db)))
|
||||||
|
|
||||||
(rf/reg-event-db
|
|
||||||
:epochs/update-epochs
|
|
||||||
[(rf/path [:epochs])]
|
|
||||||
(fn [epochs [_ rt]]
|
|
||||||
(let [matches (:matches rt)]
|
|
||||||
(assoc epochs
|
|
||||||
:matches matches
|
|
||||||
:matches-by-id (into {} (map (juxt first-match-id identity)) matches)
|
|
||||||
:match-ids (mapv first-match-id matches)))))
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:epochs/previous-epoch
|
:epochs/previous-epoch
|
||||||
[(rf/path [:epochs])]
|
[(rf/path [:epochs])]
|
||||||
|
@ -185,50 +185,51 @@
|
|||||||
(defn quiescent? [event]
|
(defn quiescent? [event]
|
||||||
(= :reagent/quiescent (:op-type event)))
|
(= :reagent/quiescent (:op-type event)))
|
||||||
|
|
||||||
(defn parse-traces [traces]
|
(def initial-parse-state
|
||||||
(let [partitions (reduce
|
{:current-match nil
|
||||||
(fn [state event]
|
:previous-event nil
|
||||||
(let [current-match (:current-match state)
|
:partitions []})
|
||||||
previous-event (:previous-event state)
|
|
||||||
no-match? (nil? current-match)]
|
|
||||||
(-> (cond
|
|
||||||
|
|
||||||
;; No current match yet, check if this is the start of an epoch
|
(defn parse-traces [parse-state traces]
|
||||||
no-match?
|
(reduce
|
||||||
(if (start-of-epoch? event)
|
(fn [state event]
|
||||||
(assoc state :current-match [event])
|
(let [current-match (:current-match state)
|
||||||
state)
|
previous-event (:previous-event state)
|
||||||
|
no-match? (nil? current-match)]
|
||||||
|
(-> (cond
|
||||||
|
|
||||||
;; We are in an epoch match, and reagent has gone to a quiescent state
|
;; No current match yet, check if this is the start of an epoch
|
||||||
(quiescent? event)
|
no-match?
|
||||||
(-> state
|
(if (start-of-epoch? event)
|
||||||
(update :partitions conj (conj current-match event))
|
(assoc state :current-match [event])
|
||||||
(assoc :current-match nil))
|
state)
|
||||||
|
|
||||||
;; We are in an epoch match, and we have started a new epoch
|
;; We are in an epoch match, and reagent has gone to a quiescent state
|
||||||
;; The previously seen event was the last event of the old epoch,
|
(quiescent? event)
|
||||||
;; and we need to start a new one from this event.
|
(-> state
|
||||||
(start-of-epoch-and-prev-end? event state)
|
(update :partitions conj (conj current-match event))
|
||||||
(-> state
|
(assoc :current-match nil))
|
||||||
(update :partitions conj (conj current-match previous-event))
|
|
||||||
(assoc :current-match [event]))
|
|
||||||
|
|
||||||
(event-run? event)
|
;; We are in an epoch match, and we have started a new epoch
|
||||||
(update state :current-match conj event)
|
;; The previously seen event was the last event of the old epoch,
|
||||||
|
;; and we need to start a new one from this event.
|
||||||
|
(start-of-epoch-and-prev-end? event state)
|
||||||
|
(-> state
|
||||||
|
(update :partitions conj (conj current-match previous-event))
|
||||||
|
(assoc :current-match [event]))
|
||||||
|
|
||||||
|
(event-run? event)
|
||||||
|
(update state :current-match conj event)
|
||||||
|
|
||||||
|
|
||||||
:else
|
:else
|
||||||
state
|
state
|
||||||
;; Add a timeout/warning if a match goes on for more than a second?
|
;; Add a timeout/warning if a match goes on for more than a second?
|
||||||
|
|
||||||
)
|
)
|
||||||
(assoc :previous-event event))))
|
(assoc :previous-event event))))
|
||||||
{:current-match nil
|
parse-state
|
||||||
:previous-event nil
|
traces))
|
||||||
:partitions []}
|
|
||||||
traces)
|
|
||||||
matches (:partitions partitions)]
|
|
||||||
{:matches matches}))
|
|
||||||
|
|
||||||
(defn matched-event [match]
|
(defn matched-event [match]
|
||||||
(->> match
|
(->> match
|
||||||
|
Loading…
x
Reference in New Issue
Block a user