Skip to content

Commit

Permalink
backend: generate mem profile for proto generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Jan 16, 2025
1 parent 387a0c2 commit 23d25be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/pkg/proto/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"context"
"encoding/binary"
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -461,6 +465,8 @@ func (s *Service) tryCreateProtoRegistry() {
}

func (s *Service) createProtoRegistry(ctx context.Context) error {
runtime.GC() // get up-to-date statistics

startTime := time.Now()

files := make(map[string]filesystem.File)
Expand Down Expand Up @@ -548,6 +554,16 @@ func (s *Service) createProtoRegistry(ctx context.Context) error {
zap.Int("registered_types", len(fileDescriptors)),
zap.Duration("operation_duration", totalDuration))

fend, err := os.Create("protomemprofile")
if err != nil {
log.Fatal("could not create memory profile: ", err)
}
defer fend.Close() // error handling omitted for example
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(fend); err != nil {
log.Fatal("could not write memory profile: ", err)
}

return nil
}

Expand Down

0 comments on commit 23d25be

Please sign in to comment.