Skip to content

Commit

Permalink
Added an optional call-site id as an arg to spy and brk
Browse files Browse the repository at this point in the history
  • Loading branch information
npetryk committed Mar 3, 2019
1 parent b6026b2 commit 832cb1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/sc/api.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@

(defn last-ep-id
"Returns the id of the last saved Execution Point, in [ep-id cs-id] form.
An optional call-site id can be given to constrain the output
Throws an Exception if no Execution Point has been saved."
[]
(i/last-ep-id))
([]
(i/last-ep-id))
([cs-id]
(i/last-ep-id cs-id)))

(defn ep-info
"Given an Execution Point Id,
Expand Down
27 changes: 18 additions & 9 deletions src/sc/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
(swap! db/ep-id inc))

(defn last-ep-id*
[db]
(let [eps (get db :execution-points)]
[db cs-id]
(let [get-cs-id #(-> % :sc.ep/code-site :sc.cs/id)
eps (cond->> (get db :execution-points)
cs-id (filter (comp #{cs-id} get-cs-id second)))]
(if (empty? eps)
(throw (ex-info
"No Execution Point has been saved yet."
(if cs-id
"No Execution Point for Call Site has been saved yet."
"No Execution Point has been saved yet.")
{:sc.api.error/error-type
:sc.api.error-types/no-ep-saved-yet}))
:sc.api.error-types/no-ep-saved-yet
:sc.cs/id cs-id}))
(let [[epid ep-v] (apply max-key first eps)]
[epid (-> ep-v :sc.ep/code-site :sc.cs/id)]))))
[epid (get-cs-id ep-v)]))))

(defn last-ep-id
[]
(last-ep-id* @db/db))
([]
(last-ep-id* @db/db nil))
([cs-id]
(last-ep-id* @db/db cs-id)))

(defn valid-ep-identifier?
[v]
Expand Down Expand Up @@ -209,11 +216,12 @@
spy-pre-eval-logger :sc/spy-ep-pre-eval-logger
spy-post-eval-logger :sc/spy-ep-post-eval-logger
only-from :sc/called-from
cs-id :sc.cs/id
:or {cs-logger-id :sc.api.logging/log-spy-cs
spy-pre-eval-logger `sc.api.logging/log-spy-ep-pre-eval
spy-post-eval-logger `sc.api.logging/log-spy-ep-post-eval
}} opts
cs-id (gen-cs-id)
cs-id (or cs-id (gen-cs-id))
cs-data (make-cs-data opts cs-id expr amp-env amp-form)]
(save-cs cs-data)
(il/log-cs cs-logger-id cs-data)
Expand Down Expand Up @@ -257,11 +265,12 @@
brk-pre-eval-logger :sc/brk-ep-pre-eval-logger
brk-post-eval-logger :sc/brk-ep-post-eval-logger
only-from :sc/called-from
cs-id :sc.cs/id
:or {cs-logger-id :sc.api.logging/log-brk-cs
brk-pre-eval-logger `sc.api.logging/log-brk-ep-pre-eval
brk-post-eval-logger `sc.api.logging/log-brk-ep-post-eval
}} opts
cs-id (gen-cs-id)
cs-id (or cs-id (gen-cs-id))
cs-data (make-cs-data opts cs-id expr amp-env amp-form)]
(save-cs cs-data)
(il/log-cs cs-logger-id cs-data)
Expand Down

0 comments on commit 832cb1c

Please sign in to comment.