Example #1
0
func Test100Random(t *testing.T) {
	p := dnpa.NewPercentile(0.95, 100)
	n, err := readTestFile("test/100-rand-0-to-100", p)
	expect := 90.491419
	if err != nil {
		t.Fatal(err)
	}
	if n != expect {
		t.Errorf("Expected %f, got %f", expect, n)
	}
}
Example #2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Printf("Usage: %s FILE\n", os.Args[0])
		os.Exit(1)
	}
	file, err := os.Open(os.Args[1])
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer file.Close()

	r := bufio.NewReader(file)
	p := dnpa.NewPercentile(0.95, 100)

	for {
		line, _, err := r.ReadLine()
		if err != nil {
			break
		}
		f, err := strconv.ParseFloat(string(line), 64)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		p.Value(f)
	}

	pid := fmt.Sprintf("%d", os.Getpid())
	out, err := exec.Command("ps", "-o", "rss", "-p", pid).Output()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	pat := regexp.MustCompile(`\d+`)
	rss := pat.Find(out)
	fmt.Printf("%.3f %s\n", p.Nth(), string(rss))
}