Skip to content

Commit

Permalink
Fix profiling (#926)
Browse files Browse the repository at this point in the history
* Fix profiling

* Add back --cpuprofile to not break backward compatibility

* Remove profile command line flag
  • Loading branch information
mat007 authored Mar 3, 2025
1 parent 012e2ea commit 325bff2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions cmd/mockery.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ func (r *RootApp) Run() error {
return nil
}

if r.Config.Profile != "" || r.Config.Cpuprofile != "" {
profile := r.Config.Profile
if profile == "" {
profile = r.Config.Cpuprofile
}
f, err := os.Create(profile)
if err != nil {
return stackerr.NewStackErrf(err, "Failed to create profile file")
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
return fmt.Errorf("failed to start CPU profile: %w", err)
}
defer pprof.StopCPUProfile()
}

var osp pkg.OutputStreamProvider
if r.Config.Print {
osp = &pkg.StdoutStreamProvider{}
Expand Down Expand Up @@ -343,18 +359,6 @@ func (r *RootApp) Run() error {
log.Fatal().Msgf("Use --name to specify the name of the interface or --all for all interfaces found")
}

if r.Config.Profile != "" {
f, err := os.Create(r.Config.Profile)
if err != nil {
return stackerr.NewStackErrf(err, "Failed to create profile file")
}
defer f.Close()
if err := pprof.StartCPUProfile(f); err != nil {
return fmt.Errorf("failed to start CPU profile: %w", err)
}
defer pprof.StopCPUProfile()
}

baseDir := r.Config.Dir

if osp == nil {
Expand Down

0 comments on commit 325bff2

Please sign in to comment.