Exemplo n.º 1
0
// report stops the given process and reports on it's resource usage in two
// ways: human readable to stderr, and CSV to stdout.
func report(p *rc.Process, wallTime time.Duration) {
	sv, err := p.SystemVersion()
	if err != nil {
		log.Println(err)
		return
	}

	ss, err := p.SystemStatus()
	if err != nil {
		log.Println(err)
		return
	}

	proc, err := p.Stop()
	if err != nil {
		return
	}

	rusage, ok := proc.SysUsage().(*syscall.Rusage)
	if !ok {
		return
	}

	log.Println("Version:", sv.Version)
	log.Println("Alloc:", ss.Alloc/1024, "KiB")
	log.Println("Sys:", ss.Sys/1024, "KiB")
	log.Println("Goroutines:", ss.Goroutines)
	log.Println("Wall time:", wallTime)
	log.Println("Utime:", time.Duration(rusage.Utime.Nano()))
	log.Println("Stime:", time.Duration(rusage.Stime.Nano()))
	if runtime.GOOS == "darwin" {
		// Darwin reports in bytes, Linux seems to report in KiB even
		// though the manpage says otherwise.
		rusage.Maxrss /= 1024
	}
	log.Println("MaxRSS:", rusage.Maxrss, "KiB")

	fmt.Printf("%s,%d,%d,%d,%.02f,%.02f,%.02f,%d\n",
		sv.Version,
		ss.Alloc/1024,
		ss.Sys/1024,
		ss.Goroutines,
		wallTime.Seconds(),
		time.Duration(rusage.Utime.Nano()).Seconds(),
		time.Duration(rusage.Stime.Nano()).Seconds(),
		rusage.Maxrss)
}
Exemplo n.º 2
0
func checkedStop(t *testing.T, p *rc.Process) {
	if _, err := p.Stop(); err != nil {
		t.Fatal(err)
	}
}