From 692f997cc3325c2f69b511c84ad2a82b07d0f193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=A5=E5=88=A9=E5=97=B7=E5=97=B7=E5=97=B7=E5=8F=AB?= Date: Mon, 20 May 2024 23:28:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/cli_perf.go | 16 ++++++++-------- entity/android_process.go | 5 +---- entity/android_system.go | 2 +- entity/perf_ws_info.go | 4 ++-- main.go | 36 ------------------------------------ server/perf_server.go | 16 ++++++++-------- 6 files changed, 20 insertions(+), 59 deletions(-) diff --git a/cmd/cli_perf.go b/cmd/cli_perf.go index a796e7f..2804485 100644 --- a/cmd/cli_perf.go +++ b/cmd/cli_perf.go @@ -80,7 +80,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { go func() { perf.GetSysFrame(device, config, func(frame *entity.SysFrameInfo, code entity.ServerCode) { - data, err := json.Marshal(frame) + data, err := json.Marshal(&entity.PerfData{SystemPerfData: &entity.SystemInfo{Frame: frame}}) if err != nil { panic(err) } @@ -93,7 +93,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { go func() { perf.GetSysCPU(device, config, func(CPU map[string]*entity.SystemCPUInfo, code entity.ServerCode) { - data, err := json.Marshal(CPU) + data, err := json.Marshal(&entity.PerfData{SystemPerfData: &entity.SystemInfo{CPU: CPU}}) if err != nil { panic(err) } @@ -106,7 +106,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { go func() { perf.GetSysMem(device, config, func(sysMem *entity.SystemMemInfo, code entity.ServerCode) { - data, err := json.Marshal(sysMem) + data, err := json.Marshal(&entity.PerfData{SystemPerfData: &entity.SystemInfo{MemInfo: sysMem}}) if err != nil { panic(err) } @@ -118,7 +118,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { if config.SysNetwork { go func() { perf.GetSysNetwork(device, config, func(sysNet map[string]*entity.SystemNetworkInfo, code entity.ServerCode) { - data, err := json.Marshal(sysNet) + data, err := json.Marshal(&entity.PerfData{SystemPerfData: &entity.SystemInfo{NetworkInfo: sysNet}}) if err != nil { panic(err) } @@ -133,7 +133,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { go func() { perf.GetProcCPU(device, config, func(cpuInfo *entity.ProcCpuInfo, code entity.ServerCode) { - data, err := json.Marshal(cpuInfo) + data, err := json.Marshal(&entity.PerfData{ProcPerfData: &entity.ProcessInfo{CPUInfo: cpuInfo}}) if err != nil { panic(err) } @@ -147,7 +147,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { go func() { perf.GetProcMem(device, config, func(memInfo *entity.ProcMemInfo, code entity.ServerCode) { - data, err := json.Marshal(memInfo) + data, err := json.Marshal(&entity.PerfData{ProcPerfData: &entity.ProcessInfo{MemInfo: memInfo}}) if err != nil { panic(err) } @@ -160,7 +160,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { if config.ProcThread { go func() { perf.GetProcThreads(device, config, func(threadInfo *entity.ProcThreadsInfo, code entity.ServerCode) { - data, err := json.Marshal(threadInfo) + data, err := json.Marshal(&entity.PerfData{ProcPerfData: &entity.ProcessInfo{ThreadInfo: threadInfo}}) if err != nil { panic(err) } @@ -172,7 +172,7 @@ func startGetPerf(device *gadb.Device, config entity.PerfConfig) { if config.SysTemperature { go func() { perf.GetSysTemperature(device, config, func(temperatureInfo *entity.SysTemperature, code entity.ServerCode) { - data, err := json.Marshal(temperatureInfo) + data, err := json.Marshal(&entity.PerfData{SystemPerfData: &entity.SystemInfo{Temperature: temperatureInfo}}) if err != nil { panic(err) } diff --git a/entity/android_process.go b/entity/android_process.go index 719090a..ab38933 100644 --- a/entity/android_process.go +++ b/entity/android_process.go @@ -87,13 +87,10 @@ type ProcessStatus struct { } type ProcessInfo struct { - Activity string `json:"currentActivity,omitempty"` - Name string `json:"name"` - Pid string `json:"pid"` CPUInfo *ProcCpuInfo `json:"cpuInfo,omitempty"` MemInfo *ProcMemInfo `json:"memInfo,omitempty"` ThreadInfo *ProcThreadsInfo `json:"threadInfo,omitempty"` - Error []string `json:"error"` + Error []string `json:"error,omitempty"` } // 都是MB为单位 diff --git a/entity/android_system.go b/entity/android_system.go index 882a312..06c536e 100644 --- a/entity/android_system.go +++ b/entity/android_system.go @@ -58,7 +58,7 @@ type SystemInfo struct { CPU map[string]*SystemCPUInfo `json:"cpuInfo,omitempty"` Frame *SysFrameInfo `json:"frame,omitempty"` Temperature *SysTemperature `json:"temperature,omitempty"` - Error []string `json:"error"` + Error []string `json:"error,omitempty"` //Timestamp int64 `json:"timeStamp"` } diff --git a/entity/perf_ws_info.go b/entity/perf_ws_info.go index a1f108f..0e66e4b 100644 --- a/entity/perf_ws_info.go +++ b/entity/perf_ws_info.go @@ -19,8 +19,8 @@ type PerfRecvMessage struct { } type PerfData struct { - SystemPerfData SystemInfo `json:"system"` - ProcPerfData ProcessInfo `json:"process"` + SystemPerfData *SystemInfo `json:"system,omitempty"` + ProcPerfData *ProcessInfo `json:"process,omitempty"` } func NewPerfDataMessage(PerfData *PerfData) *PerfDataMessage { diff --git a/main.go b/main.go index 05ee08b..ef121d5 100644 --- a/main.go +++ b/main.go @@ -11,42 +11,6 @@ var dist embed.FS //go:embed fionna-web/dist/index.html var indexHtml []byte -//func main() { -// r := gin.Default() -// r.Use(server.Cors()) -// -// r.GET("/", func(c *gin.Context) { -// c.Data(http.StatusOK, "text/html", indexHtml) -// }) -// -// r.NoRoute(func(c *gin.Context) { -// //fmt.Println(path.Join("dist", c.Request.URL.Path)) -// data, err := dist.ReadFile(path.Join("fionna-web/dist", c.Request.URL.Path)) -// -// if err != nil { -// //c.Redirect(http.StatusMovedPermanently, "/") -// } -// mimeType := mime.DetectFilePath(c.Request.URL.Path) -// c.Data(http.StatusOK, mimeType, data) -// }) -// -// server.InitDB() -// -// server.GroupAndroidSerialUrl(r) -// server.GroupAndroidPackageUrl(r) -// server.WebSocketScrcpy(r) -// server.WebSocketPerf(r) -// server.WebSocketTerminal(r) -// server.GroupReportUrl(r) -// // 开发时可以注掉 -// gin.SetMode(gin.ReleaseMode) -// -// port := "3417" -// link := "http://127.0.0.1:" + port -// fmt.Fprintf(os.Stdout, "link: \033]8;;%s\033\\%s\033]8;;\033\\\n", link, link) -// r.Run(":" + port) // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") -//} - func main() { cmd.SetEmbed(dist, indexHtml) cmd.Execute() diff --git a/server/perf_server.go b/server/perf_server.go index 2f2bd8e..af47d2d 100644 --- a/server/perf_server.go +++ b/server/perf_server.go @@ -128,7 +128,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity db.Create(sysFrameInfo) - perfData := &entity.PerfData{SystemPerfData: entity.SystemInfo{Frame: sysFrameInfo}} + perfData := &entity.PerfData{SystemPerfData: &entity.SystemInfo{Frame: sysFrameInfo}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send sys frame fail,close perf....", err) @@ -169,7 +169,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity count++ } - perfData := &entity.PerfData{SystemPerfData: entity.SystemInfo{CPU: CPU}} + perfData := &entity.PerfData{SystemPerfData: &entity.SystemInfo{CPU: CPU}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { @@ -198,7 +198,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity count++ - perfData := &entity.PerfData{SystemPerfData: entity.SystemInfo{MemInfo: sysMem}} + perfData := &entity.PerfData{SystemPerfData: &entity.SystemInfo{MemInfo: sysMem}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send sys mem fail,close perf....", err) @@ -250,7 +250,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity } count++ - perfData := &entity.PerfData{SystemPerfData: entity.SystemInfo{NetworkInfo: sysNet}} + perfData := &entity.PerfData{SystemPerfData: &entity.SystemInfo{NetworkInfo: sysNet}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send sys network fail,close perf....", err) @@ -281,7 +281,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity count++ - perfData := &entity.PerfData{ProcPerfData: entity.ProcessInfo{CPUInfo: cpuInfo}} + perfData := &entity.PerfData{ProcPerfData: &entity.ProcessInfo{CPUInfo: cpuInfo}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send proc cpu fail,close perf....", err) @@ -315,7 +315,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity count++ - perfData := &entity.PerfData{ProcPerfData: entity.ProcessInfo{MemInfo: memInfo}} + perfData := &entity.PerfData{ProcPerfData: &entity.ProcessInfo{MemInfo: memInfo}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send proc mem fail,close perf....", err) @@ -333,7 +333,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity threadInfo.UUID = config.UUID db.Create(threadInfo) - perfData := &entity.PerfData{ProcPerfData: entity.ProcessInfo{ThreadInfo: threadInfo}} + perfData := &entity.PerfData{ProcPerfData: &entity.ProcessInfo{ThreadInfo: threadInfo}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send proc thread fail,close perf....", err) @@ -371,7 +371,7 @@ func startGetPerf(perfWsConn *websocket.Conn, device *gadb.Device, config entity } count++ - perfData := &entity.PerfData{SystemPerfData: entity.SystemInfo{Temperature: temperatureInfo}} + perfData := &entity.PerfData{SystemPerfData: &entity.SystemInfo{Temperature: temperatureInfo}} err := perfConn.WriteJSON(entity.NewPerfDataMessage(perfData)) if err != nil { log.Error("perf conn send sys temperature fail,close perf....", err)