Skip to content

Commit

Permalink
优化命令行输出
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed May 20, 2024
1 parent 0ba959d commit 692f997
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 59 deletions.
16 changes: 8 additions & 8 deletions cmd/cli_perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions entity/android_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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为单位
Expand Down
2 changes: 1 addition & 1 deletion entity/android_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
4 changes: 2 additions & 2 deletions entity/perf_ws_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 0 additions & 36 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions server/perf_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 692f997

Please sign in to comment.