-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
traces.cljs
181 lines (176 loc) · 11.8 KB
/
traces.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
(ns day8.re-frame-10x.view.traces
(:require [day8.re-frame-10x.view.components :as components]
[day8.re-frame-10x.utils.pretty-print-condensed :as pp]
[clojure.string :as str]
[day8.re-frame-10x.inlined-deps.reagent.v1v0v0.reagent.core :as r]
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf]
[day8.re-frame-10x.utils.re-com :as rc]
[day8.re-frame-10x.svgs :as svgs]
[day8.re-frame-10x.material :as material]))
(defn query->fn [query]
(if (= :contains (:filter-type query))
(fn [trace]
(str/includes? (str/lower-case (str (:operation trace) " " (:op-type trace)))
(:query query)))
(fn [trace]
(< (:query query) (:duration trace)))))
(defn add-filter [filter-items filter-input filter-type]
(rf/dispatch [:traces/add-filter filter-input filter-type]))
(defn render-traces [visible-traces filter-items filter-input trace-detail-expansions]
(let [debug? @(rf/subscribe [:settings/debug?])]
(doall
(->>
visible-traces
(map-indexed (fn [index {:keys [op-type id operation tags duration] :as trace}]
(let [show-row? (get-in @trace-detail-expansions [:overrides id]
(:show-all? @trace-detail-expansions))
op-name (if (vector? operation)
(second operation)
operation)
#_#__ (js/console.log (devtools/header-api-call tags))]
(list [:tr {:key id
:on-click #(rf/dispatch [:traces/toggle-trace id])
:class (str/join " " ["trace--trace"
(case op-type
:sub/create "trace--sub-create"
:sub/run "trace--sub-run"
:sub/dispose "trace--sub-run"
:event "trace--event"
:render "trace--render"
:re-frame.router/fsm-trigger "trace--fsm-trigger"
nil)])}
[:td.trace--toggle
[:button.expansion-button
(if show-row?
[material/arrow-drop-down :fill "#6EC0E6"]
[material/arrow-right :fill "#6EC0E6"])]]
[:td.trace--op
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-type) :contains)
(.stopPropagation ev))}
(str op-type)]]
[:td.trace--op-string
[:span.op-string {:on-click (fn [ev]
(add-filter filter-items (name op-name) :contains)
(.stopPropagation ev))}
(pp/truncate 20 :middle (pp/str->namespaced-sym op-name)) " "
[:span
{:style {:opacity 0.5
:display "inline-block"}}
(when-let [[_ & params] (or (get tags :query-v)
(get tags :event))]
(->> (map pp/pretty-condensed params)
(str/join ", ")
(pp/truncate-string :middle 40)))]]]
(if debug?
[:td.trace--meta
(:reaction (:tags trace)) "/" id]
[:td.trace--meta
(.toFixed duration 1) " ms"])]
(when show-row?
[:tr.trace--details {:key (str id "-details")
:tab-index 0}
[:td]
[:td.trace--details-tags {:col-span 2
:on-click #(.log js/console trace)}
[:div.trace--details-tags-text
(let [tag-str (prn-str tags)]
(str (subs tag-str 0 400)
(when (< 400 (count tag-str))
" ...")))]]
[:td.trace--meta.trace--details-icon
{:on-click #(.log js/console tags)}]])))))))))
(defn render []
(let [filter-input (r/atom "")
filter-items (rf/subscribe [:traces/filter-items])
filter-type (r/atom :contains)
input-error (r/atom false)
categories (rf/subscribe [:traces/categories])
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/all-visible-traces])
current-traces (rf/subscribe [:traces/current-event-visible-traces])
show-epoch-traces? (rf/subscribe [:trace-panel/show-epoch-traces?])]
(fn []
(let [toggle-category-fn #(rf/dispatch [:traces/toggle-categories %])
traces-to-filter (if @show-epoch-traces?
@current-traces
@traces)
visible-traces (cond->> traces-to-filter
;; Remove cached subscriptions. Could add this back in as a setting later
;; but it's pretty low signal/noise 99% of the time.
true (remove (fn [trace] (and (= :sub/create (:op-type trace))
(get-in trace [:tags :cached?]))))
(seq @categories) (filter (fn [trace] (when (contains? @categories (:op-type trace)) trace)))
(seq @filter-items) (filter (apply every-pred (map query->fn @filter-items)))
true (sort-by :id))
save-query (fn [_]
(if (and (= @filter-type :slower-than)
(js/isNaN (js/parseFloat @filter-input)))
(reset! input-error true)
(do
(reset! input-error false)
(add-filter filter-items @filter-input @filter-type))))]
[rc/v-box
:class "tab-contents"
:size "1"
:children [[rc/v-box
:class "filter"
:children [[:div.filter-control
[:ul.filter-categories "show: "
[:li.filter-category {:class (when (contains? @categories :event) "active")
:on-click #(rf/dispatch [:traces/toggle-categories #{:event}])}
"events"]
[:li.filter-category {:class (when (contains? @categories :sub/run) "active")
:on-click #(rf/dispatch [:traces/toggle-categories #{:sub/run :sub/create :sub/dispose}])}
"subscriptions"]
[:li.filter-category {:class (when (contains? @categories :render) "active")
:on-click #(rf/dispatch [:traces/toggle-categories #{:render}])}
"reagent"]
[:li.filter-category {:class (when (contains? @categories :re-frame.router/fsm-trigger) "active")
:on-click #(rf/dispatch [:traces/toggle-categories #{:re-frame.router/fsm-trigger :componentWillUnmount}])}
"internals"]]
[rc/checkbox
:model show-epoch-traces?
:on-change #(rf/dispatch [:trace-panel/update-show-epoch-traces? %])
:label "Only show traces for this epoch?"]
[:div.filter-fields
[:select {:value @filter-type
:on-change #(reset! filter-type (keyword (.. % -target -value)))}
[:option {:value "contains"} "contains"]
[:option {:value "slower-than"} "slower than"]]
[:div.filter-control-input {:style {:margin-left 10}}
[components/search-input {:on-save save-query
:on-change #(reset! filter-input (.. % -target -value))
:placeholder "Type to filter traces"}]
(if @input-error
[:div.input-error {:style {:color "red" :margin-top 5}}
"Please enter a valid number."])]]]
[:ul.filter-items
(map (fn [item]
^{:key (:id item)}
[:li.filter-item
[:button.button
{:style {:margin 0}
:on-click #(rf/dispatch [:traces/remove-filter (:id item)])}
(:filter-type item) ": " [:span.filter-item-string (:query item)]]])
@filter-items)]]]
[rc/box
:size "1"
:style {:padding-top "20px"
:margin "0px 10px"
:overflow "auto"}
:child [:table
[:thead>tr
[:th {:style {:padding 0}}
[:button.text-button
{:style {:cursor "pointer"}
:on-click #(rf/dispatch [:traces/toggle-all-expansions])}
(if (:show-all? @trace-detail-expansions) "-" "+")]]
[:th "operations"]
[:th
(str (count visible-traces) " traces")
[:span "(" [:button.text-button {:on-click #(rf/dispatch [:epochs/reset])} "clear"] ")"]]
[:th {:style {:text-align "right"}} "meta"]]
[:tbody (render-traces visible-traces filter-items filter-input trace-detail-expansions)]]]]]))))