예제 #1
0
func collectFPS() (*Data, error) {
	fps, err := android.FPS()
	if err != nil {
		return nil, err
	}
	return &Data{
		Name: "fps",
		Data: fps,
	}, nil
}
예제 #2
0
func main() {
	kingpin.CommandLine.HelpFlag.Short('h')
	kingpin.Parse()

	if *version {
		showVersion()
		return
	}

	if *showInfo {
		DumpAndroidInfo()
		return
	}

	if *quit {
		http.Get(fmt.Sprintf("http://localhost:%d/api/quit", *port))
		return
	}

	if *showFPS && os.Getuid() != 0 {
		if err := rootRun(os.Args...); err != nil {
			log.Fatal(err)
		}
		return
	}

	if *showFPS && os.Getuid() == 0 {
		collectFuncs["fps"] = CollectUnit{collectFPS, 500 * time.Millisecond}
	}

	//if *showFPS {
	//go drainAndroidFPS(outC)
	//}

	if *listen {
		go serveHTTP(*port) // open a server for app to send data
	}

	if *test {
		log.Println(android.FPS())
		return
	}

	var proc *process.Process
	if *search != "" {
		procs, err := FindProcess(*search)
		if err != nil {
			log.Fatal(err)
		}
		if len(procs) == 0 {
			log.Fatalf("No process found by %s", strconv.Quote(*search))
		}
		if len(procs) > 1 {
			log.Fatal("Find more then one process matched, This is a bug, maybe")
		}
		proc = procs[0]
		collectFuncs["proc_cpu"] = CollectUnit{NewProcCollectCPU(proc), *duration}
		collectFuncs["proc_net"] = CollectUnit{NewProcCollectTraffic(proc), *duration}
		collectFuncs["proc_mem"] = CollectUnit{NewProcCollectMemory(proc), *duration}
	}
	collectFuncs["sys_cpu"] = CollectUnit{collectCPU, *duration}
	collectFuncs["sys_mem"] = CollectUnit{collectMem, *duration}
	collectFuncs["battery"] = CollectUnit{collectBattery, *duration}

	drainData(collectFuncs)
	for data := range outC {
		data.Time = time.Now().UnixNano() / 1e6 // milliseconds
		dataByte, _ := json.Marshal(data)
		fmt.Println(string(dataByte))
	}
}