Sayid debug and profile tool

Sayid, pronounced "siy EED", is an extensive debug and profile tool for Clojure projects. To debug or profile code it must be able to compile or sayid will fail to work.

cider-debug - a simpler approach

cider-debug is simpler and quicker approach to debugging.

Sayid works by intercepting and recording the inputs and outputs of functions. It can even record function calls that occur inside of functions. The user can select which functions to trace. Functions can be selected individually or by namespace. The recorded data can be displayed, queried and profiled.

Sayid currently has three components:

  • core and its supporting namespaces
  • nREPL middleware
  • an emacs-cider nREPL client
Key Binding Description
SPC m d b instrument expression at point
SPC m d e display last stacktrace
SPC m d r reload namespaces
SPC m d v inspect expression at point

Configure Sayid

Sayid is an optional package in the Clojure layer for Spacemacs.

To enable sayid, add the following :variable to the clojure layer in .spacemacs

     (clojure :variables
              clojure-enable-sayid t)

Cider Jack-in

, m s cider-jack-in-clj to start the Clojure REPL via Cider jack-in, which should automatically include the Sayid nrepl middleware.

For a Leiningen project, sayid library should be added as a dev-dependency

For a Clojure CLI projects, include sayid library as an alias (e.g. :lib/sayid from practicalli/clojure-deps-edn)

{:lib/sayid {com.billpiel/sayid {:mvn/version "0.1.0"}}}

Cider Connect

Leiningen projects must include the Sayid plugin in order to use Cider Connect.

{:user {:plugins [[cider/cider-nrepl "0.25.3"]
                  [com.billpiel/sayid "0.1.0"]]
        :dependencies [[nrepl/nrepl "0.7.0"]]}}

Clojure CLI projects will need to explicitly include the middleware configuration in the same alias that configures nrepl, e.g.

  :repl/cider-debug
  {:extra-deps {nrepl/nrepl        {:mvn/version "0.9.0"}
                com.billpiel/sayid {:mvn/version "0.1.0"}
                cider/cider-nrepl  {:mvn/version "0.28.5"}}
   :main-opts  ["-m" "nrepl.cmdline"
                "--middleware" "[com.billpiel.sayid.nrepl-middleware/wrap-sayid,cider.nrepl/cider-middleware]"
                "--interactive"]}

If also using clj-refactor with Cider, then that nrepl middleware as well as sayid and cider will need to be included

  :repl/cider-refactor-debug
  {:extra-deps {nrepl/nrepl                   {:mvn/version "0.9.0"}
                com.billpiel/sayid            {:mvn/version "0.1.0"}
                cider/cider-nrepl             {:mvn/version "0.28.5"}
                refactor-nrepl/refactor-nrepl {:mvn/version "3.5.3"}}
   :main-opts  ["-m" "nrepl.cmdline"
                "--middleware" "[com.billpiel.sayid.nrepl-middleware/wrap-sayid,refactor-nrepl.middleware/wrap-refactor,cider.nrepl/cider-middleware]"
                "--interactive"]}

Now run the REPL process in a terminal with the following command

clojure -M:repl/cider-debug

Cider connect will only work if the sayid nrepl middleware is added to the aliases used to configure the nREPL middleware.

Learning Sayid

There is a noticeable learn curve to Sayid as it is quite comprehensive

results matching ""

    No results matching ""