diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-07-05 00:22:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-04 16:22:37 +0000 |
commit | f35ea2b09a0553ac7644eccdf8a96dd6f90c2982 (patch) | |
tree | 73877b9b31f4567e7d64b8c407fa0d24d7fd402e /modules/git | |
parent | 934124c641438667d0bbe4c2272b27b424097d82 (diff) | |
download | gitea-f35ea2b09a0553ac7644eccdf8a96dd6f90c2982.tar.gz gitea-f35ea2b09a0553ac7644eccdf8a96dd6f90c2982.zip |
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 <lauris@nix.lv>
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/command.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/modules/git/command.go b/modules/git/command.go index ac013d4ea1..c38fd04696 100644 --- a/modules/git/command.go +++ b/modules/git/command.go @@ -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() @@ -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 } |