Skip to content

[profile] Migrate profiling middleware to orchard.profile #929

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## master (unreleased)

* Bump `orchard` to [0.33.0](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0330-2025-04-08).
* [#929](https://github.com/clojure-emacs/cider-nrepl/pull/929): Migrate profiling middleware to orchard.profile.

## 0.54.0 (2025-04-05)

* Bump `orchard` to [0.32.1](https://github.com/clojure-emacs/orchard/blob/master/CHANGELOG.md#0320-2025-04-05).
* [#925](https://github.com/clojure-emacs/cider-nrepl/pull/9250): Stop vendoring Puget dependency.
* [#925](https://github.com/clojure-emacs/cider-nrepl/pull/925): Stop vendoring Puget dependency.
* [#917](https://github.com/clojure-emacs/cider-nrepl/pull/917): Sort printed maps in test output.
* [#927](https://github.com/clojure-emacs/cider-nrepl/pull/927): Add `inspect-display-analytics` op.
* [#928](https://github.com/clojure-emacs/cider-nrepl/pull/922): Add support for `:table` view-mode in inspector.
Expand Down
201 changes: 66 additions & 135 deletions doc/modules/ROOT/pages/nrepl-api/ops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ Returns::



=== `clear-profile`

Clears profile of samples.

Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
* `:status` Done



=== `clojuredocs-lookup`

Return a map of information in ClojureDocs.
Expand Down Expand Up @@ -372,22 +357,6 @@ Returns::



=== `get-max-samples`

Returns maximum number of samples to be collected for any var.

Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` String representing number of max-sample-count



=== `info`

Return a map of information about the specified symbol.
Expand Down Expand Up @@ -779,24 +748,6 @@ Returns::



=== `is-var-profiled`

Reports whether symbol is currently profiled.

Required parameters::
* `:ns` The current namespace
* `:sym` The symbol to check


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled



=== `macroexpand`

Produces macroexpansion of some form using the given expander.
Expand Down Expand Up @@ -966,40 +917,6 @@ Returns::
{blank}


=== `profile-summary`

Return profiling data summary.

Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
* `:err` Content of profile summary report
* `:status` Done



=== `profile-var-summary`

Return profiling data summary for a single var.

Required parameters::
* `:ns` The current namespace
* `:sym` The symbol to profile


Optional parameters::
{blank}

Returns::
* `:err` Content of profile summary report
* `:status` Done



=== `refresh`

Reloads all changed files in dependency order.
Expand Down Expand Up @@ -1125,23 +1042,6 @@ Returns::



=== `set-max-samples`

Sets maximum sample count. Returns new max-sample-count.

Required parameters::
* `:max-samples` Maximum samples to collect for any single var.


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` String representing number of max-sample-count



=== `slurp`

Slurps a URL from the nREPL server, returning MIME data.
Expand Down Expand Up @@ -1332,41 +1232,6 @@ Returns::



=== `toggle-profile`

Toggle profiling of a given var.

Required parameters::
* `:ns` The current namespace
* `:sym` The symbol to profile


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled, 'unbound' if ns/sym not bound



=== `toggle-profile-ns`

Toggle profiling of given namespace.

Required parameters::
* `:ns` The current namespace


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled



=== `toggle-trace-ns`

Toggle tracing of a given ns.
Expand Down Expand Up @@ -1737,6 +1602,72 @@ Returns::



=== `cider/profile-clear`

Clear profiling data.

Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
* `:status` Done



=== `cider/profile-summary`

Return profiling summary optimized for viewing through CIDER inspector.

Required parameters::
{blank}

Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` Profile summary as inspectable data structure.



=== `cider/profile-toggle-ns`

Toggle profiling of given namespace.

Required parameters::
* `:ns` The current namespace


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled



=== `cider/profile-toggle-var`

Toggle profiling of a given var.

Required parameters::
* `:ns` The current namespace
* `:sym` The symbol to profile


Optional parameters::
{blank}

Returns::
* `:status` Done
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled



=== `cider.clj-reload/reload`

Reloads all changed files in dependency order,
Expand Down
4 changes: 2 additions & 2 deletions doc/modules/ROOT/pages/nrepl-api/supplied_middleware.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
| `wrap-profile`
| -
| No
| `toggle-profile/toggle-profile-ns/is-var-profiled/profile-summary/profile-var-summary/clear-profile/get-max-samples/set-max-samples`
| Provides profiling support based on the https://github.com/thunknyc/profile[profile] library.
| `cider/profile-toggle-var`, `cider/profile-toggle-ns`, `cider/profile-summary`, `cider/profile-clear`
| Middleware for manual profiling.

| `wrap-refresh`
| -
Expand Down
7 changes: 2 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
:dependencies [[nrepl/nrepl "1.3.1" :exclusions [org.clojure/clojure]]
[cider/orchard "0.32.1" :exclusions [org.clojure/clojure]]
^:inline-dep [thunknyc/profile "0.5.2"]
[cider/orchard "0.33.0" :exclusions [org.clojure/clojure]]
^:inline-dep [fipp ~fipp-version] ; can be removed in unresolved-tree mode
^:inline-dep [compliment "0.7.0"]
^:inline-dep [org.rksm/suitable "0.6.2" :exclusions [org.clojure/clojure
Expand Down Expand Up @@ -151,8 +150,6 @@
:eastwood [:test
{:plugins [[jonase/eastwood "1.4.0"]]
:eastwood {:config-files ["eastwood.clj"]
:exclude-namespaces [cider.nrepl.middleware.test-filter-tests cider.tasks]
:ignored-faults {:unused-ret-vals-in-try {cider.nrepl.middleware.profile-test [{:line 25}]}
:suspicious-test {cider.nrepl.middleware.profile-test [{:line 25}]}}}}]
:exclude-namespaces [cider.nrepl.middleware.test-filter-tests cider.tasks]}}]

:deploy {:source-paths [".circleci/deploy"]}})
63 changes: 19 additions & 44 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -580,41 +580,23 @@ if applicable, and re-render the updated value."
{:doc "Change #'*out* so that it no longer prints to active sessions outside an eval scope."}}}))

(def-wrapper wrap-profile cider.nrepl.middleware.profile/handle-profile
{:doc "Middleware that provides supports Profiling based on https://github.com/thunknyc/profile"
:handles {"toggle-profile-ns" {:doc "Toggle profiling of given namespace."
:requires {"ns" "The current namespace"}
:returns {"status" "Done"
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
"is-var-profiled" {:doc "Reports whether symbol is currently profiled."
:requires {"sym" "The symbol to check"
"ns" "The current namespace"}
:returns {"status" "Done"
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
"get-max-samples" {:doc "Returns maximum number of samples to be collected for any var."
:requires {}
:returns {"status" "Done"
"value" "String representing number of max-sample-count"}}
"set-max-samples" {:doc "Sets maximum sample count. Returns new max-sample-count."
:requires {"max-samples" "Maximum samples to collect for any single var."}
:returns {"status" "Done"
"value" "String representing number of max-sample-count"}}
"toggle-profile" {:doc "Toggle profiling of a given var."
:requires {"sym" "The symbol to profile"
"ns" "The current namespace"}
:returns {"status" "Done"
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled, 'unbound' if ns/sym not bound"}}
"profile-var-summary" {:doc "Return profiling data summary for a single var."
:requires {"sym" "The symbol to profile"
"ns" "The current namespace"}
:returns {"status" "Done"
"err" "Content of profile summary report"}}
"profile-summary" {:doc "Return profiling data summary."
:requires {}
:returns {"status" "Done"
"err" "Content of profile summary report"}}
"clear-profile" {:doc "Clears profile of samples."
:requires {}
:returns {"status" "Done"}}}})
{:doc "Middleware for manual profiling"
:handles {"cider/profile-toggle-var" {:doc "Toggle profiling of a given var."
:requires {"sym" "The symbol to profile"
"ns" "The current namespace"}
:returns {"status" "Done"
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
"cider/profile-toggle-ns" {:doc "Toggle profiling of given namespace."
:requires {"ns" "The current namespace"}
:returns {"status" "Done"
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
"cider/profile-summary" {:doc "Return profiling summary optimized for viewing through CIDER inspector."
:requires {}
:returns {"status" "Done"
"value" "Profile summary as inspectable data structure."}}
"cider/profile-clear" {:doc "Clear profiling data."
:requires {}
:returns {"status" "Done"}}}})

(def code-reloading-before-after-opts
{"before" "The namespace-qualified name of a zero-arity function to call before reloading."
Expand Down Expand Up @@ -757,20 +739,13 @@ stack frame of the most recent exception. This op is deprecated, please use the
:requires {"ns" "The namespace to trace"}
:returns {"ns-status" "The result of tracing operation"}}}})

(def ops-that-can-eval
"Set of nREPL ops that can lead to code being evaluated."
#{"eval" "load-file"
"refresh" "refresh-all" "refresh-clear"
"cider.clj-reload/reload" "cider.clj-reload/reload-all" "cider.clj-reload/reload-clear"
"toggle-trace-var" "toggle-trace-ns" "undef" "undef-all"})

(def-wrapper wrap-tracker cider.nrepl.middleware.track-state/handle-tracker
ops-that-can-eval
mw/ops-that-can-eval
(cljs/expects-piggieback
{:doc "Under its normal operation mode, enhances the `eval` op by notifying the client of the current REPL state.
You can also request to compute the info directly by requesting the \"cider/get-state\" op."
:requires #{#'session}
:expects ops-that-can-eval
:expects mw/ops-that-can-eval
:handles {"cider/get-state" {}}
:returns {"repl-type" "`:clj` or `:cljs`."
"changed-namespaces" "A map of namespaces to `{:aliases ,,, :interns ,,,}`"}}))
Expand Down
9 changes: 9 additions & 0 deletions src/cider/nrepl/middleware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@
cider.nrepl/wrap-undef
cider.nrepl/wrap-version
cider.nrepl/wrap-xref])

(def ops-that-can-eval
"Set of nREPL ops that can lead to code being evaluated."
#{"eval" "load-file"
"refresh" "refresh-all" "refresh-clear"
"cider.clj-reload/reload" "cider.clj-reload/reload-all" "cider.clj-reload/reload-clear"
"toggle-trace-var" "toggle-trace-ns"
"undef" "undef-all"
"cider/profile-toggle-var" "cider/profile-toggle-ns"})
Loading