Skip to content

Add elapsed time on debug for slow git commands #25642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 4, 2023
10 changes: 9 additions & 1 deletion modules/git/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func (c *Command) Run(opts *RunOpts) error {
}
defer finished()

startTime := time.Now()

cmd := exec.CommandContext(ctx, c.prog, c.args...)
if opts.Env == nil {
cmd.Env = os.Environ()
Expand All @@ -327,7 +329,13 @@ func (c *Command) Run(opts *RunOpts) error {
}
}

if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
err := cmd.Wait()
elapsed := time.Since(startTime)
if elapsed > time.Second {
log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
}

if err != nil && ctx.Err() != context.DeadlineExceeded {
return err
}

Expand Down