Add setting to drop low level traces from being stored

This commit is contained in:
Daniel Compton 2018-01-28 11:41:37 +13:00
parent 70cefc4022
commit 39f038f8d5
5 changed files with 32 additions and 6 deletions

View File

@ -6,10 +6,12 @@ All notable changes to this project will be documented in this file. This change
### Added ### Added
* Debugging instructions if re-frame-trace fails to start. * Debugging instructions if re-frame-trace fails to start.
* Setting to drop low level traces. This reduces the memory overhead of re-frame-trace as we can drop more traces that you are unlikely to want most of the time.
### Changed ### Changed
* The version of Garden that re-frame-trace uses is now bundled as a source dependency so you should no longer get conflicts. * The version of Garden that re-frame-trace uses is now bundled as a source dependency so you should no longer get conflicts if you use Garden 2.
* Refactored re-frame-trace trace parsing internals to incrementally parse new traces.
### Fixed ### Fixed

View File

@ -12,6 +12,7 @@
external-window? (localstorage/get "external-window?" false) external-window? (localstorage/get "external-window?" false)
using-trace? (localstorage/get "using-trace?" true) using-trace? (localstorage/get "using-trace?" true)
ignored-events (localstorage/get "ignored-events" {}) ignored-events (localstorage/get "ignored-events" {})
low-level-trace (localstorage/get "low-level-trace" {:reagent true :re-frame true})
filtered-view-trace (localstorage/get "filtered-view-trace" (let [id1 (random-uuid) filtered-view-trace (localstorage/get "filtered-view-trace" (let [id1 (random-uuid)
id2 (random-uuid)] id2 (random-uuid)]
{id1 {:id id1 :ns-str "re-com.box" :ns 're-com.box :sort 0} {id1 {:id id1 :ns-str "re-com.box" :ns 're-com.box :sort 0}
@ -25,6 +26,7 @@
(rf/dispatch [:settings/selected-tab selected-tab]) (rf/dispatch [:settings/selected-tab selected-tab])
(rf/dispatch [:settings/set-ignored-events ignored-events]) (rf/dispatch [:settings/set-ignored-events ignored-events])
(rf/dispatch [:settings/set-filtered-view-trace filtered-view-trace]) (rf/dispatch [:settings/set-filtered-view-trace filtered-view-trace])
(rf/dispatch [:settings/set-low-level-trace low-level-trace])
(rf/dispatch [:settings/set-number-of-retained-epochs num-epochs]) (rf/dispatch [:settings/set-number-of-retained-epochs num-epochs])
(when external-window? (when external-window?
(rf/dispatch [:global/launch-external])) (rf/dispatch [:global/launch-external]))

View File

@ -185,9 +185,17 @@
(fn [_ [_ ignored-events]] (fn [_ [_ ignored-events]]
ignored-events)) ignored-events))
(def low-level-trace-mw [(rf/path [:settings :low-level-trace]) (rf/after #(localstorage/save! "low-level-trace" %))])
(rf/reg-event-db
:settings/set-low-level-trace
low-level-trace-mw
(fn [_ [_ low-level]]
low-level))
(rf/reg-event-db (rf/reg-event-db
:settings/low-level-trace :settings/low-level-trace
[(rf/path [:settings :low-level-trace])] low-level-trace-mw
(fn [low-level [_ trace-type capture?]] (fn [low-level [_ trace-type capture?]]
(assoc low-level trace-type capture?))) (assoc low-level trace-type capture?)))
@ -491,6 +499,7 @@
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] [])
parse-state (get-in db [:epochs :parse-state] metam/initial-parse-state) parse-state (get-in db [:epochs :parse-state] metam/initial-parse-state)
{drop-re-frame :re-frame drop-reagent :reagent} (get-in db [:settings :low-level-trace])
all-traces (reduce conj previous-traces filtered-traces) all-traces (reduce conj previous-traces filtered-traces)
parse-state (metam/parse-traces parse-state filtered-traces) parse-state (metam/parse-traces parse-state filtered-traces)
new-matches (:partitions parse-state) new-matches (:partitions parse-state)
@ -502,7 +511,9 @@
all-matches (reduce conj previous-matches new-matches) all-matches (reduce conj previous-matches new-matches)
retained-matches (into [] (take-last number-of-epochs-to-retain all-matches)) retained-matches (into [] (take-last number-of-epochs-to-retain all-matches))
first-id-to-retain (:id (ffirst retained-matches)) first-id-to-retain (:id (ffirst retained-matches))
retained-traces (into [] (drop-while #(< (:id %) first-id-to-retain)) all-traces)] retained-traces (into [] (comp (drop-while #(< (:id %) first-id-to-retain))
(remove (fn [trace] (or (when drop-reagent (metam/low-level-reagent-trace? trace))
(when drop-re-frame (metam/low-level-re-frame-trace? trace)))))) all-traces)]
(-> db (-> db
(assoc-in [:traces :all-traces] retained-traces) (assoc-in [:traces :all-traces] retained-traces)
(update :epochs (fn [epochs] (update :epochs (fn [epochs]

View File

@ -142,6 +142,18 @@
(defn subscription-not-run? [trace] (defn subscription-not-run? [trace]
false) false)
(defn low-level-re-frame-trace?
"Is this part of re-frame internals?"
[trace]
(case (:op-type trace)
(:re-frame.router/fsm-trigger) true
false))
(defn low-level-reagent-trace?
"Is this part of reagent internals?"
[trace]
(= :componentWillUnmount (:op-type trace)))
(defn render? [trace] (defn render? [trace]
(= :render (:op-type trace))) (= :render (:op-type trace)))

View File

@ -149,9 +149,8 @@
[:p "Nominate one or more namespaces."]] [:p "Nominate one or more namespaces."]]
settings-box-131] settings-box-131]
;; TODO: remove low level trace [rc/line]
#_[rc/line] (let [low-level-trace @(rf/subscribe [:settings/low-level-trace])]
#_(let [low-level-trace @(rf/subscribe [:settings/low-level-trace])]
[settings-box [settings-box
[[rc/label :label "Remove low level trace"] [[rc/label :label "Remove low level trace"]
[rc/checkbox [rc/checkbox