File tree Expand file tree Collapse file tree 7 files changed +21
-7
lines changed
Expand file tree Collapse file tree 7 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 1414 (@rl/global-saved-kbytes-limiter length-kb))
1515 (raise 429 " Upload saved bytes limit reached." )))
1616
17- (defn save-profile [stream ip {:keys [public] :as params}]
17+ (defn save-profile [stream ip {:keys [public kind ] :as params}]
1818 (let [profile (case (:format params)
1919 :collapsed (proc/collapsed-stacks-stream->dense-profile stream)
2020 :dense-edn (proc/dense-edn-stream->dense-profile stream))
2727 (ensure-saved-limits ip dpf-kb)
2828 (storage/save-file dpf-array filename)
2929 ; ; TODO: replace IP with proper owner at some point
30- (-> (dto/->Profile id filename (:type params) (:total-samples profile) ip
30+ (-> (dto/->Profile id filename (:type params) kind (:total-samples profile) ip
3131 edit-token public nil (Instant/now ))
3232 db/insert-profile
3333 ; ; Attach read-token to the response here — it's not in the scheme
Original file line number Diff line number Diff line change 4040
4141(defschema-and-constructor DenseProfile
4242 (-> (array-map
43- :stacks [:vector [:tuple [:vector nat-int?] pos-int?]]
43+ :stacks [:or
44+ [:vector [:tuple [:vector nat-int?] pos-int?]]
45+ [:vector [:tuple [:vector nat-int?] [:map
46+ [:samples-a pos-int?]
47+ [:samples-b pos-int?]]]]]
4448 :id->frame [:vector string?]
4549 :total-samples pos-int?)
4650 mlite/schema
Original file line number Diff line number Diff line change 109109 collapsed-stacks-stream->intermediate-profile
110110 intermediate-profile->dense-profile))
111111
112+ (defn- count-total-samples [dense-profile]
113+ (transduce (if (number? (first (:stacks dense-profile)))
114+ (map second) ; ; Flamegraph
115+ (map (fn [[_ v]](+ (:samples-a v) (:samples-b v))))) ; ; Diffgraph
116+ + 0 (:stacks dense-profile)))
117+
112118(defn dense-edn-stream->dense-profile [^InputStream input-stream]
113119 (with-open [rdr (PushbackReader. (io/reader input-stream))]
114120 (let [profile (select-keys (edn/read rdr) [:stacks :id->frame :total-samples ])]
115121 (m/assert DenseProfile profile)
116122 ; ; Calculate total samples if not provided.
117123 (update profile :total-samples
118- #(or % (transduce ( map second) + 0 ( :stacks profile) ))))))
124+ #(or % (count-total-samples profile))))))
119125
120126(defn read-compressed-profile [source-file read-token]
121127 (try (nippy/thaw-from-file source-file {:password (when read-token
Original file line number Diff line number Diff line change 66
77(defn render-html-flamegraph [dense-profile profile-dto options]
88 (let [{:keys [stacks id->frame]} dense-profile
9- {:keys [config]} profile-dto
9+ {:keys [config kind ]} profile-dto
1010 config (if config
1111 (str " \" " config " \" " )
1212 " null" )
1313 idToFrame (#'cljap.render/print-id-to-frame id->frame)
14- data (#'cljap.render/print-add-stacks stacks false )
14+ diffgraph? (= kind :diffgraph )
15+ data (#'cljap.render/print-add-stacks stacks diffgraph?)
1516 user-transforms nil
1617 full-js (-> (slurp (io/resource " flamegraph/script.js" ))
1718 (cljap.render/render-template
1819 {:graphTitle (pr-str (or (:title options) " " ))
1920 :profileId (:id profile-dto)
20- :isDiffgraph false
21+ :isDiffgraph ( str diffgraph?)
2122 :userTransforms " "
2223 :idToFrame idToFrame
2324 :config config
Original file line number Diff line number Diff line change 4242(defn $upload-profile [{:keys [remote-addr body query-params] :as req}]
4343 (let [length-kb (quot (ensure-content-length req) 1024 )]
4444 (ensure-processed-limits remote-addr length-kb)
45+ (when (and (= (:kind query-params) :diffgraph )
46+ (= (:format query-params) :collapsed ))
47+ (raise 422 " Diffgraphs can only be uploaded in dense-edn format." ))
4548 (let [{:keys [id read-token edit_token] :as profile}
4649 (core/save-profile body remote-addr query-params)]
4750 {:status 201
You can’t perform that action at this time.
0 commit comments