gnl/ghostwheel

Instrumentation?

Closed this issue · 7 comments

jmlsf commented

I cannot for the life of me actually get instrumentation to turn on.

I tried putting #:ghostwheel.core{:instrument true} in my namespace and I tried in the function itself:

(>defn gtest
  ^{:g/instrument true}
  [myint]
  [int? => any?]
  (print myint))

But if I pass a string I don't get an error. Am I missing something here?

gnl commented

Two things:

  • the metadata map passed to defn is a regular map (this isn't a Ghostwheel-specific thing) which is then attached to the symbol by defn
  • the keyword is :ghostwheel.core/instrument or ::g/instrument if you've aliased ghostwheel.core :as g

So you need to do either this:

(>defn gtest
  {::g/instrument true}

...or attach the metadata directly to the symbol:

(>defn ^::g/instrument gtest

EDIT:
The same rules apply when adding metadata to the namespace (except of course that you can't use aliased namespaces in the keywords, so you use namespaced maps instead)

jmlsf commented

Sorry I must be doing something dumb. I tried to isolate variables so it can be reproduced:

src/tst.core:

(ns tst.core
  (:require [ghostwheel.core :as g
             ;; `?` is an optional shortcut for `s/nilable`
             :refer-macros [>defn >defn- >fdef ?]
             ;; Optional - you can use `:ret`, `:st` and `:gen` instead.
             :refer [=> | <-]]))

(>defn gtest1
  {::g/instrument true}
  [myint]
  [int? => any?]
  (println myint))

(gtest1 "gtest1")

(>defn ^::g/instrument gtest2
  [myint]
  [int? => any?]
  (println myint))

(gtest2 "gtest2")

deps.edn:

{:deps {org.clojure/clojurescript {:mvn/version "1.10.238"}
        gnl/ghostwheel            {:mvn/version "0.2.1"}}}

command line & output:

$ clj --main cljs.main --compile tst.core --repl
gtest1
gtest2
ClojureScript 1.10.238
cljs.user=> 
gnl commented

Off the top of my head, it looks like you skipped step 3 of the getting started guide - set :ghostwheel true in your compiler options. Without that Ghostwheel is disabled on ClojureScript and doesn't do any code generation, it simply strips the gspec and returns a plain defn.

I haven't really had time to play around with deps.edn yet, but I assume that setting :compiler should be possible.

jmlsf commented

You're right. Unfortunately it still doesn't seem to be activated. I'll have to try again when I have more time.

clj --main cljs.main -co "{:ghostwheel true}" --compile tst.core --repl

gnl commented

Okay, now we're talking bug. :) Instrumentation only worked when ::g/check was enabled. The fix will be in the next release, but you can install the pre-release: [gnl/ghostwheel "0.2.2-SNAPSHOT"]

I haven't tested this with clj specifically, but it was perfectly reproducible with Shadow CLJS – let me know if this does the trick.

gnl commented

Closing this because the bug is fixed, but feel free to reopen if it's still not working for you for some reason.

jmlsf commented

Thanks! It works in 0.2.0-SNAPSHOT.