Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instrument's new option for adding :depth to execution logs #6

Merged
merged 3 commits into from
Jan 29, 2020

Conversation

athos
Copy link
Owner

@athos athos commented Jan 28, 2020

It would sometimes be useful if each log item in instrument's execution logs had an additional key that indicates their nesting level (depth) of function calls at invocation time, especially when debugging a recursive function.

This PR adds another option {:with-depth true} for optionally adding such a key to each log item in the execution logs, like the following:

(require '[postmortem.core :as pm]
         '[postmortem.instrument :as pi])

(defn fact [n]
  (if (= n 0)
    1
    (* n (fact (dec n)))))

;; without :with-depth option
(pi/instrument `fact)
(fact 5) ;=> 120
(pm/log-for `fact)
;=> [{:args (5)}
;    {:args (4)}
;    {:args (3)}
;    {:args (2)}
;    {:args (1)}
;    {:args (0)}
;    {:args (0), :ret 1}
;    {:args (1), :ret 1}
;    {:args (2), :ret 2}
;    {:args (3), :ret 6}
;    {:args (4), :ret 24}
;    {:args (5), :ret 120}]

(pm/reset!)

;; with :with-depth option
(pi/instrument `fact {:with-depth true})
(fact 5) ;=> 120
(pm/log-for `fact)
;=> [{:args (5), :depth 1}
;    {:args (4), :depth 2}
;    {:args (3), :depth 3}
;    {:args (2), :depth 4}
;    {:args (1), :depth 5}
;    {:args (0), :depth 6}
;    {:args (0), :ret 1, :depth 6}
;    {:args (1), :ret 1, :depth 5}
;    {:args (2), :ret 2, :depth 4}
;    {:args (3), :ret 6, :depth 3}
;    {:args (4), :ret 24, :depth 2}
;    {:args (5), :ret 120, :depth 1}]

@athos athos force-pushed the feature/optional-depth-field branch from 5979cbb to f9809ac Compare January 28, 2020 12:52
@codecov
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #6 into master will increase coverage by 0.26%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #6      +/-   ##
==========================================
+ Coverage   91.71%   91.97%   +0.26%     
==========================================
  Files           7        7              
  Lines         338      349      +11     
  Branches       17       17              
==========================================
+ Hits          310      321      +11     
  Misses         11       11              
  Partials       17       17
Impacted Files Coverage Δ
src/postmortem/instrument/core.cljc 97.72% <100%> (+0.75%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb75a30...f9809ac. Read the comment docs.

@athos athos merged commit 930ac12 into master Jan 29, 2020
@athos athos deleted the feature/optional-depth-field branch January 29, 2020 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant