Giter Site home page Giter Site logo

Comments (3)

vvvvalvalval avatar vvvvalvalval commented on June 6, 2024 1

Hello, I would not encourage you to use with-redefs for that (or anything), but have you read the customization section from the docs? It's really meant for this sort of use case. You can also pass the inline :sc/spy-ep-pre-eval-logger-fn and :sc/spy-ep-post-eval-logger-fn opts.

When I want to catch on Exceptions only, I usually do it by wrapping the exception in a try/catch and spying inside the catch clause.

Other options are:

  1. using a brk, then exiting with an error
  2. spying at random: (when (zero? (rand-int 100)) (sc.api/spy))

People have very different opinions regarding such workflow optimizations; this is why I recommend writing your own spy... wrappers in your project's utility namespace.

from scope-capture.

yuhan0 avatar yuhan0 commented on June 6, 2024

Update: I traced the source of the logging and tried redefining these functions with no-ops:

  • sc.api.logging/log-spy-ep-pre-eval
  • sc.api.logging/log-spy-ep-post-eval

That alone reduced the execution time to 51ms, so it turned out the huge majority of the overhead was due to all the println logging.

There doesn't look to be a simple way of switching this logging behaviour off - perhaps a dynamic var of some sort like sc.api/*log-spy-execution* or a separate spying macro?
Here's what I'm using for the time being:

(defmacro spy' [& args]
  `(with-redefs [sc.api.logging/log-spy-ep-pre-eval (fn [~'ep])
                 sc.api.logging/log-spy-ep-post-eval (fn [~'ep])]
     (sc/spy ~@args)))

Let me know and I'd be willing to contribute a PR :)

from scope-capture.

yuhan0 avatar yuhan0 commented on June 6, 2024

Thanks for all the pointers! That's what I get for digging through the source but not the documentation 😅
Being able to conditionally (spy) anywhere is pretty nice, I had the wrong impression that it had to always be wrapped around an expression.

Here's my modified macro from above, for anyone interested:

(def spysl-opts
  {:sc/spy-ep-post-eval-logger (fn [ep])
   :sc/spy-ep-pre-eval-logger (fn [ep])})

(defmacro spysl
  "Spy silently - do not print anything at execution points."
  ([] (sc.api/spy-emit spysl-opts nil &env &form))
  ([expr] (sc.api/spy-emit spysl-opts expr &env &form))
  ([opts expr] (sc.api/spy-emit (merge spysl-opts opts) expr &env &form)))

from scope-capture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.