Skip to content

Commit f35ea2b

Browse files
lunnylafriksdelvh
authored
Add elapsed time on debug for slow git commands (#25642)
To record which command is slow, this PR adds a debug log for slow git operations. --------- Co-authored-by: Lauris BH <[email protected]> Co-authored-by: delvh <[email protected]>
1 parent 934124c commit f35ea2b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/git/command.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ func (c *Command) Run(opts *RunOpts) error {
301301
}
302302
defer finished()
303303

304+
startTime := time.Now()
305+
304306
cmd := exec.CommandContext(ctx, c.prog, c.args...)
305307
if opts.Env == nil {
306308
cmd.Env = os.Environ()
@@ -327,7 +329,13 @@ func (c *Command) Run(opts *RunOpts) error {
327329
}
328330
}
329331

330-
if err := cmd.Wait(); err != nil && ctx.Err() != context.DeadlineExceeded {
332+
err := cmd.Wait()
333+
elapsed := time.Since(startTime)
334+
if elapsed > time.Second {
335+
log.Debug("slow git.Command.Run: %s (%s)", c, elapsed)
336+
}
337+
338+
if err != nil && ctx.Err() != context.DeadlineExceeded {
331339
return err
332340
}
333341

0 commit comments

Comments
 (0)