fix: set perf monitor interval for Sysmontap

This commit is contained in:
debugtalk
2022-11-29 22:11:20 +08:00
parent 5aeb1960c7
commit 9d474d895e
2 changed files with 11 additions and 3 deletions
+5 -1
View File
@@ -56,6 +56,7 @@ func initIOSDevice(uuid string) uixt.Device {
perfOptions = append(perfOptions, hrp.WithPerfGPU(true)) perfOptions = append(perfOptions, hrp.WithPerfGPU(true))
} }
} }
perfOptions = append(perfOptions, hrp.WithPerfOutputInterval(interval*1000))
device, err := uixt.NewIOSDevice( device, err := uixt.NewIOSDevice(
uixt.WithUDID(uuid), uixt.WithUDID(uuid),
@@ -78,6 +79,7 @@ func initAndroidDevice(uuid string) uixt.Device {
} }
type timeLog struct { type timeLog struct {
UTCTimeStr string `json:"utc_time_str"`
UTCTime int64 `json:"utc_time"` UTCTime int64 `json:"utc_time"`
LiveTime string `json:"live_time"` LiveTime string `json:"live_time"`
LiveTimeSeconds int `json:"live_time_seconds"` LiveTimeSeconds int `json:"live_time_seconds"`
@@ -111,7 +113,7 @@ func NewWorldCupLive(device uixt.Device, matchName, bundleID string, duration, i
startTime := time.Now() startTime := time.Now()
matchName = fmt.Sprintf("%s-%s", startTime.Format("2006-01-02"), matchName) matchName = fmt.Sprintf("%s-%s", startTime.Format("2006-01-02"), matchName)
resultDir := filepath.Join("worldcup-archives", matchName, startTime.Format("15:04:05")) resultDir := filepath.Join("worldcuplive", matchName, startTime.Format("15:04:05"))
if err = os.MkdirAll(filepath.Join(resultDir, "screenshot"), 0o755); err != nil { if err = os.MkdirAll(filepath.Join(resultDir, "screenshot"), 0o755); err != nil {
log.Fatal().Err(err).Msg("failed to create result dir") log.Fatal().Err(err).Msg("failed to create result dir")
@@ -168,6 +170,7 @@ func (wc *WorldCupLive) getCurrentLiveTime(utcTime time.Time) error {
log.Error().Err(err).Str("line", line).Msg("write timeseries failed") log.Error().Err(err).Str("line", line).Msg("write timeseries failed")
} }
wc.Summary = append(wc.Summary, timeLog{ wc.Summary = append(wc.Summary, timeLog{
UTCTimeStr: utcTimeStr,
UTCTime: utcTime.Unix(), UTCTime: utcTime.Unix(),
LiveTime: ocrText.Text, LiveTime: ocrText.Text,
LiveTimeSeconds: liveTimeSeconds, LiveTimeSeconds: liveTimeSeconds,
@@ -256,6 +259,7 @@ func (wc *WorldCupLive) DumpResult() error {
wc.PerfData = wc.driver.GetPerfData() wc.PerfData = wc.driver.GetPerfData()
err := encoder.Encode(wc) err := encoder.Encode(wc)
if err != nil { if err != nil {
log.Error().Err(err).Msg("encode json failed")
return err return err
} }
+6 -2
View File
@@ -5,6 +5,7 @@ import (
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"net" "net"
"strconv" "strconv"
"time" "time"
@@ -179,10 +180,13 @@ type perfdSysmontap struct {
func (c *perfdSysmontap) Start() (data <-chan []byte, err error) { func (c *perfdSysmontap) Start() (data <-chan []byte, err error) {
// set config // set config
interval := time.Millisecond * time.Duration(c.options.OutputInterval)
log.Printf("set sysmontap sample interval: %dms\n", c.options.OutputInterval)
config := map[string]interface{}{ config := map[string]interface{}{
"bm": 0, "bm": 0,
"cpuUsage": true, "cpuUsage": true,
"sampleInterval": time.Second * 1, // 1s "sampleInterval": interval, // time.Duration
"ur": c.options.OutputInterval, // 输出频率 "ur": c.options.OutputInterval, // 输出频率
"procAttrs": c.options.ProcessAttributes, // process performance "procAttrs": c.options.ProcessAttributes, // process performance
"sysAttrs": c.options.SystemAttributes, // system performance "sysAttrs": c.options.SystemAttributes, // system performance
@@ -740,7 +744,7 @@ func (c *perfdGraphicsOpengl) Start() (data <-chan []byte, err error) {
if _, err = c.i.call( if _, err = c.i.call(
instrumentsServiceGraphicsOpengl, instrumentsServiceGraphicsOpengl,
"setSamplingRate:", "setSamplingRate:",
float64(c.options.OutputInterval)/100, float64(c.options.OutputInterval)/100, // FIXME: unable to set sampling rate, always 1.0
); err != nil { ); err != nil {
return nil, err return nil, err
} }