1
Tutfe是一個剖析庫,它非常適合理解運行時的組成,特別是在複雜的調用棧中。如何用Tufte剖析多線程clojure結果
當我在我的項目中運行它時,我預期代碼段的性能價格昂貴,並未在結果中註冊爲高級用戶,這導致發現Tufte(合理)僅捕獲了線程本地結果。
的文檔表明,它有內置的結合上使用{:dynamic? true}
選擇其他線程儀器累計時間,但似乎更需要爲了捕捉積累的其它線程,如由pmap
啓動時間
這裏是原來的塔夫特的演示,一些多線程介紹:
(require '[taoensso.tufte :as tufte :refer (defnp p profiled profile)])
;; We'll request to send `profile` stats to `println`:
(tufte/add-basic-println-handler! {})
;;; Let's define a couple dummy fns to simulate doing some expensive work
(defn get-x [] (Thread/sleep 500) "x val")
(defn get-y []
(pmap
#(do
(Thread/sleep 500)
(print %))
(range 10)))
;; How do these fns perform? Let's check:
(profile ; Profile any `p` forms called during body execution
{:dynamic? true} ; Profiling options; we'll use the defaults for now
(dotimes [_ 5]
(p :get-x (get-x))
(p :get-y (get-y))))
輸出表明println語句強行線程來評估。然而,get-y累計時間並未顯示在結果中:
2187306594=> nil
=> #{:basic-println}
=> #'user/get-x
=> #'user/get-y
8904365271703695842110783956243415760829=> nil
pId nCalls Min Max MAD Mean Time% Time
:get-x 5 500.52ms 504.84ms 1.44ms 502.44ms 100 2.51s
:get-y 5 90.67μs 581.91μs 162.2μs 269.29μs 0 1.35ms
Clock Time 100 2.51s
Accounted Time 100 2.51s