diff --git a/hrp/pkg/gadb/device.go b/hrp/pkg/gadb/device.go index 515553b1..9d497fcf 100644 --- a/hrp/pkg/gadb/device.go +++ b/hrp/pkg/gadb/device.go @@ -267,6 +267,16 @@ func (d *Device) RunShellCommandWithBytes(cmd string, args ...string) ([]byte, e if strings.TrimSpace(cmd) == "" { return nil, errors.New("adb shell: command cannot be empty") } + + startTime := time.Now() + defer func() { + // log elapsed seconds for shell execution + log.Debug().Str("cmd", + fmt.Sprintf("adb -s %s shell %s", d.serial, cmd)). + Float64("elapsed(s)", time.Since(startTime).Seconds()). + Msg("run adb shell") + }() + raw, err := d.executeCommand(fmt.Sprintf("shell:%s", cmd)) return raw, err } @@ -280,6 +290,15 @@ func (d *Device) RunShellCommandV2WithBytes(cmd string, args ...string) ([]byte, return nil, errors.New("adb shell: command cannot be empty") } + startTime := time.Now() + defer func() { + // log elapsed seconds for shell execution + log.Debug().Str("cmd", + fmt.Sprintf("adb -s %s shell %s", d.serial, cmd)). + Float64("elapsed(s)", time.Since(startTime).Seconds()). + Msg("run adb shell in v2") + }() + raw, err := d.executeCommand(fmt.Sprintf("shell,v2,raw:%s", cmd)) if err != nil { return raw, err @@ -362,31 +381,6 @@ func (d *Device) createDeviceTransport() (tp transport, err error) { } func (d *Device) executeCommand(command string, onlyVerifyResponse ...bool) (raw []byte, err error) { - startTime := time.Now() - defer func() { - // log elapsed seconds for shell execution - elapsed := time.Since(startTime).Seconds() - if strings.HasPrefix(command, "shell,v2,raw:") { - cmd := strings.TrimPrefix(command, "shell,v2,raw:") - log.Debug().Str("cmd", - fmt.Sprintf("adb -s %s shell %s", d.serial, cmd)). - Float64("elapsed(s)", elapsed). - Msg("run adb shell in v2") - } else if strings.HasPrefix(command, "shell:") { - cmd := strings.TrimPrefix(command, "shell:") - log.Debug().Str("cmd", - fmt.Sprintf("adb -s %s shell %s", d.serial, cmd)). - Float64("elapsed(s)", elapsed). - Msg("run adb shell") - } else { - cmd := strings.ReplaceAll(command, ":", " ") - log.Debug().Str("command", - fmt.Sprintf("adb -s %s %s", d.serial, cmd)). - Float64("elapsed(s)", elapsed). - Msg("run adb command") - } - }() - if len(onlyVerifyResponse) == 0 { onlyVerifyResponse = []bool{false} }