Skip to content

Commit 897cceb

Browse files
[profile] Migrate profiling middleware to orchard.profile
1 parent 4122d85 commit 897cceb

File tree

8 files changed

+169
-349
lines changed

8 files changed

+169
-349
lines changed

doc/modules/ROOT/pages/nrepl-api/ops.adoc

Lines changed: 66 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,6 @@ Returns::
7777

7878

7979

80-
=== `clear-profile`
81-
82-
Clears profile of samples.
83-
84-
Required parameters::
85-
{blank}
86-
87-
Optional parameters::
88-
{blank}
89-
90-
Returns::
91-
* `:status` Done
92-
93-
94-
9580
=== `clojuredocs-lookup`
9681

9782
Return a map of information in ClojureDocs.
@@ -372,22 +357,6 @@ Returns::
372357

373358

374359

375-
=== `get-max-samples`
376-
377-
Returns maximum number of samples to be collected for any var.
378-
379-
Required parameters::
380-
{blank}
381-
382-
Optional parameters::
383-
{blank}
384-
385-
Returns::
386-
* `:status` Done
387-
* `:value` String representing number of max-sample-count
388-
389-
390-
391360
=== `info`
392361

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

780749

781750

782-
=== `is-var-profiled`
783-
784-
Reports whether symbol is currently profiled.
785-
786-
Required parameters::
787-
* `:ns` The current namespace
788-
* `:sym` The symbol to check
789-
790-
791-
Optional parameters::
792-
{blank}
793-
794-
Returns::
795-
* `:status` Done
796-
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled
797-
798-
799-
800751
=== `macroexpand`
801752

802753
Produces macroexpansion of some form using the given expander.
@@ -966,40 +917,6 @@ Returns::
966917
{blank}
967918

968919

969-
=== `profile-summary`
970-
971-
Return profiling data summary.
972-
973-
Required parameters::
974-
{blank}
975-
976-
Optional parameters::
977-
{blank}
978-
979-
Returns::
980-
* `:err` Content of profile summary report
981-
* `:status` Done
982-
983-
984-
985-
=== `profile-var-summary`
986-
987-
Return profiling data summary for a single var.
988-
989-
Required parameters::
990-
* `:ns` The current namespace
991-
* `:sym` The symbol to profile
992-
993-
994-
Optional parameters::
995-
{blank}
996-
997-
Returns::
998-
* `:err` Content of profile summary report
999-
* `:status` Done
1000-
1001-
1002-
1003920
=== `refresh`
1004921

1005922
Reloads all changed files in dependency order.
@@ -1125,23 +1042,6 @@ Returns::
11251042

11261043

11271044

1128-
=== `set-max-samples`
1129-
1130-
Sets maximum sample count. Returns new max-sample-count.
1131-
1132-
Required parameters::
1133-
* `:max-samples` Maximum samples to collect for any single var.
1134-
1135-
1136-
Optional parameters::
1137-
{blank}
1138-
1139-
Returns::
1140-
* `:status` Done
1141-
* `:value` String representing number of max-sample-count
1142-
1143-
1144-
11451045
=== `slurp`
11461046

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

13331233

13341234

1335-
=== `toggle-profile`
1336-
1337-
Toggle profiling of a given var.
1338-
1339-
Required parameters::
1340-
* `:ns` The current namespace
1341-
* `:sym` The symbol to profile
1342-
1343-
1344-
Optional parameters::
1345-
{blank}
1346-
1347-
Returns::
1348-
* `:status` Done
1349-
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled, 'unbound' if ns/sym not bound
1350-
1351-
1352-
1353-
=== `toggle-profile-ns`
1354-
1355-
Toggle profiling of given namespace.
1356-
1357-
Required parameters::
1358-
* `:ns` The current namespace
1359-
1360-
1361-
Optional parameters::
1362-
{blank}
1363-
1364-
Returns::
1365-
* `:status` Done
1366-
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled
1367-
1368-
1369-
13701235
=== `toggle-trace-ns`
13711236

