Comments (2)
Hi @Futurile, Thank you for giving a try to the library! And thanks for your feedback, too. 😉
I think it's hardly possible for instrument
to programmatically determine where the call to dump
should be inserted into because a function may have several different local contexts and they can even be nested. For instance, every call to dump
occurring in the example code below will all save different log data:
(defn f [x]
(pm/dump :f) ;; saves {:x 0} when you call f with 0
(let [x 10]
(pm/dump :f) ;; saves {:x 10}
(let [x 20]
(pm/dump :f))) ;; saves {:x 20}
(let [x 30]
(pm/dump :f))) ;; saves {:x 30}
And moreover, instrument
doesn't even have access to the code of a function, so it can't insert any code into the middle of the function code. After all, I would say it has to be considered as the user's responsibility to determine where the calls to dump
should be inserted into.
As an alternative solution (though I think it's not a good one), how about naming the log entry key same as the name of the function that you want to instrument
? If you do so, you can collect logs both for dump
and instrument
into a single log entry:
(defn f [x y]
(let [x2 (* x x) y2 (* y y)]
(pm/dump `f)
(Math/sqrt (+ x2 y2))))
(pi/instrument `f {:xform (map (fn [m] (if (:args m) m {:locals m})))})
(f 3 4) ;=> 5
(pm/log-for `f)
;=> [{:args (3 4)} {:locals {:x 3, :y 4, :x2 9, :y2 16}} {:args (3 4), :ret 5.0}]
from postmortem.
Thanks for the explanation @athos
I am probably unclear (or poorly understand) how instrument works. I thought it "somehow" changed execution of the function, so that it was placing a spy>>
right at the start of the function and also right at the end.
"the execution log for an instrumented function consists of two types of log items, ones for entry and ones for exit"
Consequently, I imagined that what I was asking was that instrument would enable the dump right at the start and end of the function. So from your example:
(defn f [x]
(pm/dump :f) ;; saves {:x 0} when you call f with 0
(let [x 10]
(let [x 20]
(let [x 30]
(pm/dump :f))) ;; saves {:x 30}
I see what you are saying - I wouldn't see the specific values being used if there's another let
later on as your example showed. In particular, any let's at the start of the function wouldn't be shown which I guess is pretty common.
I am using it as a learning tool, to play with simple function, so hadn't really thought about more complex use-cases.
from postmortem.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postmortem.