Пример #1
0
Файл: main.go Проект: taysom/va
func commandHandler(w http.ResponseWriter, r *http.Request) {
	bug.Pr("Method", r.Method)
	bug.Pr("URL", r.URL)
	label := r.URL.Path[1:]
	bug.Pr("command", label)
	cmd, ok := command[label]
	if ok {
		bug.Where()
		http.Redirect(w, r, "/", http.StatusFound)
		fmt.Fprintf(w, doc())
		cmd.fn(label, cmd)
	} else {
		bug.Where()
		fmt.Fprintf(w, doc())
	}
}
Пример #2
0
Файл: main.go Проект: taysom/va
func toggleRunningColor() {
	bug.Pr("Color:", stateColor[active])
	if stateColor[running] == red {
		stateColor[running] = yellow
	} else {
		stateColor[running] = red
	}
}
Пример #3
0
Файл: main.go Проект: taysom/va
func dir(label string, cmd *Command) {
	wd := workingDir(label)
	bug.Pr("wd", wd)
	err := os.Chdir(wd)
	if err == nil {
		current.wd = label
	} else {
		fmt.Println("Failed to cd to", wd, "error", err)
	}
}
Пример #4
0
Файл: bloom.go Проект: taysom/va
// MayExist returns true if the byte slice may already exist
func (bl *Bloom) MayExist(key []byte) bool {
	crc := hash(key)
	for i := 0; i < 64/int(bl.shift); i++ {
		if bl.filter.IsClear(crc & bl.mask) {
			bug.Pr(string(key))
			bug.Px("i", i)
			return false
		}
		crc >>= bl.shift
	}
	return true
}
Пример #5
0
func FillPoly(p Point, n int) Vector {
	v := make(Vector, n+1)
	for j := 0; j < n; j++ {
		v[j] = 1
		for k := 0; k < j; k++ {
			v[k] *= p.X
		}
	}
	v[n] = p.Y
	bug.Pr("v", v)
	return v
}
Пример #6
0
Файл: json.go Проект: taysom/va
func (cee *CeeReader) Read(b []byte) (int, error) {
	line, err := cee.rd.ReadBytes('\n')
	bug.Pr("err", err)
	if err != nil {
		return 0, nil
	}
	for {
		i := bytes.IndexByte(line, '@')
		if i == -1 {
			return copy(b, line), nil
		}
		if bytes.Compare(line[i:i+5], []byte("@cee:")) == 0 {
			return copy(b, line[i+5:]), nil
		}
		line = line[i+1:]
	}
}
Пример #7
0
Файл: ktop.go Проект: taysom/va
func processEvent(e Event) {
	NumEvents++
	enter, ok := Enter[e.pid]
	switch e.event {
	case SysEnter:
		if ok {
			MissedExit++
			bug.Pln("Missed Exit ", e)
		}
		Enter[e.pid] = e
	case SysExit:
		if ok {
			if e.callId == enter.callId {
				dt := e.time - enter.time
				if e.cpu != enter.cpu {
					CpuDoesntMatch++
					bug.Pr("Doesn't Match %d:\n\t%v\n\t%v\n", dt, enter, e)
				} else if e.callId >= numSysCalls {
					OutOfRange++
					bug.Pln("Sys call id out of range:", e)
				} else if dt < 0 {
					Early++
					bug.Pln("exit before enter", dt, enter, e)
				} else {
					Ok++
					pc := PidCall{pid: e.pid, callId: e.callId, dt: dt}
					bug.Pln(pc)
					setCallStats(&pc)
				}
			} else {
				Mismatched++
				bug.Pln("Missmatched events", enter, e)
			}
		} else {
			MissedEnter++
			bug.Pln("Missed Enter", e)
		}
		delete(Enter, e.pid)
	default:
		Unknown++
		bug.Pln("Unknown event:", e)
	}
}
Пример #8
0
Файл: main.go Проект: taysom/va
func main() {
	flag.Parse()
	if bug.Debug {
		command["debug"].state = active
	} else {
		command["debug"].state = idle
	}
	bug.Note("Debugging is on")
	bug.Pr("dirPrefix", dirPrefix)
	fmt.Println("IP and Port:", ip+port)

	cmd := command[current.wd]
	cmd.fn(current.wd, cmd)
	fmt.Printf("%d: ", commandInstance)
	commandInstance++

	http.HandleFunc("/", commandHandler)
	http.HandleFunc("/favicon.ico", favicon)
	http.ListenAndServe(":62832", nil)
}
Пример #9
0
func ReadMeminfo() {
	f, err := os.Open("/proc/meminfo")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	for {
		f.Seek(0, 0)
		_, err = fmt.Fscanf(f,
			"MemTotal: %d kB\n"+
				"MemFree: %d kB\n"+
				"MemAvailable: %d kB\n"+
				"Buffers: %d kB\n"+
				"Cached: %d kB\n"+
				"SwapCached: %d kB\n"+
				"Active: %d kB\n"+
				"Inactive: %d kB\n"+
				"Active(anon): %d kB\n"+
				"Inactive(anon): %d kB\n"+
				"Active(file): %d kB\n"+
				"Inactive(file): %d kB\n"+
				"Unevictable: %d kB\n"+
				"Mlocked: %d kB\n"+
				"SwapTotal: %d kB\n"+
				"SwapFree: %d kB\n"+
				"Dirty: %d kB\n"+
				"Writeback: %d kB\n"+
				"AnonPages: %d kB\n"+
				"Mapped: %d kB\n"+
				"Shmem: %d kB\n"+
				"Slab: %d kB\n"+
				"SReclaimable: %d kB\n"+
				"SUnreclaim: %d kB\n"+
				"KernelStack: %d kB\n"+
				"PageTables: %d kB\n"+
				"NFS_Unstable: %d kB\n"+
				"Bounce: %d kB\n"+
				"WritebackTmp: %d kB\n"+
				"CommitLimit: %d kB\n"+
				"Committed_AS: %d kB\n"+
				"VmallocTotal: %d kB\n"+
				"VmallocUsed: %d kB\n"+
				"VmallocChunk: %d kB\n", /*+
			"DirecMap4k: %d kB\n"+
			"DirecMap2M: %d kB\n",*/
			&MemTotal, &MemFree, &MemAvailable, &Buffers, &Cached, &SwapCached,
			&Active, &Inactive, &ActiveAnon, &InactiveAnon,
			&ActiveFile, &InactiveFile, &Unevictable,
			&Mlocked, &SWapTotal, &SwapFree, &Dirty,
			&Writeback, &AnonPages, &Mapped, &Shmem,
			&Slab, &SReclaimable, &SUnreclaim, &Kernelstack,
			&PageTables, &NFS_Unstable, &Bounce, &WritebackTmp,
			&CommitLimit, &Committed_AS, &VmallocTotal,
			&VmallocUsed, &VmallocChunk) /*, &DirectMap4k,
		&DirectMpa2M)*/
		if err != nil {
			bug.Pr("err", err)
			log.Fatal(err)
		}
		if false {
			fmt.Println(MemTotal, MemFree)
		}
		time.Sleep(1000 * time.Millisecond)
	}
}
Пример #10
0
Файл: main.go Проект: taysom/va
func workingDir(label string) string {
	bug.Pr("label", label)
	bug.Pr("path", path[label])
	return dirPrefix + path[label]
}