13721237
Toggle tracing of a given ns.
@@ -1737,6 +1602,72 @@ Returns::
17371602

17381603

17391604

1605+
=== `cider/profile-clear`
1606+
1607+
Clear profiling data.
1608+
1609+
Required parameters::
1610+
{blank}
1611+
1612+
Optional parameters::
1613+
{blank}
1614+
1615+
Returns::
1616+
* `:status` Done
1617+
1618+
1619+
1620+
=== `cider/profile-summary`
1621+
1622+
Return profiling summary optimized for viewing through CIDER inspector.
1623+
1624+
Required parameters::
1625+
{blank}
1626+
1627+
Optional parameters::
1628+
{blank}
1629+
1630+
Returns::
1631+
* `:status` Done
1632+
* `:value` Profile summary as inspectable data structure.
1633+
1634+
1635+
1636+
=== `cider/profile-toggle-ns`
1637+
1638+
Toggle profiling of given namespace.
1639+
1640+
Required parameters::
1641+
* `:ns` The current namespace
1642+
1643+
1644+
Optional parameters::
1645+
{blank}
1646+
1647+
Returns::
1648+
* `:status` Done
1649+
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled
1650+
1651+
1652+
1653+
=== `cider/profile-toggle-var`
1654+
1655+
Toggle profiling of a given var.
1656+
1657+
Required parameters::
1658+
* `:ns` The current namespace
1659+
* `:sym` The symbol to profile
1660+
1661+
1662+
Optional parameters::
1663+
{blank}
1664+
1665+
Returns::
1666+
* `:status` Done
1667+
* `:value` 'profiled' if profiling enabled, 'unprofiled' if disabled
1668+
1669+
1670+
17401671
=== `cider.clj-reload/reload`
17411672

17421673
Reloads all changed files in dependency order,

doc/modules/ROOT/pages/nrepl-api/supplied_middleware.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484
| `wrap-profile`
8585
| -
8686
| No
87-
| `toggle-profile/toggle-profile-ns/is-var-profiled/profile-summary/profile-var-summary/clear-profile/get-max-samples/set-max-samples`
88-
| Provides profiling support based on the https://github.com/thunknyc/profile[profile] library.
87+
| `cider/profile-toggle-var`, `cider/profile-toggle-ns`, `cider/profile-summary`, `cider/profile-clear`
88+
| Middleware for manual profiling.
8989

9090
| `wrap-refresh`
9191
| -

project.clj

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
:url "http://www.eclipse.org/legal/epl-v10.html"}
2323
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
2424
:dependencies [[nrepl/nrepl "1.3.1" :exclusions [org.clojure/clojure]]
25-
[cider/orchard "0.32.1" :exclusions [org.clojure/clojure]]
26-
^:inline-dep [thunknyc/profile "0.5.2"]
25+
[cider/orchard "0.33.0" :exclusions [org.clojure/clojure]]
2726
^:inline-dep [fipp ~fipp-version] ; can be removed in unresolved-tree mode
2827
^:inline-dep [compliment "0.7.0"]
2928
^:inline-dep [org.rksm/suitable "0.6.2" :exclusions [org.clojure/clojure
@@ -151,8 +150,6 @@
151150
:eastwood [:test
152151
{:plugins [[jonase/eastwood "1.4.0"]]
153152
:eastwood {:config-files ["eastwood.clj"]
154-
:exclude-namespaces [cider.nrepl.middleware.test-filter-tests cider.tasks]
155-
:ignored-faults {:unused-ret-vals-in-try {cider.nrepl.middleware.profile-test [{:line 25}]}
156-
:suspicious-test {cider.nrepl.middleware.profile-test [{:line 25}]}}}}]
153+
:exclude-namespaces [cider.nrepl.middleware.test-filter-tests cider.tasks]}}]
157154

158155
:deploy {:source-paths [".circleci/deploy"]}})

src/cider/nrepl.clj

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -580,41 +580,23 @@ if applicable, and re-render the updated value."
580580
{:doc "Change #'*out* so that it no longer prints to active sessions outside an eval scope."}}}))
581581

