From 2a753f30f97b80ca03172739711ba9c3bde6f725 Mon Sep 17 00:00:00 2001 From: Eason <291028775@qq.com> Date: Thu, 12 Jan 2023 21:41:42 +0800 Subject: [PATCH] doc: fix cli like sib --- cmd/perfmon.go | 53 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/cmd/perfmon.go b/cmd/perfmon.go index 97cf929..9489383 100644 --- a/cmd/perfmon.go +++ b/cmd/perfmon.go @@ -33,22 +33,43 @@ var perfmonCmd = &cobra.Command{ Use: "perfmon", Short: "Get device performance", Long: "Get device performance", - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) (err error) { device := util.GetDevice(serial) - pid, err := perfmonUtil.GetPidOnPackageName(device, packageName) - if err != nil { - fmt.Println("no corresponding application PID found") - os.Exit(0) + pidStr := "" + if pid == -1 { + pidStr, err = perfmonUtil.GetPidOnPackageName(device, packageName) + if err != nil { + fmt.Println("no corresponding application PID found") + os.Exit(0) + } + } else { + pidStr = fmt.Sprintf("%d", pid) } sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, os.Kill) - if !perfOptions.ProcMem && !perfOptions.ProcCPU && - !perfOptions.ProcFPS && !perfOptions.SystemCPU && - !perfOptions.SystemGPU && !perfOptions.SystemNetWorking && + if (pid == -1 && packageName == "") && + !perfOptions.SystemCPU && + !perfOptions.SystemGPU && + !perfOptions.SystemNetWorking && + !perfOptions.SystemMem { + sysAllParamsSet() + } + + if (pid != -1 || packageName != "") && + !perfOptions.ProcMem && + !perfOptions.ProcCPU && + !perfOptions.ProcThreads && + !perfOptions.ProcFPS && + !perfOptions.SystemCPU && + !perfOptions.SystemNetWorking && + !perfOptions.SystemGPU && !perfOptions.SystemMem { - perfOptions.SystemCPU = true - perfOptions.SystemMem = true + sysAllParamsSet() + perfOptions.ProcMem = true + perfOptions.ProcCPU = true + perfOptions.ProcThreads = true + perfOptions.ProcFPS = true } timer := time.Tick(time.Duration(refreshTime * int(time.Millisecond))) @@ -63,7 +84,7 @@ var perfmonCmd = &cobra.Command{ if err1 != nil { log.Panic(err1) } - processInfo, err2 := perfmonUtil.GetProcessInfo(device, pid, packageName, perfOptions, 1) + processInfo, err2 := perfmonUtil.GetProcessInfo(device, pidStr, packageName, perfOptions, 1) if err2 != nil { log.Panic(err2) } @@ -77,6 +98,7 @@ var perfmonCmd = &cobra.Command{ } } + return nil }, } @@ -87,6 +109,13 @@ var ( refreshTime int ) +func sysAllParamsSet() { + perfOptions.SystemCPU = true + perfOptions.SystemMem = true + perfOptions.SystemGPU = true + perfOptions.SystemNetWorking = true +} + func init() { rootCmd.AddCommand(perfmonCmd) perfmonCmd.Flags().StringVarP(&serial, "serial", "s", "", "device serial (default first device)") @@ -96,7 +125,7 @@ func init() { perfmonCmd.Flags().BoolVar(&perfOptions.SystemMem, "sys-mem", false, "get system memory data") //perfmonCmd.Flags().BoolVar(&sysDisk, "sys-disk", false, "get system disk data") perfmonCmd.Flags().BoolVar(&perfOptions.SystemNetWorking, "sys-network", false, "get system networking data") - perfmonCmd.Flags().BoolVar(&perfOptions.SystemGPU, "gpu", false, "get gpu data") + //perfmonCmd.Flags().BoolVar(&perfOptions.SystemGPU, "gpu", false, "get gpu data") perfmonCmd.Flags().BoolVar(&perfOptions.ProcFPS, "proc-fps", false, "get fps data") perfmonCmd.Flags().BoolVar(&perfOptions.ProcThreads, "proc-threads", false, "get process threads") //perfmonCmd.Flags().BoolVar(&, "proc-network", false, "get process network data")