Skip to content

Commit

Permalink
Add clj-async-profiler to repl for benchmarking.
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed Jan 23, 2020
1 parent 895ef01 commit eed3b8d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
27 changes: 27 additions & 0 deletions core/dev/cljstyle/repl.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns cljstyle.repl
(:require
[clj-async-profiler.core :as prof]
[cljstyle.config :as config]
[cljstyle.format.core :as fmt]
[cljstyle.format.zloc :as zl]
Expand Down Expand Up @@ -37,3 +38,29 @@
(as-> x (apply edit-fn x args))
(node/string)
(println)))



;; ## Flame Graphs

(defn massage-stack
"Collapse a stack frame in a profiling run."
[stack]
(-> stack
(str/replace #"cljstyle\.task\.process/processing-action/compute-BANG---\d+;(.*;cljstyle\.task\.process/processing-action/compute-BANG---\d+;)?"
"cljstyle.task.process/processing-action/compute! ...;")
,,,))


(comment
;; For example:
(prof/profile
{:event :cpu
:transform massage-stack}
(try
(task/check-sources ["../.."])
(catch Exception _
nil)))

;; - Should also support `:alloc` profiling
,,,)
4 changes: 3 additions & 1 deletion core/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
{:repl
{:source-paths ["dev"]
:repl-options {:init-ns cljstyle.repl}
:jvm-opts ["-XX:+UnlockDiagnosticVMOptions" "-XX:+DebugNonSafepoints"]
:dependencies
[[org.clojure/tools.namespace "0.3.1"]]}})
[[com.clojure-goes-fast/clj-async-profiler "0.4.0"]
[org.clojure/tools.namespace "0.3.1"]]}})
9 changes: 6 additions & 3 deletions core/src/cljstyle/task/process.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
(send results report-result! result)))

compute!
(bound-fn []
(bound-fn compute!
[]
(cond
(config/ignored? config file)
(report!
Expand All @@ -92,8 +93,10 @@
(config/directory? file)
(try
(let [config' (config/merge-settings config (config/dir-config file))
file->task #(processing-action process! results config' root %)
subtasks (mapv file->task (.listFiles file))]
subtasks (mapv (fn file-task
[child]
(processing-action process! results config' root child))
(.listFiles file))]
(ForkJoinTask/invokeAll ^java.util.Collection subtasks))
(catch Exception ex
(report!
Expand Down
11 changes: 9 additions & 2 deletions core/test/cljstyle/format/type_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@
;; a method comment
(frobble
[bar x y]))")))
,,,))
[bar x y]))"))))
(testing "nesting"
(is (= "(do
(defprotocol Foo
\"doc string goes here\"
(abc [foo])))"
(reformat-string "(do\n(defprotocol Foo \"doc string goes here\"
(abc [foo])))")))))


(deftest type-definitions
Expand Down

0 comments on commit eed3b8d

Please sign in to comment.