Skip to content

Commit 9cb5376

Browse files
committed
improve computation profile endpoint
1 parent 950c08d commit 9cb5376

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

server/utils/emulator.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424
"slices"
2525
"strconv"
26+
"strings"
2627

2728
"github.com/gorilla/mux"
2829
"github.com/onflow/cadence/runtime"
@@ -261,17 +262,30 @@ func (m EmulatorAPIServer) ComputationReport(w http.ResponseWriter, _ *http.Requ
261262
}
262263
}
263264

265+
const cadenceFileSuffix = ".cdc"
266+
264267
func (m EmulatorAPIServer) ComputationProfile(w http.ResponseWriter, _ *http.Request) {
268+
w.Header().Set("Content-Disposition", "attachment; filename=profile.pprof")
265269
w.Header().Set("Content-Type", "application/gzip")
266270

267271
computationProfile := m.emulator.ComputationProfile()
272+
if computationProfile == nil {
273+
w.WriteHeader(http.StatusNotFound)
274+
return
275+
}
268276

269277
pprofProfile, err := runtime.NewPProfExporter(computationProfile).Export()
270278
if err != nil {
271279
w.WriteHeader(http.StatusInternalServerError)
272280
return
273281
}
274282

283+
for _, function := range pprofProfile.Function {
284+
if !strings.HasSuffix(function.Filename, cadenceFileSuffix) {
285+
function.Filename += cadenceFileSuffix
286+
}
287+
}
288+
275289
err = pprofProfile.Write(w)
276290
if err != nil {
277291
w.WriteHeader(http.StatusInternalServerError)

0 commit comments

Comments
 (0)