-
Notifications
You must be signed in to change notification settings - Fork 0
/
002_async_profiler.clj
74 lines (41 loc) · 1.24 KB
/
002_async_profiler.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(ns clojure-quips.002-async-profiler
(:require [clj-async-profiler.core :as prof]))
;;;; clj-async-profiler demo
;;;; See:
;;;; - Profiling tool: async-profiler: http://clojure-goes-fast.com/blog/profiling-tool-async-profiler/
;;;; - Github: https://github.com/clojure-goes-fast/clj-async-profiler
;;;; - Adds support for SVG's `width` and `height` options: https://github.com/clojure-goes-fast/clj-async-profiler/pull/10/
(defn test-sum []
(reduce + (map inc (range 1000))))
(defn test-div []
(reduce / (map inc (range 1000))))
;; optimized with doubles
#_(defn test-div []
(reduce / (map #(-> % inc double) (range 1000))))
(defn burn-cpu [secs]
(let [start (System/nanoTime)]
(while (< (/ (- (System/nanoTime) start) 1e9) secs)
(test-sum)
(test-div))))
(comment
(prof/list-event-types)
;; => Basic events:
;; cpu
;; alloc
;; lock
;; wall
;; itimer
;; start profiling
(prof/start {})
;; or
(prof/start {:event :alloc})
;; then run the task
(burn-cpu 10)
;; then stop the profiling
(prof/stop {})
;; or profile the form itself (still system wide!)
(prof/profile {:width 2400}
(burn-cpu 10))
(prof/serve-files 8888)
;; end comment
)