mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
change: log elapsed seconds for shell execution
This commit is contained in:
+19
-25
@@ -267,6 +267,16 @@ func (d *Device) RunShellCommandWithBytes(cmd string, args ...string) ([]byte, e
|
|||||||
if strings.TrimSpace(cmd) == "" {
|
if strings.TrimSpace(cmd) == "" {
|
||||||
return nil, errors.New("adb shell: command cannot be empty")
|
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))
|
raw, err := d.executeCommand(fmt.Sprintf("shell:%s", cmd))
|
||||||
return raw, err
|
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")
|
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))
|
raw, err := d.executeCommand(fmt.Sprintf("shell,v2,raw:%s", cmd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return raw, err
|
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) {
|
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 {
|
if len(onlyVerifyResponse) == 0 {
|
||||||
onlyVerifyResponse = []bool{false}
|
onlyVerifyResponse = []bool{false}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user