-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
stats.cljc
94 lines (83 loc) · 3.3 KB
/
stats.cljc
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
(ns com.wsscode.pathom3.connect.runner.stats
(:require
[com.fulcrologic.guardrails.core :refer [<- => >def >defn >fdef ? |]]
[com.wsscode.pathom3.attribute :as p.attr]
[com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.connect.planner :as pcp]
[com.wsscode.pathom3.connect.runner :as pcr]))
(>def ::node-error-id ::pcp/node-id)
(>def ::node-error-type #{::node-error-type-direct
::node-error-type-ancestor})
; region performance
(defn duration-resolver [attr]
(let [op-name (symbol (str (pbir/attr-munge attr) "-duration"))
start-kw (keyword (namespace attr) (str (name attr) "-start-ms"))
finish-kw (keyword (namespace attr) (str (name attr) "-finish-ms"))
duration-kw (keyword (namespace attr) (str (name attr) "-duration-ms"))]
(pco/resolver op-name
{::pco/input [start-kw finish-kw]
::pco/output [duration-kw]}
(fn [_ input]
{duration-kw (- (finish-kw input) (start-kw input))}))))
(pco/defresolver resolver-accumulated-duration
[{::pcr/keys [node-run-stats]} _]
{::resolver-accumulated-duration-ms
(transduce (map #(- (::pcr/resolver-run-finish-ms %)
(::pcr/resolver-run-start-ms %))) + 0 (vals node-run-stats))})
(pco/defresolver overhead-duration
[{::pcr/keys [graph-run-duration-ms]
::keys [resolver-accumulated-duration-ms]}]
{::overhead-duration-ms
(- graph-run-duration-ms resolver-accumulated-duration-ms)})
(pco/defresolver overhead-pct
[{::pcr/keys [graph-run-duration-ms]
::keys [overhead-duration-ms]}]
{::overhead-duration-percentage
(double (/ overhead-duration-ms graph-run-duration-ms))})
; endregion
(def stats-registry
[resolver-accumulated-duration
overhead-duration
overhead-pct
(pbir/alias-resolver ::pcr/compute-plan-run-start-ms ::pcr/process-run-start-ms)
(pbir/alias-resolver ::pcr/graph-run-finish-ms ::pcr/process-run-finish-ms)
(duration-resolver ::pcr/process-run)
(duration-resolver ::pcr/node-run)
(duration-resolver ::pcr/resolver-run)
(duration-resolver ::pcr/batch-run)
(duration-resolver ::pcr/graph-run)
(duration-resolver ::pcr/compute-plan-run)
(duration-resolver ::pcr/mutation-run)
(pbir/single-attr-with-env-resolver ::p.attr/attribute ::pcp/node-id
#(get (::pcp/index-attrs %) %2 ::pco/unknown-value))
(pbir/env-table-resolver ::pcp/nodes ::pcp/node-id
[::pco/op-name
::pcp/expects
::pcp/input
::pcp/run-and
::pcp/run-or
::pcp/run-next
::pcp/foreign-ast
::pcp/source-for-attrs
::pcp/node-parents])
(pbir/env-table-resolver ::pcr/node-run-stats ::pcp/node-id
[::pcr/resolver-run-start-ms
::pcr/resolver-run-finish-ms
::pcr/batch-run-start-ms
::pcr/batch-run-finish-ms
::pcp/nested-process
::pcr/node-run-start-ms
::pcr/node-run-finish-ms
::pcr/node-resolver-input
::pcr/node-resolver-input-shape
::pcr/node-resolver-output
::pcr/node-resolver-output-shape
::pcr/node-error
::pcr/taken-paths
::pcr/success-path])])
(def stats-index (pci/register stats-registry))
(defn run-stats-env [stats]
(-> stats
(pci/register stats-index)))