582582
(def-wrapper wrap-profile cider.nrepl.middleware.profile/handle-profile
583-
{:doc "Middleware that provides supports Profiling based on https://github.com/thunknyc/profile"
584-
:handles {"toggle-profile-ns" {:doc "Toggle profiling of given namespace."
585-
:requires {"ns" "The current namespace"}
586-
:returns {"status" "Done"
587-
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
588-
"is-var-profiled" {:doc "Reports whether symbol is currently profiled."
589-
:requires {"sym" "The symbol to check"
590-
"ns" "The current namespace"}
591-
:returns {"status" "Done"
592-
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
593-
"get-max-samples" {:doc "Returns maximum number of samples to be collected for any var."
594-
:requires {}
595-
:returns {"status" "Done"
596-
"value" "String representing number of max-sample-count"}}
597-
"set-max-samples" {:doc "Sets maximum sample count. Returns new max-sample-count."
598-
:requires {"max-samples" "Maximum samples to collect for any single var."}
599-
:returns {"status" "Done"
600-
"value" "String representing number of max-sample-count"}}
601-
"toggle-profile" {:doc "Toggle profiling of a given var."
602-
:requires {"sym" "The symbol to profile"
603-
"ns" "The current namespace"}
604-
:returns {"status" "Done"
605-
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled, 'unbound' if ns/sym not bound"}}
606-
"profile-var-summary" {:doc "Return profiling data summary for a single var."
607-
:requires {"sym" "The symbol to profile"
608-
"ns" "The current namespace"}
609-
:returns {"status" "Done"
610-
"err" "Content of profile summary report"}}
611-
"profile-summary" {:doc "Return profiling data summary."
612-
:requires {}
613-
:returns {"status" "Done"
614-
"err" "Content of profile summary report"}}
615-
"clear-profile" {:doc "Clears profile of samples."
616-
:requires {}
617-
:returns {"status" "Done"}}}})
583+
{:doc "Middleware for manual profiling"
584+
:handles {"cider/profile-toggle-var" {:doc "Toggle profiling of a given var."
585+
:requires {"sym" "The symbol to profile"
586+
"ns" "The current namespace"}
587+
:returns {"status" "Done"
588+
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
589+
"cider/profile-toggle-ns" {:doc "Toggle profiling of given namespace."
590+
:requires {"ns" "The current namespace"}
591+
:returns {"status" "Done"
592+
"value" "'profiled' if profiling enabled, 'unprofiled' if disabled"}}
593+
"cider/profile-summary" {:doc "Return profiling summary optimized for viewing through CIDER inspector."
594+
:requires {}
595+
:returns {"status" "Done"
596+
"value" "Profile summary as inspectable data structure."}}
597+
"cider/profile-clear" {:doc "Clear profiling data."
598+
:requires {}
599+
:returns {"status" "Done"}}}})
618600

619601
(def code-reloading-before-after-opts
620602
{"before" "The namespace-qualified name of a zero-arity function to call before reloading."

src/cider/nrepl/middleware/inspect.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
(select-keys msg [:page-size :max-atom-length :max-coll-size
3535
:max-value-length :max-nested-depth :display-analytics-hint]))
3636

37-
(defn inspect-reply*
38-
[msg value]
37+
(defn inspect-reply* [{:keys [view-mode] :as msg} value]
3938
(let [config (msg->inspector-config msg)
40-
inspector (swap-inspector! msg #(inspect/start (merge % config) value))]
39+
;; Setting view mode from the start is only needed by cider-profile.
40+
inspector (swap-inspector! msg #(cond-> (inspect/start (merge % config) value)
41+
view-mode (inspect/set-view-mode view-mode)))]
4142
;; By using 3-arity `inspector-response` we ensure that the default
4243
;; `{:status :done}` is not sent with this message, as the underlying
4344
;; eval will send it on its own.

0 commit comments

Comments
 (0)