Skip to content

Commit

Permalink
doc: fix cli like sib
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Jan 12, 2023
1 parent 478508d commit 2a753f3
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions cmd/perfmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)
}
Expand All @@ -77,6 +98,7 @@ var perfmonCmd = &cobra.Command{

}
}
return nil
},
}

Expand All @@ -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)")
Expand All @@ -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")
Expand Down

0 comments on commit 2a753f3

Please sign in to comment.