Skip to content

Commit

Permalink
添加web的pid监控
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed May 27, 2024
1 parent 692f997 commit 214070c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
15 changes: 10 additions & 5 deletions android/android_util/package_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func extractPackageNames(output string) []string {
return packages
}

func GetCurrentPackageName(device *gadb.Device) (string, error) {
func GetCurrentPackageNameAndPid(device *gadb.Device) (string, string, error) {
data, err := device.RunShellCommand("dumpsys activity top | grep ACTIVITY")
if err != nil {
return "", fmt.Errorf("exec command erro : " + "dumpsys activity top | grep ACTIVITY")
return "", "", fmt.Errorf("exec command erro : " + "dumpsys activity top | grep ACTIVITY")
}

var dataSplit []string
Expand All @@ -67,10 +67,15 @@ func GetCurrentPackageName(device *gadb.Device) (string, error) {

dataSplit = strings.Split(currentActivityLineStr, " ")
if len(dataSplit) > 1 {
dataSplit = strings.Split(dataSplit[1], "/")
return dataSplit[0], nil
packageNameSplit := strings.Split(dataSplit[1], "/")
for _, param := range dataSplit {
if strings.Contains(param, "pid=") {
return packageNameSplit[0], strings.ReplaceAll(param, "pid=", ""), nil
}
}
return packageNameSplit[0], "", nil
} else {
return "", errors.New("not get current package name")
return "", "", errors.New("not get current package name")
}
}

Expand Down
4 changes: 2 additions & 2 deletions android/android_util/package_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func TestGetCurrentPackageName(t *testing.T) {
if err != nil {
panic(err)
}
packageName, err := GetCurrentPackageName(device)
packageName, pid, err := GetCurrentPackageNameAndPid(device)
if err != nil {
panic(err)
}
fmt.Println(packageName)
fmt.Println(packageName, pid)
}

func TestGetSerialList(t *testing.T) {
Expand Down
7 changes: 5 additions & 2 deletions server/android_device_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GroupAndroidPackageUrl(r *gin.Engine) {
}
return
}
packageName, err := android_util.GetCurrentPackageName(device)
packageName, pid, err := android_util.GetCurrentPackageNameAndPid(device)
if err != nil {
c.JSON(http.StatusOK, entity.ResponseData{
Data: "current package get error",
Expand All @@ -77,7 +77,10 @@ func GroupAndroidPackageUrl(r *gin.Engine) {
return
}
c.JSON(http.StatusOK, entity.ResponseData{
Data: packageName,
Data: map[string]string{
"packageName": packageName,
"pid": pid,
},
Code: entity.RequestSucceed,
})
})
Expand Down
6 changes: 5 additions & 1 deletion server/perf_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ func WebSocketPerf(r *gin.Engine) {

var testName = ""

if perfConfig.PackageName != "" {
if perfConfig.PackageName != "" && perfConfig.Pid != "" {
testName = fmt.Sprintf("%s_%s_%s_pid%s_%s", serialInfo.ProductDevice, serialInfo.Model, perfConfig.PackageName, perfConfig.Pid, formattedTime)
} else if perfConfig.PackageName != "" && perfConfig.Pid == "" {

testName = fmt.Sprintf("%s_%s_%s_%s", serialInfo.ProductDevice, serialInfo.Model, perfConfig.PackageName, formattedTime)

Expand All @@ -462,6 +464,8 @@ func WebSocketPerf(r *gin.Engine) {
ws.WriteJSON(entity.NewPerfDataError("get pid err:" + err.Error()))
break
}
} else if perfConfig.PackageName == "" && perfConfig.Pid != "" {
testName = fmt.Sprintf("%s_%s_pid%s_%s", serialInfo.ProductDevice, serialInfo.Model, perfConfig.Pid, formattedTime)
} else {
testName = fmt.Sprintf("%s_%s_%s", serialInfo.ProductDevice, serialInfo.Model, formattedTime)
}
Expand Down
2 changes: 1 addition & 1 deletion server/scrcpy_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func WebSocketScrcpy(r *gin.Engine) {
if err != nil {
log.Error("read message steam err:", err)
ws.WriteJSON(entity.NewScrcpyError("read message steam err:" + err.Error()))
break
scrcpyClient.ClientStop()
} else {
if message.MessageType == entity.ScrcpyTouchType {
data, err1 := json.Marshal(message.Data)
Expand Down

0 comments on commit 214070c

Please sign in to comment.