Rename 'total'->'time'

This commit is contained in:
Peter Taoussanis 2012-12-16 18:45:01 +07:00
parent 2c6230dfa8
commit d6bc6b2947

View File

@ -30,8 +30,8 @@
[plog] [plog]
(reduce (fn [m [pname times]] (reduce (fn [m [pname times]]
(let [count (count times) (let [count (count times)
total (reduce + times) time (reduce + times)
mean (long (/ total count)) mean (long (/ time count))
;; Mean Absolute Deviation ;; Mean Absolute Deviation
mad (long (/ (reduce + (map #(Math/abs (long (- % mean))) mad (long (/ (reduce + (map #(Math/abs (long (- % mean)))
times)) times))
@ -41,7 +41,7 @@
:max (apply max times) :max (apply max times)
:mean mean :mean mean
:mad mad :mad mad
:total total}))) :time time})))
{} plog)) {} plog))
(defn fqname (defn fqname
@ -51,14 +51,14 @@
(defn plog-table (defn plog-table
"Returns formatted table string for given plog stats." "Returns formatted table string for given plog stats."
([stats] (plog-table stats :total)) ([stats] (plog-table stats :time))
([stats sort-field] ([stats sort-field]
(let [;; How long entire (profile) body took (let [;; How long entire (profile) body took
total-time (-> stats :meta/total :total) total-time (-> stats :meta/total :time)
stats (dissoc stats :meta/total) stats (dissoc stats :meta/total)
;; Sum of (p) times, <= total-time ;; Sum of (p) times, <= total-time
accounted (reduce + (map :total (vals stats))) accounted (reduce + (map :time (vals stats)))
max-name-width (apply max (map (comp count str) max-name-width (apply max (map (comp count str)
(conj (keys stats) "Unaccounted"))) (conj (keys stats) "Unaccounted")))
@ -76,18 +76,18 @@
:else (str (long nanosecs) "ns"))))] :else (str (long nanosecs) "ns"))))]
(with-out-str (with-out-str
(printf s-pattern "Name" "Calls" "Min" "Max" "MAD" "Mean" "Total%" "Total") (printf s-pattern "Name" "Calls" "Min" "Max" "MAD" "Mean" "Time%" "Time")
(doseq [pname (->> (keys stats) (doseq [pname (->> (keys stats)
(sort-by #(- (get-in stats [% sort-field]))))] (sort-by #(- (get-in stats [% sort-field]))))]
(let [{:keys [count min max mean mad total]} (stats pname)] (let [{:keys [count min max mean mad time]} (stats pname)]
(printf pattern (fqname pname) count (ft min) (ft max) (ft mad) (printf pattern (fqname pname) count (ft min) (ft max) (ft mad)
(ft mean) (perc total total-time) (ft total)))) (ft mean) (perc time total-time) (ft time))))
(let [unacc (- total-time accounted) (let [unacc (- total-time accounted)
unacc-perc (perc unacc total-time)] unacc-perc (perc unacc total-time)]
(printf s-pattern "Unaccounted" "" "" "" "" "" unacc-perc (ft unacc)) (printf s-pattern "Unaccounted" "" "" "" "" "" unacc-perc (ft unacc))
(printf s-pattern "Total" "" "" "" "" "" 100 (ft total-time))))))) (printf s-pattern "Time" "" "" "" "" "" 100 (ft total-time)))))))
(defmacro profile* (defmacro profile*
"Executes named body with profiling enabled. Body forms wrapped in (p) will be "Executes named body with profiling enabled. Body forms wrapped in (p) will be