mirror of
https://github.com/status-im/re-frame-10x.git
synced 2025-03-03 15:10:32 +00:00
Only show traces for the current epoch
This commit is contained in:
parent
b324d62c4e
commit
ac19e04572
@ -8,7 +8,8 @@
|
||||
[re-frame.db]
|
||||
[day8.re-frame.trace.view.container :as container]
|
||||
[day8.re-frame.trace.styles :as styles]
|
||||
[clojure.set :as set]))
|
||||
[clojure.set :as set]
|
||||
[day8.re-frame.trace.metamorphic :as metam]))
|
||||
|
||||
(defonce traces (r/atom []))
|
||||
(defonce total-traces (r/atom 0))
|
||||
@ -26,18 +27,21 @@
|
||||
|
||||
(defn enable-tracing! []
|
||||
(re-frame.trace/register-trace-cb ::cb (fn [new-traces]
|
||||
(when-let [new-traces (filter log-trace? new-traces)]
|
||||
(when-let [new-traces (->> (filter log-trace? new-traces)
|
||||
(sort-by :id))]
|
||||
(swap! total-traces + (count new-traces))
|
||||
(swap! traces
|
||||
(fn [existing]
|
||||
(let [new (reduce conj existing new-traces)
|
||||
size (count new)]
|
||||
(if (< 4000 size)
|
||||
(let [new2 (subvec new (- size 2000))]
|
||||
(if (< @total-traces 20000) ;; Create a new vector to avoid structurally sharing all traces forever
|
||||
(if (< 8000 size)
|
||||
(let [new2 (subvec new (- size 4000))]
|
||||
(if (< @total-traces 40000) ;; Create a new vector to avoid structurally sharing all traces forever
|
||||
(do (reset! total-traces 0)
|
||||
(into [] new2))))
|
||||
new))))))))
|
||||
new))))
|
||||
(rf/dispatch [:traces/update-traces @traces])
|
||||
(rf/dispatch [:epochs/update-epochs (metam/parse-traces @traces)])))))
|
||||
|
||||
(defn dissoc-in
|
||||
"Dissociates an entry from a nested associative structure returning a new
|
||||
@ -318,3 +322,29 @@
|
||||
(fn [snapshot _]
|
||||
(reset! re-frame.db/app-db (:current-snapshot snapshot))
|
||||
snapshot))
|
||||
|
||||
;;;
|
||||
|
||||
(rf/reg-event-db
|
||||
:epochs/update-epochs
|
||||
[(rf/path [:epochs :matches])]
|
||||
(fn [matches [_ rt]]
|
||||
(:matches rt)))
|
||||
|
||||
(rf/reg-event-db
|
||||
:epochs/previous-epoch
|
||||
[(rf/path [:epochs :current-epoch-index])]
|
||||
(fn [index _]
|
||||
((fnil dec 0) index)))
|
||||
|
||||
(rf/reg-event-db
|
||||
:epochs/next-epoch
|
||||
[(rf/path [:epochs :current-epoch-index])]
|
||||
(fn [index _]
|
||||
((fnil inc 0) index)))
|
||||
|
||||
(rf/reg-event-db
|
||||
:traces/update-traces
|
||||
[(rf/path [:traces :all-traces])]
|
||||
(fn [_ [_ traces]]
|
||||
traces))
|
||||
|
@ -1,7 +1,8 @@
|
||||
(ns day8.re-frame.trace.metamorphic
|
||||
(:require [metamorphic.api :as m]
|
||||
[metamorphic.runtime :as rt]
|
||||
[metamorphic.viz :as v]))
|
||||
#?(:clj
|
||||
[metamorphic.viz :as v])))
|
||||
|
||||
;; Next, we define predicate functions that take exactly 4 arguments.
|
||||
;; These predicates are obviously incredibly boring, but they help
|
||||
@ -65,12 +66,17 @@
|
||||
(= :running (get-in event [:tags :current-state]))
|
||||
(= :idle (get-in event [:tags :new-state]))))
|
||||
|
||||
(defn request-animation-frame? [event history pattern-sequence pattern]
|
||||
(= :raf (:op-type event)))
|
||||
|
||||
(defn trace-events [] (->> (slurp "test-resources/events2.edn")
|
||||
(clojure.edn/read-string {:readers {'utc identity
|
||||
'object (fn [x] "<object>")}})
|
||||
(sort-by :id))
|
||||
)
|
||||
(defn request-animation-frame-end? [event history pattern-sequence pattern]
|
||||
(= :raf-end (:op-type event)))
|
||||
|
||||
|
||||
#?(:clj (defn trace-events [] (->> (slurp "test-resources/events2.edn")
|
||||
(clojure.edn/read-string {:readers {'utc identity
|
||||
'object (fn [x] "<object>")}})
|
||||
(sort-by :id))))
|
||||
|
||||
|
||||
(defn summarise-event [ev]
|
||||
@ -79,17 +85,37 @@
|
||||
(defn summarise-match [match]
|
||||
(map summarise-event match))
|
||||
|
||||
(defn parse-events []
|
||||
#?(:clj
|
||||
(defn parse-events []
|
||||
#_ (let [runtime (-> (m/new-pattern-sequence "simple traces")
|
||||
(m/begin "new-epoch-started" new-epoch-started?)
|
||||
#_(m/followed-by "redispatched-event" redispatched-event? {:optional? true})
|
||||
#_(m/followed-by "router-scheduled" router-scheduled? {:optional? true})
|
||||
(m/followed-by "event-run" event-run?)
|
||||
(m/followed-by "router-finished" router-finished?)
|
||||
(m/followed-by "raf" request-animation-frame?)
|
||||
(m/followed-by "raf-end" request-animation-frame-end?)
|
||||
(rt/initialize-runtime))
|
||||
events (trace-events)
|
||||
rt (reduce rt/evaluate-event runtime events)]
|
||||
#_(println "Count"
|
||||
(count (:matches rt))
|
||||
(map count (:matches rt)))
|
||||
(map summarise-match (:matches rt)))))
|
||||
|
||||
(defn parse-traces
|
||||
"Returns a metamorphic runtime"
|
||||
[traces]
|
||||
(let [runtime (-> (m/new-pattern-sequence "simple traces")
|
||||
(m/begin "new-epoch-started" new-epoch-started?)
|
||||
#_(m/followed-by "redispatched-event" redispatched-event? {:optional? true})
|
||||
#_ (m/followed-by "router-scheduled" router-scheduled? {:optional? true})
|
||||
(m/followed-by "event-run" event-run?)
|
||||
(m/followed-by "router-finished" router-finished?)
|
||||
(m/followed-by "raf" request-animation-frame?)
|
||||
(m/followed-by "raf-end" request-animation-frame-end?)
|
||||
(rt/initialize-runtime))
|
||||
events (trace-events)
|
||||
rt (reduce rt/evaluate-event runtime events)]
|
||||
rt (reduce rt/evaluate-event runtime traces)]
|
||||
#_(println "Count"
|
||||
(count (:matches rt))
|
||||
(map count (:matches rt)))
|
||||
(map summarise-match (:matches rt))))
|
||||
(count (:matches rt))
|
||||
(map count (:matches rt)))
|
||||
#_(map summarise-match (:matches rt))
|
||||
rt))
|
@ -59,6 +59,11 @@
|
||||
|
||||
;;
|
||||
|
||||
(rf/reg-sub
|
||||
:traces/trace-root
|
||||
(fn [db _]
|
||||
(:traces db)))
|
||||
|
||||
(rf/reg-sub
|
||||
:traces/filter-items
|
||||
(fn [db _]
|
||||
@ -74,6 +79,29 @@
|
||||
(fn [db _]
|
||||
(get-in db [:traces :categories])))
|
||||
|
||||
(rf/reg-sub
|
||||
:traces/all-traces
|
||||
:<- [:traces/trace-root]
|
||||
(fn [traces _]
|
||||
(:all-traces traces)))
|
||||
|
||||
(rf/reg-sub
|
||||
:traces/number-of-traces
|
||||
:<- [:traces/trace-root]
|
||||
(fn [traces _]
|
||||
(count traces)))
|
||||
|
||||
(rf/reg-sub
|
||||
:traces/current-event-traces
|
||||
:<- [:traces/all-traces]
|
||||
:<- [:epochs/beginning-trace-id]
|
||||
:<- [:epochs/ending-trace-id]
|
||||
(fn [[traces beginning ending] _]
|
||||
(filter #(<= beginning (:id %) ending) traces)
|
||||
#_traces))
|
||||
|
||||
;;
|
||||
|
||||
(rf/reg-sub
|
||||
:global/unloading?
|
||||
(fn [db _]
|
||||
@ -91,3 +119,56 @@
|
||||
:<- [:snapshot/snapshot-root]
|
||||
(fn [snapshot _]
|
||||
(contains? snapshot :current-snapshot)))
|
||||
|
||||
;;
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/epoch-root
|
||||
(fn [db _]
|
||||
(:epochs db)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/current-event
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs _]
|
||||
(let [matches (:matches epochs)
|
||||
current-index (:current-epoch-index epochs)
|
||||
match (nth matches (+ (count matches) (or current-index 0)) (last matches))
|
||||
event (get-in (second match) [:tags :event])]
|
||||
event)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/number-of-matches
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs _]
|
||||
(count (get epochs :matches))))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/current-event-index
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs _]
|
||||
(:current-epoch-index epochs)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/event-position
|
||||
:<- [:epochs/current-event-index]
|
||||
:<- [:epochs/number-of-matches]
|
||||
(fn [[current total]]
|
||||
(str current " of " total)))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/beginning-trace-id
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs]
|
||||
;; TODO: make it use the real match
|
||||
(let [match (last (:matches epochs))]
|
||||
(:id (first match)))))
|
||||
|
||||
(rf/reg-sub
|
||||
:epochs/ending-trace-id
|
||||
:<- [:epochs/epoch-root]
|
||||
(fn [epochs]
|
||||
;; TODO: make it use the real match
|
||||
(let [match (last (:matches epochs))]
|
||||
(:id (last match)))))
|
||||
|
||||
|
@ -66,19 +66,20 @@
|
||||
[right-hand-buttons external-window?]])
|
||||
|
||||
(defn standard-header [external-window?]
|
||||
[[rc/h-box
|
||||
:align :center
|
||||
:size "auto"
|
||||
:gap common/gs-12s
|
||||
:children
|
||||
[[:span.arrow "◀"]
|
||||
[rc/v-box
|
||||
(let [current-event @(rf/subscribe [:epochs/current-event])]
|
||||
[[rc/h-box
|
||||
:align :center
|
||||
:size "auto"
|
||||
:children [[:span.event-header "[:some-namespace/blah 34 \"Hello\""]]]
|
||||
[:span.arrow "▶"]]]
|
||||
[rc/gap-f :size common/gs-12s]
|
||||
[rc/line :size "2px" :color common/sidebar-heading-divider-color]
|
||||
[right-hand-buttons external-window?]]
|
||||
:gap common/gs-12s
|
||||
:children
|
||||
[[:span.arrow {:on-click #(rf/dispatch [:epochs/previous-epoch])} "◀"]
|
||||
[rc/v-box
|
||||
:size "auto"
|
||||
:children [[:span.event-header (prn-str current-event)]]]
|
||||
[:span.arrow {:on-click #(rf/dispatch [:epochs/next-epoch])} "▶"]]]
|
||||
[rc/gap-f :size common/gs-12s]
|
||||
[rc/line :size "2px" :color common/sidebar-heading-divider-color]
|
||||
[right-hand-buttons external-window?]])
|
||||
)
|
||||
|
||||
(defn devtools-inner [traces opts]
|
||||
@ -125,7 +126,7 @@
|
||||
:style {:margin-left common/gs-19s}
|
||||
:children
|
||||
[(case @selected-tab
|
||||
:overview [overview/render]
|
||||
:overview [overview/render traces]
|
||||
:app-db [app-db/render-state db/app-db]
|
||||
:subs [subs/subs-panel]
|
||||
:views [views/render]
|
||||
|
@ -1,7 +1,8 @@
|
||||
(ns day8.re-frame.trace.view.overview
|
||||
(:require [day8.re-frame.trace.utils.re-com :as rc]))
|
||||
(:require [day8.re-frame.trace.utils.re-com :as rc]
|
||||
[day8.re-frame.trace.metamorphic :as metam]))
|
||||
|
||||
(defn render []
|
||||
(defn render [traces]
|
||||
[rc/v-box
|
||||
:children
|
||||
[[rc/label :label "Event"]
|
||||
|
@ -23,10 +23,12 @@
|
||||
:style {:padding-top common/gs-31s}
|
||||
:gap common/gs-19s
|
||||
:children
|
||||
[[settings-box
|
||||
[[rc/label :label "Retain last 10 epochs"]
|
||||
[:button "Clear All Epochs"]]
|
||||
[[:p "8 epochs currently retained, involving 10,425 traces."]]]
|
||||
[(let [num-epochs @(rf/subscribe [:epochs/number-of-matches])
|
||||
num-traces @(rf/subscribe [:traces/number-of-traces])]
|
||||
[settings-box
|
||||
[[rc/label :label "Retain last 10 epochs"]
|
||||
[:button "Clear All Epochs"]]
|
||||
[[:p num-epochs " epochs currently retained, involving " num-traces " traces."]]])
|
||||
|
||||
[rc/line]
|
||||
|
||||
|
@ -64,7 +64,8 @@
|
||||
(str/join ", ")
|
||||
(pp/truncate-string :middle 40)))]]]
|
||||
[:td.trace--meta
|
||||
(.toFixed duration 1) " ms"]]
|
||||
id
|
||||
#_ #_(.toFixed duration 1) " ms"]]
|
||||
(when show-row?
|
||||
[:tr.trace--details {:key (str id "-details")
|
||||
:tab-index 0}
|
||||
@ -86,7 +87,10 @@
|
||||
filter-type (r/atom :contains)
|
||||
input-error (r/atom false)
|
||||
categories (rf/subscribe [:traces/categories])
|
||||
trace-detail-expansions (rf/subscribe [:traces/expansions])]
|
||||
trace-detail-expansions (rf/subscribe [:traces/expansions])
|
||||
beginning (rf/subscribe [:epochs/beginning-trace-id])
|
||||
end (rf/subscribe [:epochs/ending-trace-id])
|
||||
traces (rf/subscribe [:traces/current-event-traces])]
|
||||
(fn []
|
||||
(let [toggle-category-fn #(rf/dispatch [:traces/toggle-categories %])
|
||||
visible-traces (cond->> @traces
|
||||
@ -141,6 +145,7 @@
|
||||
:on-click #(rf/dispatch [:traces/remove-filter (:id item)])}
|
||||
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
|
||||
@filter-items)]]
|
||||
[:pre @beginning " to " @end]
|
||||
[components/autoscroll-list {:class "panel-content-scrollable" :scroll? true}
|
||||
[:table
|
||||
[:thead>tr
|
||||
|
Loading…
x
Reference in New Issue
Block a user