summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-29 09:31:42 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-29 09:39:22 +1000
commit71cab4fadc84fff893aa797482b3436ea2faae8a (patch)
tree9cbb597b2d7895640021817699d279df18c0d676 /pkg/commands
parent09ce430240fdc348a7bdbd03318ce1ccb75c1c05 (diff)
Log duration of commands
This will help us diagnose performance issues
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/oscommands/cmd_obj_runner.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go
index b82e3a25c..23ec47070 100644
--- a/pkg/commands/oscommands/cmd_obj_runner.go
+++ b/pkg/commands/oscommands/cmd_obj_runner.go
@@ -6,6 +6,7 @@ import (
"io"
"regexp"
"strings"
+ "time"
"github.com/go-errors/errors"
"github.com/jesseduffield/gocui"
@@ -102,10 +103,14 @@ func (self *cmdObjRunner) RunWithOutputAux(cmdObj ICmdObj) (string, error) {
self.logCmdObj(cmdObj)
}
+ t := time.Now()
output, err := sanitisedCommandOutput(cmdObj.GetCmd().CombinedOutput())
if err != nil {
self.log.WithField("command", cmdObj.ToString()).Error(output)
}
+
+ self.log.Infof("%s (%s)", cmdObj.ToString(), time.Since(t))
+
return output, err
}
@@ -116,12 +121,15 @@ func (self *cmdObjRunner) RunWithOutputsAux(cmdObj ICmdObj) (string, string, err
self.logCmdObj(cmdObj)
}
+ t := time.Now()
var outBuffer, errBuffer bytes.Buffer
cmd := cmdObj.GetCmd()
cmd.Stdout = &outBuffer
cmd.Stderr = &errBuffer
err := cmd.Run()
+ self.log.Infof("%s (%s)", cmdObj.ToString(), time.Since(t))
+
stdout := outBuffer.String()
stderr, err := sanitisedCommandOutput(errBuffer.Bytes(), err)
if err != nil {
@@ -144,6 +152,7 @@ func (self *cmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line st
if cmdObj.ShouldLog() {
self.logCmdObj(cmdObj)
}
+ t := time.Now()
cmd := cmdObj.GetCmd()
stdoutPipe, err := cmd.StdoutPipe()
@@ -171,6 +180,8 @@ func (self *cmdObjRunner) RunAndProcessLines(cmdObj ICmdObj, onLine func(line st
_ = cmd.Wait()
+ self.log.Infof("%s (%s)", cmdObj.ToString(), time.Since(t))
+
return nil
}
@@ -237,9 +248,14 @@ func (self *cmdObjRunner) runAndStreamAux(
}
}()
+ t := time.Now()
+
onRun(handler, cmdWriter)
err = cmd.Wait()
+
+ self.log.Infof("%s (%s)", cmdObj.ToString(), time.Since(t))
+
if err != nil {
errStr := stderr.String()
if errStr != "" {